Add an analyzer to prevent the explicit definition of the EqualityContract
property, which establishes value-based equality in Records
#9170
Replies: 1 comment 3 replies
-
You can suggest analyzers at the following repo: https://github.com/dotnet/roslyn-analyzers |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Even though a reference type, Records exhibit Value-based equality.
For that, it generates the getter only
EqualityContract
property that returns its actual type info (immutable).However, this does not prevent it from being manually defined. Perhaps it is an intentional consideration.
To prevent unintentional usage, it would be advisable to implement an analyzer that alerts the user to its implications.
Run the below code for an example. Program is doing what is instructed to perform. Ideally, this should return
False
as types are incompatible.I managed to get it working by returning the matching type info, but this can return any type info (say, typeof(decimal)) as it is not linked to the containing type. Therefore, it advisable to add this analyzer as soon as possible.
Beta Was this translation helpful? Give feedback.
All reactions