You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I really like the idea of having equality checks where a developer goes left == right or left.Equals(right) being more than just a warning to enforce proper equality checks with decimal values.
Describe the solution you'd like
A code analyzer that looks for equality checks where they aren't using any tolerance and treat them as compiler errors.
Describe alternatives you've considered
I've thought about including FxCop and adding a rule for this purpose but with the Roslyn SDK I feel like a custom analyzer would be the way to go.
Additional context
N/A
The text was updated successfully, but these errors were encountered:
@lkomanetz If you're planning a PR for this, please note that I've been working (it's going to be exactly one year soon) on a version of UnitsNet (hopefully to be release as v6) that, among other things, replaces the floating point representation with a rational one, which allows as to use all the natural comparison/equality operators without worries.
Until that time, I'd advice you to keep in mind that, while there aren't any warnings emitted for the comparison operators, but they are also not safe : it's possible to come up with a situation where (a >= b) != (b<=a) is true. In practical terms, there isn't any exact way of stating that, "the length should be in the range 1m ± 0.1m" - depending on the units you're using, this may or may not work with something like 1m + 10%.
@lipchev
Do you feel like this enhancement ticket should be closed out? I did think about the <= and >= comparisons and felt that maybe a warning would've sufficed because of what you mentioned. An analyzer that sees those and goes, "yeah...not the MOST safe thing to do but we're not sure how to do this with every possible unit type so we'll warn you." With that another analyzer that goes, "you're checking equality? It's got to be in this way otherwise that's FOR SURE unsafe." That's where my mind was going.
Is your feature request related to a problem? Please describe.
I really like the idea of having equality checks where a developer goes
left == right
orleft.Equals(right)
being more than just a warning to enforce proper equality checks with decimal values.Describe the solution you'd like
A code analyzer that looks for equality checks where they aren't using any tolerance and treat them as compiler errors.
Describe alternatives you've considered
I've thought about including FxCop and adding a rule for this purpose but with the Roslyn SDK I feel like a custom analyzer would be the way to go.
Additional context
N/A
The text was updated successfully, but these errors were encountered: