Provide an implementation of IEqualityComparer based on object identity - by Jason Kresowaty

Status : 

  External<br /><br />
		This item may be valid but belongs to an external system out of the direct control of this product team.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


3
0
Sign in
to vote
ID 261286 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 3/3/2007 11:42:51 AM
Access Restriction Public

Description

If an arbitrary type overrides Equals/GetHashCode, there is no way to use object's identity for that type as keys to a dictionary.

Java's solution to this is to provide a "public static int System.identityHashCode(Object x)" method along with a IdentityHashMap class.

One way to solve this in .NET would be to provide a singleton concrete implementation of IEqualityComparer that uses the non-overridden forms of Object.Equals and Object.GetHashCode.

The programming need for this occurs when implementing certain kinds of caches (especially ones for which the overridden Equals/GetHashCode implementations provided by the object are inefficient or buggy).
Sign in to post a comment.
Posted by Microsoft on 3/5/2007 at 2:19 PM
Hello,
Thanks a lot for reporting this. We will consider adding this feature to a future release.
Thanks
Lakshan Fernando
BCL Team