-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add proposal for 'key' modifier #3127
Conversation
Implements structural equality.
protected bool KeyEquals(A a) | ||
=> P1 == a.P1; | ||
|
||
public static bool operator==(A left, A right) => left.Equals(right); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't check for null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Yeah, it seems good to make this null-aware.
``` | ||
|
||
|
||
Three synthesized members will be added to the type, `T`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is well more than 3 synthesized members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh, just made up a number before writing this list and forgot to go back
|
||
Three synthesized members will be added to the type, `T`: | ||
|
||
1. override of `object.Equals(object)`. It is an error if a base class has sealed this member. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also consider commenting on what happens if the class has written out implementations of any of these members.
Then B.Equals could be: public bool Equals(B other) => other.GetType() == typeof(B) && KeyEquals(b);
|
No. It can be implemented that way, but it's not required to be implemented that way. The point is to allow the impl (including user overrides) to make the call on what determines equality. |
No. Having it be a virtual method means that you can extend a class (implementation inheritance) without changing its equality contract. |
Can |
Why closed? |
We ended up implementing records without the notion and at the moment I don't think it's worth the additional complexity. |
I think it would still be useful for records in case you wanted to compare only by certain properties and not all. |
Implements structural equality.