by Andreas

IsNullOrEmpty() extension for generic lists (List<T>)

The .IsNullOrEmpty() and .IsNullOrWhitespace() utility methods for string objects really helps cleaning up the code compared to the old fashion

if (myString == null || myString.Trim().Equals(""))
  ...

This should definately have been implemented for other classes as well, like the List or the Dictionary. But until that happens, add your own extensions:

    public static class Extensions
    {
        public static bool IsNullOrEmpty<T>(this List<T> list)
        {
            return list == null || !list.Any();
        }

        public static bool IsNullOrEmpty<TKey, TValue>(this Dictionary<TKey, TValue> dictionary)
        {
            return dictionary == null || !dictionary.Any();
        }

    }

Then you’ll be able to check whether your List is null or empty in a single statement:

List<long> myNumericValues = new List<long>();
if (myNumericValues.IsNullOrEmpty())
{
    ...
}