-
Notifications
You must be signed in to change notification settings - Fork 405
Closed
Description
a.Equals(b) is the basic way to check if two elements are the same. But it is Obsolete!
For the case I want to use record, the equality is almost unusable.
UnitsNet/UnitsNet/GeneratedCode/Quantities/Length.g.cs
Lines 1217 to 1234 in b57ac63
| /// <inheritdoc /> | |
| /// <summary>Indicates strict equality of two <see cref="Length"/> quantities, where both <see cref="Value" /> and <see cref="Unit" /> are exactly equal.</summary> | |
| [Obsolete("Use Equals(Length other, Length tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] | |
| public override bool Equals(object? obj) | |
| { | |
| if (obj is null || !(obj is Length otherQuantity)) | |
| return false; | |
| return Equals(otherQuantity); | |
| } | |
| /// <inheritdoc /> | |
| /// <summary>Indicates strict equality of two <see cref="Length"/> quantities, where both <see cref="Value" /> and <see cref="Unit" /> are exactly equal.</summary> | |
| [Obsolete("Use Equals(Length other, Length tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] | |
| public bool Equals(Length other) | |
| { | |
| return new { Value, Unit }.Equals(new { other.Value, other.Unit }); | |
| } |
Shall we add a static class like Global Tolerance Configurations to let it work like the Equals method with tolerance? That would make things ez.
UnitsNet/UnitsNet/GeneratedCode/Quantities/Length.g.cs
Lines 1337 to 1345 in b57ac63
| /// <inheritdoc /> | |
| public bool Equals(Length other, Length tolerance) | |
| { | |
| return UnitsNet.Comparison.Equals( | |
| referenceValue: this.Value, | |
| otherValue: other.As(this.Unit), | |
| tolerance: tolerance.As(this.Unit), | |
| comparisonType: ComparisonType.Absolute); | |
| } |
So it should look like this.
public bool Equals(Length other)
{
return Equals(other, GlobalToleranceConfigurations.Length);
}