Home Dashboard Directory Help
Search

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


Status: 

Closed
 as External Help for as External


3
0
Sign in
to vote
Type: Suggestion
ID: 261286
Opened: 3/3/2007 11:42:51 AM
Access Restriction: Public
0
Workaround(s)
view

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).
Details
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
Sign in to post a workaround.