mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
644 B
24 lines
644 B
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ZeroLevel
|
|
{
|
|
public static class LinqExtension
|
|
{
|
|
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
|
|
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
{
|
|
if (source != null)
|
|
{
|
|
var seenKeys = new HashSet<TKey>();
|
|
foreach (TSource element in source)
|
|
{
|
|
if (seenKeys.Add(keySelector(element)))
|
|
{
|
|
yield return element;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |