Records: EqualityContract is a Type #3787
-
Why is the equality contract on records a type? How will it be used? I kind of expected it to to return a static singleton instance of a synthesized IComparer. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
It's used to compare the type of the current instance, pretty much like doing |
Beta Was this translation helpful? Give feedback.
-
So would it essentially use an Activator.CreateInstance(EqualityContract).Equals(x, y) to do a compare? What would the synthesized compare code look like? |
Beta Was this translation helpful? Give feedback.
-
No. It will do: => this.EqualityContract == other.EqualityContract && ... do the member equality checks ... |
Beta Was this translation helpful? Give feedback.
-
Why is |
Beta Was this translation helpful? Give feedback.
-
Adding See #3137 for more information
|
Beta Was this translation helpful? Give feedback.
-
Technically that's what GetType returns.
Is there any case that a derived type doesn't alter equality? |
Beta Was this translation helpful? Give feedback.
Adding
EqualityContract
allows for precise control over whether subtypes are equal, or not.See #3137 for more information