Skip to content

[Feature] Global Tolerance Configurations #1440

@Ted-Jin-Lab

Description

@Ted-Jin-Lab

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.

/// <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.

/// <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);
 } 

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions