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