Skip to content

Instantly share code, notes, and snippets.

@jfranmora
Last active June 25, 2020 08:50
Show Gist options
  • Save jfranmora/404fcdb3fa2cfd2ee5dbb6ac7a86936d to your computer and use it in GitHub Desktop.
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.
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