Last active
June 25, 2020 08:50
-
-
Save jfranmora/404fcdb3fa2cfd2ee5dbb6ac7a86936d to your computer and use it in GitHub Desktop.
Extension to create a consistent way to check if null or empty with different types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
public static class IsNullOrEmptyExtensions | |
{ | |
public static bool IsNullOrEmpty(this string str) | |
{ | |
return string.IsNullOrEmpty(str); | |
} | |
public static bool IsNullOrEmpty<T>(this ICollection<T> collection) | |
{ | |
return collection == null || collection.Count == 0; | |
} | |
public static bool IsNullOrEmpty<T>(this T[] array) | |
{ | |
return array == null || array.Length == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment