Created
April 17, 2015 07:52
-
-
Save mikaelnet/76d0b62324b76ba2a8a4 to your computer and use it in GitHub Desktop.
Extension methods for enumerables
This file contains 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
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