整理代码

This commit is contained in:
GG Z
2026-02-20 15:31:44 +08:00
parent 94cf3f3266
commit 9f121cfc7f
149 changed files with 4063 additions and 6964 deletions

View File

@@ -0,0 +1,50 @@
using ShrlAlgoToolkit.RevitAddins.Extensions;
namespace ShrlAlgoToolkit.RevitAddins.Extensions;
/// <summary>
/// 自定义Distinct扩展方法
/// </summary>
public static class DistinctExtensions
{
public static IEnumerable<T> Distinct<T>(
this IEnumerable<T> source, Func<T, T, bool> comparer)
where T : class
=> source.Distinct(new DistinctExtensions.DynamicEqualityComparer<T>(comparer));
public static IEnumerable<T> Distinct<T, V>(this IEnumerable<T> source, Func<T, V> keySelector)
=> source.Distinct(new DistinctExtensions.CommonEqualityComparer<T, V>(keySelector));
private sealed class DynamicEqualityComparer<T> : IEqualityComparer<T>
where T : class
{
private readonly Func<T, T, bool> _func;
public DynamicEqualityComparer(Func<T, T, bool> func)
{
_func = func;
}
public bool Equals(T x, T y) => _func(x, y);
public int GetHashCode(T obj) => 0;
}
private sealed class CommonEqualityComparer<T, V> : IEqualityComparer<T>
{
private readonly Func<T, V> keySelector;
public CommonEqualityComparer(Func<T, V> keySelector)
{
this.keySelector = keySelector;
}
public bool Equals(T x, T y)
{
return EqualityComparer<V>.Default.Equals(keySelector(x), keySelector(y));
}
public int GetHashCode(T obj)
{
return EqualityComparer<V>.Default.GetHashCode(keySelector(obj));
}
}
}