Harmonise `AvaloniaObject` equality comparison
See original GitHub issueAvaloniaObject.Equals
and GetHashCode
are overridden, but only to seal the methods and prevent derived types from overriding them. This is fine at runtime, but causes static code analysis tools to think that the type has special equality logic. In my project this leads to annoying compile warnings every time we use ==
to compare two controls. Our CI rejects any commit containing these warnings.
To Reproduce Steps to reproduce the behavior:
- Compare two
AvaloniaObject
variables with==
- Run Resharper on your solution with
PossibleUnintendedReferenceComparison
enabled - Resharper will warn about the comparison
Expected behavior There are two options:
AvaloniaObject
should stop overridingEquals
andGetHashCode
. An analyzer diagnostic can be emitted to warn anyone who tries to override those methods in a derived type.AvaloniaObject
should also provideoperator ==
andoperator !=
, so that code analysis tools think that everything is customised and stops warning about it.
I think option 1 is preferable, because sealing the methods does not stop users from defining their own static equality operators.
Desktop
- OS: N/A
- Version 11 RC 1.1
Issue Analytics
- State:
- Created 4 months ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Converting Binding Values
You can negate a binding value by prepending a "bang" operator: ! ... Convert( object? value, Type targetType, object? parameter, CultureInfo culture )...
Read more >API - AvaloniaProperty.Equals(object) Method - Avalonia UI
AvaloniaProperty. Equals(object) Method. Namespace: Avalonia; Containing Type: AvaloniaProperty. Syntax. public override bool Equals(object obj). Parameters ...
Read more >c# - WPF Event Binding to ViewModel (for non-Command ...
I've been able to find a ton of information on how to bind the Command of these objects to an ICommand in the...
Read more >Equality Comparisons - C# Programming Guide
For records, value equality means that two variables of a record type are equal if the types match and all property and field...
Read more >Commission Meeting - February 16,, 2023
(c) INSURANCE: Buyer agrees to insure the goods delivered under the Agreement in an amount at least equal to the purchase price against...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is it really a problem with modern runtime? I am pretty sure if will be inlined to the same code nowadays.
https://youtrack.jetbrains.com/issue/RSRP-492562/Possible-unintended-reference-comparison-for-AvaloniaObject