Skip to content

Commit

Permalink
Add equality override for KeyValuePairComparer (#56634)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthcall authored Aug 2, 2021
1 parent aa4290f commit bb7e7f9
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,21 @@ public override int Compare(KeyValuePair<TKey, TValue> x, KeyValuePair<TKey, TVa
{
return keyComparer.Compare(x.Key, y.Key);
}

public override bool Equals(object? obj)
{
if (obj is KeyValuePairComparer other)
{
// Commonly, both comparers will be the default comparer (and reference-equal). Avoid a virtual method call to Equals() in that case.
return this.keyComparer == other.keyComparer || this.keyComparer.Equals(other.keyComparer);
}
return false;
}

public override int GetHashCode()
{
return this.keyComparer.GetHashCode();
}
}
}

Expand Down

0 comments on commit bb7e7f9

Please sign in to comment.