IsNullOrEmpty generic method for Array to avoid Re-Sharper warning
- by Michael Freidgeim
I’ve used the following extension method in many places. public static bool IsNullOrEmpty(this Object[] myArr) { return (myArr == null || myArr.Length == 0); }Recently I’ve noticed that Resharper shows warning covariant array conversion to object[] may cause an exception for the following codeObjectsOfMyClass.IsNullOrEmpty()I’ve resolved the issue by creating generic extension method public static bool IsNullOrEmpty<T>(this T[] myArr) { return (myArr == null || myArr.Length == 0); }Related linkshttp://connect.microsoft.com/VisualStudio/feedback/details/94089/add-isnullorempty-to-array-class public static bool IsNullOrEmpty(this System.Collections.IEnumerable source) { if (source == null) return true; else { return !source.GetEnumerator().MoveNext(); } }http://stackoverflow.com/questions/8560106/isnullorempty-equivalent-for-array-c-sharp