namespace HKW.HKWUtils;
///
/// 比较工具
///
/// 比较类型
public class CompareUtils : IEqualityComparer, IEquatable>
{
///
/// (Comparer, CompareUtils)
///
public static Dictionary, CompareUtils> Comparers = new();
public static CompareUtils Create(Func comparer)
{
if (Comparers.TryGetValue(comparer, out var value) is false)
value = Comparers[comparer] = new CompareUtils(comparer);
return value;
}
public Func Comparer { get; set; }
public CompareUtils(Func comparer)
{
Comparer = comparer;
}
public bool Equals(T x, T y)
{
return Comparer(x).Equals(Comparer(y));
}
public int GetHashCode(T obj)
{
return Comparer(obj).GetHashCode();
}
public bool Equals(CompareUtils other)
{
return Comparer.Equals(other.Comparer);
}
}