-
-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency between InternetAddress.Equals(InternetAddress) and InternetAddress.Equals(object) #481
Comments
I'm honestly not sure that overriding Equals(object) is the right thing to do here. Normally, Equals(object) is for reference equality which is why that Equals fails for you. The Equals(object) method is used in conjunction with GetHashCode() when storing objects in a dictionary or hash table, for example, and in general, I don't think you'd want 2 different object instances to be considered to be the same. Just cast to an InternetAddress and you get your comparison. |
From the documentation of
From the documentation of
The vast majority of generic data structures and many algorithms rely on Reference-equality is merely a default (and even then only for reference types), and usually not an appropriate one. There is also no "just" to getting at the Working around this requires making the following redundant-looking class
If I have a map from strings to ints, put |
When two instances (which will be referred to as
x
andy
) ofInternetAddress
are created usingInternetAddress.Parse
with identical input,x.Equals(y)
returnstrue
when usingInternetAddress.Equals(InternetAddress)
andfalse
when usingInternetAddress.Equals(object)
.In the NUnit test below, the first assertion succeeds while the second fails.
The same behavior occurs when using
MailboxAddress
instead ofInternetAddress
.Affects versions 2.13 and 2.14 on NuGet.
The text was updated successfully, but these errors were encountered: