Skip to content

Instantly share code, notes, and snippets.

@mikaelnet
Created April 17, 2015 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelnet/76d0b62324b76ba2a8a4 to your computer and use it in GitHub Desktop.
Save mikaelnet/76d0b62324b76ba2a8a4 to your computer and use it in GitHub Desktop.
Extension methods for enumerables
public static class EnumerableExtensions
{
public static IEnumerable<T> ToEnumerable<T>(this T item, bool nullAsEmpty = true)
{
if (EqualityComparer<T>.Default.Equals(item, default(T)) && nullAsEmpty)
yield break;
yield return item;
}
public static bool None<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
return !source.Any(predicate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment