Is there a default IEqualityComparer<T> implementation that uses ReferenceEquals?
EqualityComparer<T>.Default uses ObjectComparer, which uses object.Equals(). In my case, the objects already implement IEquatable<T>, which I need to ignore and compare by object's reference only.
Just in case there is no default implementation, this is my own:
Edit by 280Z28: Rationale for using
RuntimeHelpers.GetHashCode(object), which many of you probably haven't seen before. :) This method has two effects that make it the correct call for this implementation:ReferenceEqualsworks for null parameters, so should the comparer's implementation of GetHashCode().Object.GetHashCode()non-virtually.ReferenceEqualsspecifically ignores any overrides ofEquals, so the implementation of GetHashCode() should use a special method that matches the effect of ReferenceEquals, which is exactly what RuntimeHelpers.GetHashCode is for.[end 280Z28]