Files
SzmediTools/Szmedi.RevitToolkit.Approval/Extensions/IEnumerableExtensions.cs
2025-09-16 16:06:41 +08:00

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;
}
}
}
}
}