/// <summary> /// Creates a KeyEqualityComparer based on the current key comparer that /// in addition checks for equality based the value returned by the key selector. /// </summary> /// <typeparam name="TKey">The type of the value returned by the key selector.</typeparam> /// <param name="keySelector">The delegate used to select the next key.</param> /// <returns> /// A KeyEqualityComparer based on the current key comparer that /// in addition checks for equality based the value returned by the key selector. /// </returns> /// <exception cref="System.ArgumentNullException">The key selector is null.</exception> public KeyEqualityComparer <T> And <TKey>(Func <T, TKey> keySelector) { if (keySelector == null) { throw new ArgumentNullException("keySelector"); } CompoundKeyEqualityComparer <T> comparer = new CompoundKeyEqualityComparer <T>(); comparer.Add(this); comparer.Add(new TypedKeyEqualityComparer <T, TKey>(keySelector, EqualityComparer <TKey> .Default)); return(comparer); }
public void Add(KeyEqualityComparer <T> comparer) { CompoundKeyEqualityComparer <T> compoundComparer = comparer as CompoundKeyEqualityComparer <T>; if (compoundComparer == null) { _comparers.Add(comparer); } else { _comparers.AddRange(compoundComparer._comparers); } }