[Proposal] EqualityComparer should be configurable for record type properties #8245
Unanswered
SilentViking
asked this question in
Language Ideas
Replies: 1 comment
-
This could be implemented with a source generators that interprets custom attributes and emits |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Value based equality check in record types are very useful, however any time a reference type property is introduced, the
Equals
andGetHashCode
methods on the record must be overridden, or an implementation of the reference type must be written withEquals
andGetHashCode
overrides.For example, collections are a common issue.
If I want value based equality on
SomeList
, IEnumerable would need to be wrapped, or MyRecord will need to implementEquals
andGetHashCode
, losing out on the benefit of compile time generated code which would handle N number of other properties do have desirable default equality comparison.Proposal:
An attribute, which can be applied to a property, which specifies an IEqualityComparer type with a parameterless constructor.
Then the compile time generated Equals method will create an instance of MyIEnumerableComparer to compare SomeList, and otherwise use EqualityComparer.Default.
Beta Was this translation helpful? Give feedback.
All reactions