クラスは HashSet から継承し、 のEqualKeys(T x, T y)
代わりにカスタム チェックを使用して一意のオブジェクトのセットを取得しますIEqualityComparer
。
public class UniqueSet<T> : HashSet<T> where T : IKey
{
public new void Add(T item)
{
// .. check item for null, empty key etc.
if (base.Any(t => UniqueSet<T>.EqualKeys(t, item)))
{
throw new ArgumentException(..);
}
if (!base.Add(item)) throw new ArgumentException(..);
}
private static bool EqualKeys(T x, T y)
{
return ((IKey)x).Key.Equals(((IKey)y).Key, StringComparison.CurrentCultureIgnoreCase);
}
}
base.Any
に置き換える必要があるため、コードはコンパイルされませんthis.Any
。
私はそれがなぜなのか理解できないのではないかと心配していますか?