using System; using System.Collections.Generic; namespace ZeroLevel { public static class LinqExtension { public static IEnumerable DistinctBy (this IEnumerable source, Func keySelector) { if (source != null) { var seenKeys = new HashSet(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(element))) { yield return element; } } } } } }