GetHashCode 値によって返される値によってオブジェクトを比較する組み込みの IEqualityComparer はありますか? 書くのは簡単ですが、カスタム クラスではなく提供されたクラスを使用したいと思います。
現在のコード:
private class HashComparer : IEqualityComparer<TKey>
{
private readonly Func<TKey, int> _Hasher;
public HashComparer (Func<TKey, int> hasher)
{
_Hasher = hasher;
}
public bool Equals (TKey x, TKey y)
{
// null supposed to throw, therefore no check
return _Hasher (x) == _Hasher (y);
}
public int GetHashCode (TKey obj)
{
return _Hasher (obj);
}
}