25 lines
671 B
C#
25 lines
671 B
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RevitToolkit.Approval.Extensions
|
|||
|
|
{
|
|||
|
|
internal static class IEnumerableExtensions
|
|||
|
|
{
|
|||
|
|
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
|
|||
|
|
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|||
|
|
{
|
|||
|
|
HashSet<TKey> seenKeys = new HashSet<TKey>();
|
|||
|
|
foreach (TSource element in source)
|
|||
|
|
{
|
|||
|
|
if (seenKeys.Add(keySelector(element)))
|
|||
|
|
{
|
|||
|
|
yield return element;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|