From ce42aa89a7a0cac6f0f77ad28672f0769ac2376d Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 27 May 2023 01:37:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Equals()=20to=20IQuantity=20i?= =?UTF-8?q?nterfaces=20(#1215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref #1193 In v5, the default equality implementation changed to strict equality and the existing methods to compare across units with a tolerance, but this was not available in `IQuantity` interfaces. ### Changes - Add `Equals(IQuantity? other, IQuantity tolerance)` to `IQuantity` - Add `Equals(TSelf? other, TSelf tolerance)` to `IQuantity` for strongly typed comparisons - Obsolete `Equals(TQuantity other, double tolerance, ComparisonType comparisonType)` method in quantity types --- .../UnitsNetGen/QuantityGenerator.cs | 60 +++++++++----- UnitsNet.Tests/CustomQuantities/HowMuch.cs | 2 + UnitsNet.Tests/DummyIQuantity.cs | 4 + UnitsNet.Tests/QuantityTests.cs | 81 +++++++++++++++++++ UnitsNet.Tests/UnitsNet.Tests.csproj | 2 +- UnitsNet/Comparison.cs | 12 +-- .../Quantities/Acceleration.g.cs | 44 +++++++--- .../Quantities/AmountOfSubstance.g.cs | 42 +++++++--- .../Quantities/AmplitudeRatio.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Angle.g.cs | 42 +++++++--- .../Quantities/ApparentEnergy.g.cs | 42 +++++++--- .../Quantities/ApparentPower.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Area.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/AreaDensity.g.cs | 42 +++++++--- .../Quantities/AreaMomentOfInertia.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/BitRate.g.cs | 42 +++++++--- .../BrakeSpecificFuelConsumption.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Capacitance.g.cs | 42 +++++++--- .../CoefficientOfThermalExpansion.g.cs | 42 +++++++--- .../Quantities/Compressibility.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Density.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Duration.g.cs | 42 +++++++--- .../Quantities/DynamicViscosity.g.cs | 42 +++++++--- .../Quantities/ElectricAdmittance.g.cs | 42 +++++++--- .../Quantities/ElectricCharge.g.cs | 42 +++++++--- .../Quantities/ElectricChargeDensity.g.cs | 42 +++++++--- .../Quantities/ElectricConductance.g.cs | 42 +++++++--- .../Quantities/ElectricConductivity.g.cs | 42 +++++++--- .../Quantities/ElectricCurrent.g.cs | 42 +++++++--- .../Quantities/ElectricCurrentDensity.g.cs | 42 +++++++--- .../Quantities/ElectricCurrentGradient.g.cs | 42 +++++++--- .../Quantities/ElectricField.g.cs | 42 +++++++--- .../Quantities/ElectricInductance.g.cs | 42 +++++++--- .../Quantities/ElectricPotential.g.cs | 42 +++++++--- .../Quantities/ElectricPotentialAc.g.cs | 42 +++++++--- .../ElectricPotentialChangeRate.g.cs | 42 +++++++--- .../Quantities/ElectricPotentialDc.g.cs | 42 +++++++--- .../Quantities/ElectricResistance.g.cs | 42 +++++++--- .../Quantities/ElectricResistivity.g.cs | 42 +++++++--- .../ElectricSurfaceChargeDensity.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Energy.g.cs | 42 +++++++--- .../Quantities/EnergyDensity.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Entropy.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Force.g.cs | 42 +++++++--- .../Quantities/ForceChangeRate.g.cs | 42 +++++++--- .../Quantities/ForcePerLength.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Frequency.g.cs | 42 +++++++--- .../Quantities/FuelEfficiency.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/HeatFlux.g.cs | 42 +++++++--- .../Quantities/HeatTransferCoefficient.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Illuminance.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Impulse.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Information.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Irradiance.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Irradiation.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Jerk.g.cs | 42 +++++++--- .../Quantities/KinematicViscosity.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/LeakRate.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Length.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Level.g.cs | 42 +++++++--- .../Quantities/LinearDensity.g.cs | 42 +++++++--- .../Quantities/LinearPowerDensity.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Luminance.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Luminosity.g.cs | 42 +++++++--- .../Quantities/LuminousFlux.g.cs | 42 +++++++--- .../Quantities/LuminousIntensity.g.cs | 42 +++++++--- .../Quantities/MagneticField.g.cs | 42 +++++++--- .../Quantities/MagneticFlux.g.cs | 42 +++++++--- .../Quantities/Magnetization.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Mass.g.cs | 42 +++++++--- .../Quantities/MassConcentration.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/MassFlow.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/MassFlux.g.cs | 42 +++++++--- .../Quantities/MassFraction.g.cs | 42 +++++++--- .../Quantities/MassMomentOfInertia.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/MolarEnergy.g.cs | 42 +++++++--- .../Quantities/MolarEntropy.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/MolarFlow.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/MolarMass.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Molarity.g.cs | 42 +++++++--- .../Quantities/Permeability.g.cs | 42 +++++++--- .../Quantities/Permittivity.g.cs | 42 +++++++--- .../Quantities/PorousMediumPermeability.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Power.g.cs | 42 +++++++--- .../Quantities/PowerDensity.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/PowerRatio.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Pressure.g.cs | 42 +++++++--- .../Quantities/PressureChangeRate.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Ratio.g.cs | 42 +++++++--- .../Quantities/RatioChangeRate.g.cs | 42 +++++++--- .../Quantities/ReactiveEnergy.g.cs | 42 +++++++--- .../Quantities/ReactivePower.g.cs | 42 +++++++--- .../Quantities/ReciprocalArea.g.cs | 42 +++++++--- .../Quantities/ReciprocalLength.g.cs | 42 +++++++--- .../Quantities/RelativeHumidity.g.cs | 42 +++++++--- .../Quantities/RotationalAcceleration.g.cs | 42 +++++++--- .../Quantities/RotationalSpeed.g.cs | 42 +++++++--- .../Quantities/RotationalStiffness.g.cs | 42 +++++++--- .../RotationalStiffnessPerLength.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Scalar.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/SolidAngle.g.cs | 42 +++++++--- .../Quantities/SpecificEnergy.g.cs | 42 +++++++--- .../Quantities/SpecificEntropy.g.cs | 42 +++++++--- .../Quantities/SpecificFuelConsumption.g.cs | 42 +++++++--- .../Quantities/SpecificVolume.g.cs | 42 +++++++--- .../Quantities/SpecificWeight.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Speed.g.cs | 42 +++++++--- .../Quantities/StandardVolumeFlow.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Temperature.g.cs | 42 +++++++--- .../Quantities/TemperatureChangeRate.g.cs | 42 +++++++--- .../Quantities/TemperatureDelta.g.cs | 42 +++++++--- .../Quantities/TemperatureGradient.g.cs | 42 +++++++--- .../Quantities/ThermalConductivity.g.cs | 42 +++++++--- .../Quantities/ThermalResistance.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Torque.g.cs | 42 +++++++--- .../Quantities/TorquePerLength.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/Turbidity.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/VitaminA.g.cs | 42 +++++++--- UnitsNet/GeneratedCode/Quantities/Volume.g.cs | 42 +++++++--- .../Quantities/VolumeConcentration.g.cs | 42 +++++++--- .../GeneratedCode/Quantities/VolumeFlow.g.cs | 42 +++++++--- .../Quantities/VolumeFlowPerArea.g.cs | 42 +++++++--- .../Quantities/VolumePerLength.g.cs | 42 +++++++--- .../Quantities/VolumetricHeatCapacity.g.cs | 42 +++++++--- .../Quantities/WarpingMomentOfInertia.g.cs | 42 +++++++--- UnitsNet/IQuantity.cs | 50 +++++++++++- 126 files changed, 3753 insertions(+), 1458 deletions(-) diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs index 78a6c9fa59..66d033f8bc 100644 --- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs @@ -330,14 +330,14 @@ private void GenerateStaticMethods() /// The to register the default conversion functions in. internal static void RegisterDefaultConversions(UnitConverter unitConverter) {{ - // Register in unit converter: {_quantity.Name}Unit -> BaseUnit"); + // Register in unit converter: {_unitEnumName} -> BaseUnit"); foreach (Unit unit in _quantity.Units) { if (unit.SingularName == _quantity.BaseUnit) continue; Writer.WL($@" - unitConverter.SetConversionFunction<{_quantity.Name}>({_quantity.Name}Unit.{unit.SingularName}, {_unitEnumName}.{_quantity.BaseUnit}, quantity => quantity.ToUnit({_unitEnumName}.{_quantity.BaseUnit}));"); + unitConverter.SetConversionFunction<{_quantity.Name}>({_unitEnumName}.{unit.SingularName}, {_unitEnumName}.{_quantity.BaseUnit}, quantity => quantity.ToUnit({_unitEnumName}.{_quantity.BaseUnit}));"); } Writer.WL(); @@ -346,14 +346,14 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) // Register in unit converter: BaseUnit <-> BaseUnit unitConverter.SetConversionFunction<{_quantity.Name}>({_unitEnumName}.{_quantity.BaseUnit}, {_unitEnumName}.{_quantity.BaseUnit}, quantity => quantity); - // Register in unit converter: BaseUnit -> {_quantity.Name}Unit"); + // Register in unit converter: BaseUnit -> {_unitEnumName}"); foreach (Unit unit in _quantity.Units) { if (unit.SingularName == _quantity.BaseUnit) continue; Writer.WL($@" - unitConverter.SetConversionFunction<{_quantity.Name}>({_unitEnumName}.{_quantity.BaseUnit}, {_quantity.Name}Unit.{unit.SingularName}, quantity => quantity.ToUnit({_quantity.Name}Unit.{unit.SingularName}));"); + unitConverter.SetConversionFunction<{_quantity.Name}>({_unitEnumName}.{_quantity.BaseUnit}, {_unitEnumName}.{unit.SingularName}, quantity => quantity.ToUnit({_unitEnumName}.{unit.SingularName}));"); } Writer.WL($@" @@ -749,16 +749,14 @@ private void GenerateEqualityAndComparison() #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete(""For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals({_quantity.Name}, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + [Obsolete(""For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals({_quantity.Name} other, {_quantity.Name} 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 static bool operator ==({_quantity.Name} left, {_quantity.Name} right) {{ return left.Equals(right); }} /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete(""For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals({_quantity.Name}, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + [Obsolete(""For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals({_quantity.Name} other, {_quantity.Name} 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 static bool operator !=({_quantity.Name} left, {_quantity.Name} right) {{ return !(left == right); @@ -766,8 +764,7 @@ private void GenerateEqualityAndComparison() /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete(""Consider using Equals({_quantity.Name}, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + [Obsolete(""Use Equals({_quantity.Name} other, {_quantity.Name} 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 {_quantity.Name} otherQuantity)) @@ -778,8 +775,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete(""Consider using Equals({_quantity.Name}, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + [Obsolete(""Use Equals({_quantity.Name} other, {_quantity.Name} 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({_quantity.Name} other) {{ return new {{ Value, Unit }}.Equals(new {{ other.Value, other.Unit }}); @@ -863,15 +859,37 @@ public int CompareTo({_quantity.Name} other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete(""Use Equals({_quantity.Name} other, {_quantity.Name} 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({_quantity.Name} other, {_quantity.ValueType} tolerance, ComparisonType comparisonType) {{ if (tolerance < 0) - throw new ArgumentOutOfRangeException(""tolerance"", ""Tolerance must be greater than or equal to 0.""); + throw new ArgumentOutOfRangeException(nameof(tolerance), ""Tolerance must be greater than or equal to 0.""); - {_quantity.ValueType} thisValue = this.Value; - {_quantity.ValueType} otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + }} - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + {{ + return other is {_quantity.Name} otherTyped + && (tolerance is {_quantity.Name} toleranceTyped + ? true + : throw new ArgumentException($""Tolerance quantity ({{tolerance.QuantityInfo.Name}}) did not match the other quantities of type '{_quantity.Name}'."", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + }} + + /// + public bool Equals({_quantity.Name} other, {_quantity.Name} tolerance) + {{ + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); }} /// @@ -1011,7 +1029,7 @@ double IQuantity.As(Enum unit) /// The unit to convert to. /// The converted in , if successful. /// True if successful, otherwise false. - private bool TryToUnit({_quantity.Name}Unit unit, [NotNullWhen(true)] out {_quantity.Name}? converted) + private bool TryToUnit({_unitEnumName} unit, [NotNullWhen(true)] out {_quantity.Name}? converted) {{ if (Unit == unit) {{ @@ -1021,7 +1039,7 @@ private bool TryToUnit({_quantity.Name}Unit unit, [NotNullWhen(true)] out {_quan {_quantity.Name}? convertedOrNull = (Unit, unit) switch {{ - // {_quantity.Name}Unit -> BaseUnit"); + // {_unitEnumName} -> BaseUnit"); foreach (Unit unit in _quantity.Units) { @@ -1029,20 +1047,20 @@ private bool TryToUnit({_quantity.Name}Unit unit, [NotNullWhen(true)] out {_quan var func = unit.FromUnitToBaseFunc.Replace("{x}", "_value"); Writer.WL($@" - ({_quantity.Name}Unit.{unit.SingularName}, {_unitEnumName}.{_quantity.BaseUnit}) => new {_quantity.Name}({func}, {_unitEnumName}.{_quantity.BaseUnit}),"); + ({_unitEnumName}.{unit.SingularName}, {_unitEnumName}.{_quantity.BaseUnit}) => new {_quantity.Name}({func}, {_unitEnumName}.{_quantity.BaseUnit}),"); } Writer.WL(); Writer.WL($@" - // BaseUnit -> {_quantity.Name}Unit"); + // BaseUnit -> {_unitEnumName}"); foreach(Unit unit in _quantity.Units) { if (unit.SingularName == _quantity.BaseUnit) continue; var func = unit.FromBaseToUnitFunc.Replace("{x}", "_value"); Writer.WL($@" - ({_unitEnumName}.{_quantity.BaseUnit}, {_quantity.Name}Unit.{unit.SingularName}) => new {_quantity.Name}({func}, {_quantity.Name}Unit.{unit.SingularName}),"); + ({_unitEnumName}.{_quantity.BaseUnit}, {_unitEnumName}.{unit.SingularName}) => new {_quantity.Name}({func}, {_unitEnumName}.{unit.SingularName}),"); } Writer.WL(); diff --git a/UnitsNet.Tests/CustomQuantities/HowMuch.cs b/UnitsNet.Tests/CustomQuantities/HowMuch.cs index bada53f7c8..f9b39f918b 100644 --- a/UnitsNet.Tests/CustomQuantities/HowMuch.cs +++ b/UnitsNet.Tests/CustomQuantities/HowMuch.cs @@ -14,6 +14,8 @@ public HowMuch(double value, HowMuchUnit unit) Value = value; } + public bool Equals(IQuantity? other, IQuantity tolerance) => throw new NotImplementedException(); + Enum IQuantity.Unit => Unit; public HowMuchUnit Unit { get; } diff --git a/UnitsNet.Tests/DummyIQuantity.cs b/UnitsNet.Tests/DummyIQuantity.cs index bd9f57c2e7..01a39f4eb3 100644 --- a/UnitsNet.Tests/DummyIQuantity.cs +++ b/UnitsNet.Tests/DummyIQuantity.cs @@ -9,6 +9,8 @@ internal class DummyIQuantity : IQuantity public QuantityInfo QuantityInfo => throw new NotImplementedException(); + bool IQuantity.Equals(IQuantity? other, IQuantity tolerance) => throw new NotImplementedException(); + public Enum Unit => throw new NotImplementedException(); public QuantityValue Value => throw new NotImplementedException(); @@ -17,6 +19,8 @@ internal class DummyIQuantity : IQuantity public double As(UnitSystem unitSystem ) => throw new NotImplementedException(); + public bool Equals(IQuantity? other, double tolerance, ComparisonType comparisonType) => throw new NotImplementedException(); + public string ToString(IFormatProvider? provider) => throw new NotImplementedException(); public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException(); diff --git a/UnitsNet.Tests/QuantityTests.cs b/UnitsNet.Tests/QuantityTests.cs index 4e4ad0759c..98adbafa4a 100644 --- a/UnitsNet.Tests/QuantityTests.cs +++ b/UnitsNet.Tests/QuantityTests.cs @@ -1,6 +1,8 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. +using System; +using System.Globalization; using UnitsNet.Units; using Xunit; @@ -16,5 +18,84 @@ public void GetHashCodeForDifferentQuantitiesWithSameValuesAreNotEqual() Assert.NotEqual(length.GetHashCode(), area.GetHashCode()); } + + [Theory] + [InlineData("10 m", "9.89 m" , "0.1 m", false)] // +/- 0.1m absolute tolerance and some additional margin tolerate rounding errors in test case. + [InlineData("10 m", "9.91 m" , "0.1 m", true)] + [InlineData("10 m", "10.09 m", "0.1 m", true)] + [InlineData("10 m", "1009 cm", "0.1 m", true)] // Different unit, still equal. + [InlineData("10 m", "10.11 m", "0.1 m", false)] + [InlineData("10 m", "8.9 m" , "0.1 m", false)] // +/- 1m relative tolerance (10%) and some additional margin tolerate rounding errors in test case. + public void Equals_IGenericEquatableQuantity(string q1String, string q2String, string toleranceString, bool expectedEqual) + { + // This interfaces implements .NET generic math interfaces. + IQuantity q1 = ParseLength(q1String); + IQuantity q2 = ParseLength(q2String); + IQuantity tolerance = ParseLength(toleranceString); + + Assert.Equal(expectedEqual, q1.Equals(q2, tolerance)); + } + + [Theory] + [InlineData("10 m", "9.89 m" , "0.1 m", false)] // +/- 0.1m absolute tolerance and some additional margin tolerate rounding errors in test case. + [InlineData("10 m", "9.91 m" , "0.1 m", true)] + [InlineData("10 m", "10.09 m", "0.1 m", true)] + [InlineData("10 m", "1009 cm", "0.1 m", true)] // Different unit, still equal. + [InlineData("10 m", "10.11 m", "0.1 m", false)] + [InlineData("10 m", "8.9 m" , "0.1 m", false)] // +/- 1m relative tolerance (10%) and some additional margin tolerate rounding errors in test case. + public void Equals_IQuantity(string q1String, string q2String, string toleranceString, bool expectedEqual) + { + IQuantity q1 = ParseLength(q1String); + IQuantity q2 = ParseLength(q2String); + IQuantity tolerance = ParseLength(toleranceString); + + Assert.NotEqual(q1, q2); // Strict equality should not be equal. + Assert.Equal(expectedEqual, q1.Equals(q2, tolerance)); + } + + [Fact] + public void Equals_IQuantity_OtherIsNull_ReturnsFalse() + { + IQuantity q1 = ParseLength("10 m"); + IQuantity? q2 = null; + IQuantity tolerance = ParseLength("0.1 m"); + + Assert.False(q1.Equals(q2, tolerance)); + } + + [Fact] + public void Equals_IQuantity_OtherIsDifferentType_ReturnsFalse() + { + IQuantity q1 = ParseLength("10 m"); + IQuantity q2 = Mass.FromKilograms(10); + IQuantity tolerance = Mass.FromKilograms(0.1); + + Assert.False(q1.Equals(q2, tolerance)); + } + + [Fact] + public void Equals_IQuantity_ToleranceIsDifferentType_Throws() + { + IQuantity q1 = ParseLength("10 m"); + IQuantity q2 = ParseLength("10 m"); + IQuantity tolerance = Mass.FromKilograms(0.1); + + Assert.Throws(() => q1.Equals(q2, tolerance)); + } + + [Fact] + public void Equals_GenericEquatableIQuantity_OtherIsNull_ReturnsFalse() + { + IQuantity q1 = ParseLength("10 m"); + IQuantity? q2 = null; + IQuantity tolerance = ParseLength("0.1 m"); + + Assert.False(q1.Equals(q2, tolerance)); + } + + private static Length ParseLength(string str) + { + return Length.Parse(str, CultureInfo.InvariantCulture); + } } } diff --git a/UnitsNet.Tests/UnitsNet.Tests.csproj b/UnitsNet.Tests/UnitsNet.Tests.csproj index 67cd43b1de..9fbd0a02f3 100644 --- a/UnitsNet.Tests/UnitsNet.Tests.csproj +++ b/UnitsNet.Tests/UnitsNet.Tests.csproj @@ -4,7 +4,7 @@ net7.0;net48 latest true - CS0618 + CS0618 enable diff --git a/UnitsNet/Comparison.cs b/UnitsNet/Comparison.cs index ac6726c3e2..6c5a405a9d 100644 --- a/UnitsNet/Comparison.cs +++ b/UnitsNet/Comparison.cs @@ -52,7 +52,7 @@ public static class Comparison public static bool Equals(double referenceValue, double otherValue, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0"); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0"); switch (comparisonType) { @@ -107,7 +107,7 @@ public static bool Equals(double referenceValue, double otherValue, double toler public static bool Equals(decimal referenceValue, decimal otherValue, decimal tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0"); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0"); switch (comparisonType) { @@ -144,7 +144,7 @@ public static bool Equals(decimal referenceValue, decimal otherValue, decimal to public static bool EqualsRelative(double referenceValue, double otherValue, double tolerance) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0"); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0"); var maxVariation = Math.Abs(referenceValue * tolerance); return Math.Abs(referenceValue - otherValue) <= maxVariation; @@ -174,7 +174,7 @@ public static bool EqualsRelative(double referenceValue, double otherValue, doub public static bool EqualsRelative(decimal referenceValue, decimal otherValue, decimal tolerance) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0"); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0"); var maxVariation = Math.Abs(referenceValue * tolerance); return Math.Abs(referenceValue - otherValue) <= maxVariation; @@ -202,7 +202,7 @@ public static bool EqualsRelative(decimal referenceValue, decimal otherValue, de public static bool EqualsAbsolute(double value1, double value2, double tolerance) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0"); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0"); return Math.Abs(value1 - value2) <= tolerance; } @@ -229,7 +229,7 @@ public static bool EqualsAbsolute(double value1, double value2, double tolerance public static bool EqualsAbsolute(decimal value1, decimal value2, decimal tolerance) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0"); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0"); return Math.Abs(value1 - value2) <= tolerance; } diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 50c61da5df..6d6e96aef6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -151,7 +151,7 @@ public Acceleration(double value, UnitSystem unitSystem) public static Acceleration AdditiveIdentity => Zero; #endregion - + #region Properties /// @@ -727,16 +727,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Accel #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Acceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Acceleration other, Acceleration 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 static bool operator ==(Acceleration left, Acceleration right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Acceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Acceleration other, Acceleration 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 static bool operator !=(Acceleration left, Acceleration right) { return !(left == right); @@ -744,8 +742,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Accel /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Acceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Acceleration other, Acceleration 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 Acceleration otherQuantity)) @@ -756,8 +753,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Acceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Acceleration other, Acceleration 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(Acceleration other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -841,15 +837,37 @@ public int CompareTo(Acceleration other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Acceleration other, Acceleration 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(Acceleration other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); + + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Acceleration otherTyped + && (tolerance is Acceleration toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Acceleration'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(Acceleration other, Acceleration tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs index d0e2a9b1ca..7937aeb386 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs @@ -732,16 +732,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Amoun #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(AmountOfSubstance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AmountOfSubstance other, AmountOfSubstance 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 static bool operator ==(AmountOfSubstance left, AmountOfSubstance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(AmountOfSubstance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AmountOfSubstance other, AmountOfSubstance 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 static bool operator !=(AmountOfSubstance left, AmountOfSubstance right) { return !(left == right); @@ -749,8 +747,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Amoun /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AmountOfSubstance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AmountOfSubstance other, AmountOfSubstance 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 AmountOfSubstance otherQuantity)) @@ -761,8 +758,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AmountOfSubstance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AmountOfSubstance other, AmountOfSubstance 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(AmountOfSubstance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -846,15 +842,37 @@ public int CompareTo(AmountOfSubstance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(AmountOfSubstance other, AmountOfSubstance 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(AmountOfSubstance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is AmountOfSubstance otherTyped + && (tolerance is AmountOfSubstance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'AmountOfSubstance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(AmountOfSubstance other, AmountOfSubstance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs index 26a4b35dd2..969d381adb 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs @@ -531,16 +531,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ampli #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(AmplitudeRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AmplitudeRatio other, AmplitudeRatio 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 static bool operator ==(AmplitudeRatio left, AmplitudeRatio right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(AmplitudeRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AmplitudeRatio other, AmplitudeRatio 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 static bool operator !=(AmplitudeRatio left, AmplitudeRatio right) { return !(left == right); @@ -548,8 +546,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ampli /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AmplitudeRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AmplitudeRatio other, AmplitudeRatio 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 AmplitudeRatio otherQuantity)) @@ -560,8 +557,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AmplitudeRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AmplitudeRatio other, AmplitudeRatio 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(AmplitudeRatio other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -645,15 +641,37 @@ public int CompareTo(AmplitudeRatio other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(AmplitudeRatio other, AmplitudeRatio 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(AmplitudeRatio other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is AmplitudeRatio otherTyped + && (tolerance is AmplitudeRatio toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'AmplitudeRatio'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(AmplitudeRatio other, AmplitudeRatio tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index 27c248be69..b4cda3142d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -763,16 +763,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Angle #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Angle other, Angle 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 static bool operator ==(Angle left, Angle right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Angle other, Angle 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 static bool operator !=(Angle left, Angle right) { return !(left == right); @@ -780,8 +778,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Angle /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Angle other, Angle 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 Angle otherQuantity)) @@ -792,8 +789,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Angle other, Angle 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(Angle other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -877,15 +873,37 @@ public int CompareTo(Angle other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Angle other, Angle 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(Angle other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Angle otherTyped + && (tolerance is Angle toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Angle'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Angle other, Angle tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs index baf290ad86..ced57734a1 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Appar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ApparentEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ApparentEnergy other, ApparentEnergy 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 static bool operator ==(ApparentEnergy left, ApparentEnergy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ApparentEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ApparentEnergy other, ApparentEnergy 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 static bool operator !=(ApparentEnergy left, ApparentEnergy right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Appar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ApparentEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ApparentEnergy other, ApparentEnergy 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 ApparentEnergy otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ApparentEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ApparentEnergy other, ApparentEnergy 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(ApparentEnergy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(ApparentEnergy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ApparentEnergy other, ApparentEnergy 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(ApparentEnergy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ApparentEnergy otherTyped + && (tolerance is ApparentEnergy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ApparentEnergy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ApparentEnergy other, ApparentEnergy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs index bfc6980144..b2d646fb8c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs @@ -561,16 +561,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Appar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ApparentPower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ApparentPower other, ApparentPower 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 static bool operator ==(ApparentPower left, ApparentPower right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ApparentPower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ApparentPower other, ApparentPower 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 static bool operator !=(ApparentPower left, ApparentPower right) { return !(left == right); @@ -578,8 +576,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Appar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ApparentPower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ApparentPower other, ApparentPower 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 ApparentPower otherQuantity)) @@ -590,8 +587,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ApparentPower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ApparentPower other, ApparentPower 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(ApparentPower other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -675,15 +671,37 @@ public int CompareTo(ApparentPower other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ApparentPower other, ApparentPower 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(ApparentPower other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ApparentPower otherTyped + && (tolerance is ApparentPower toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ApparentPower'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ApparentPower other, ApparentPower tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index 4de92cb165..368dc2eeed 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -740,16 +740,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Area, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Area other, Area 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 static bool operator ==(Area left, Area right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Area, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Area other, Area 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 static bool operator !=(Area left, Area right) { return !(left == right); @@ -757,8 +755,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Area, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Area other, Area 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 Area otherQuantity)) @@ -769,8 +766,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Area, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Area other, Area 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(Area other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -854,15 +850,37 @@ public int CompareTo(Area other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Area other, Area 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(Area other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Area otherTyped + && (tolerance is Area toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Area'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Area other, Area tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs index f989873016..bd3eb2c19a 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaD #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(AreaDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AreaDensity other, AreaDensity 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 static bool operator ==(AreaDensity left, AreaDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(AreaDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AreaDensity other, AreaDensity 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 static bool operator !=(AreaDensity left, AreaDensity right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaD /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AreaDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AreaDensity other, AreaDensity 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 AreaDensity otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AreaDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AreaDensity other, AreaDensity 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(AreaDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(AreaDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(AreaDensity other, AreaDensity 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(AreaDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is AreaDensity otherTyped + && (tolerance is AreaDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'AreaDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(AreaDensity other, AreaDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs index 2a63adeb01..100e1f3a4e 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs @@ -561,16 +561,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaM #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(AreaMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AreaMomentOfInertia other, AreaMomentOfInertia 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 static bool operator ==(AreaMomentOfInertia left, AreaMomentOfInertia right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(AreaMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(AreaMomentOfInertia other, AreaMomentOfInertia 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 static bool operator !=(AreaMomentOfInertia left, AreaMomentOfInertia right) { return !(left == right); @@ -578,8 +576,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaM /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AreaMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AreaMomentOfInertia other, AreaMomentOfInertia 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 AreaMomentOfInertia otherQuantity)) @@ -590,8 +587,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(AreaMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(AreaMomentOfInertia other, AreaMomentOfInertia 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(AreaMomentOfInertia other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -675,15 +671,37 @@ public int CompareTo(AreaMomentOfInertia other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(AreaMomentOfInertia other, AreaMomentOfInertia 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(AreaMomentOfInertia other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is AreaMomentOfInertia otherTyped + && (tolerance is AreaMomentOfInertia toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'AreaMomentOfInertia'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(AreaMomentOfInertia other, AreaMomentOfInertia tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs index 49e9903f31..6444f5e964 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs @@ -945,16 +945,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out BitRa #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(BitRate, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(BitRate other, BitRate 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 static bool operator ==(BitRate left, BitRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(BitRate, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(BitRate other, BitRate 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 static bool operator !=(BitRate left, BitRate right) { return !(left == right); @@ -962,8 +960,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out BitRa /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(BitRate, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(BitRate other, BitRate 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 BitRate otherQuantity)) @@ -974,8 +971,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(BitRate, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(BitRate other, BitRate 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(BitRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1059,15 +1055,37 @@ public int CompareTo(BitRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(BitRate other, BitRate 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(BitRate other, decimal tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - decimal thisValue = this.Value; - decimal otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is BitRate otherTyped + && (tolerance is BitRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'BitRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(BitRate other, BitRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs index 3cb5f0382c..61bd08bd7c 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Brake #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(BrakeSpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(BrakeSpecificFuelConsumption other, BrakeSpecificFuelConsumption 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 static bool operator ==(BrakeSpecificFuelConsumption left, BrakeSpecificFuelConsumption right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(BrakeSpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(BrakeSpecificFuelConsumption other, BrakeSpecificFuelConsumption 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 static bool operator !=(BrakeSpecificFuelConsumption left, BrakeSpecificFuelConsumption right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Brake /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(BrakeSpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(BrakeSpecificFuelConsumption other, BrakeSpecificFuelConsumption 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 BrakeSpecificFuelConsumption otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(BrakeSpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(BrakeSpecificFuelConsumption other, BrakeSpecificFuelConsumption 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(BrakeSpecificFuelConsumption other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(BrakeSpecificFuelConsumption other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(BrakeSpecificFuelConsumption other, BrakeSpecificFuelConsumption 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(BrakeSpecificFuelConsumption other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is BrakeSpecificFuelConsumption otherTyped + && (tolerance is BrakeSpecificFuelConsumption toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'BrakeSpecificFuelConsumption'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(BrakeSpecificFuelConsumption other, BrakeSpecificFuelConsumption tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs index 26743b160c..b30bee2741 100644 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs @@ -583,16 +583,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Capac #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Capacitance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Capacitance other, Capacitance 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 static bool operator ==(Capacitance left, Capacitance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Capacitance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Capacitance other, Capacitance 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 static bool operator !=(Capacitance left, Capacitance right) { return !(left == right); @@ -600,8 +598,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Capac /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Capacitance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Capacitance other, Capacitance 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 Capacitance otherQuantity)) @@ -612,8 +609,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Capacitance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Capacitance other, Capacitance 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(Capacitance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -697,15 +693,37 @@ public int CompareTo(Capacitance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Capacitance other, Capacitance 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(Capacitance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Capacitance otherTyped + && (tolerance is Capacitance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Capacitance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Capacitance other, Capacitance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs index 6b116c03db..509cd8018a 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Coeff #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(CoefficientOfThermalExpansion, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(CoefficientOfThermalExpansion other, CoefficientOfThermalExpansion 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 static bool operator ==(CoefficientOfThermalExpansion left, CoefficientOfThermalExpansion right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(CoefficientOfThermalExpansion, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(CoefficientOfThermalExpansion other, CoefficientOfThermalExpansion 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 static bool operator !=(CoefficientOfThermalExpansion left, CoefficientOfThermalExpansion right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Coeff /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(CoefficientOfThermalExpansion, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(CoefficientOfThermalExpansion other, CoefficientOfThermalExpansion 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 CoefficientOfThermalExpansion otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(CoefficientOfThermalExpansion, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(CoefficientOfThermalExpansion other, CoefficientOfThermalExpansion 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(CoefficientOfThermalExpansion other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(CoefficientOfThermalExpansion other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(CoefficientOfThermalExpansion other, CoefficientOfThermalExpansion 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(CoefficientOfThermalExpansion other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is CoefficientOfThermalExpansion otherTyped + && (tolerance is CoefficientOfThermalExpansion toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'CoefficientOfThermalExpansion'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(CoefficientOfThermalExpansion other, CoefficientOfThermalExpansion tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs index d9745f5396..9dc6d3682b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs @@ -580,16 +580,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Compr #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Compressibility, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Compressibility other, Compressibility 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 static bool operator ==(Compressibility left, Compressibility right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Compressibility, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Compressibility other, Compressibility 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 static bool operator !=(Compressibility left, Compressibility right) { return !(left == right); @@ -597,8 +595,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Compr /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Compressibility, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Compressibility other, Compressibility 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 Compressibility otherQuantity)) @@ -609,8 +606,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Compressibility, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Compressibility other, Compressibility 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(Compressibility other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -694,15 +690,37 @@ public int CompareTo(Compressibility other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Compressibility other, Compressibility 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(Compressibility other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Compressibility otherTyped + && (tolerance is Compressibility toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Compressibility'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Compressibility other, Compressibility tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs index ae27d2e4d7..0eac171657 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs @@ -1423,16 +1423,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Densi #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Density, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Density other, Density 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 static bool operator ==(Density left, Density right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Density, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Density other, Density 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 static bool operator !=(Density left, Density right) { return !(left == right); @@ -1440,8 +1438,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Densi /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Density, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Density other, Density 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 Density otherQuantity)) @@ -1452,8 +1449,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Density, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Density other, Density 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(Density other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1537,15 +1533,37 @@ public int CompareTo(Density other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Density other, Density 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(Density other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Density otherTyped + && (tolerance is Density toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Density'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Density other, Density tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs index ceea4f803a..9bb094d8b1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs @@ -666,16 +666,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Durat #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Duration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Duration other, Duration 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 static bool operator ==(Duration left, Duration right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Duration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Duration other, Duration 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 static bool operator !=(Duration left, Duration right) { return !(left == right); @@ -683,8 +681,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Durat /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Duration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Duration other, Duration 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 Duration otherQuantity)) @@ -695,8 +692,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Duration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Duration other, Duration 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(Duration other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -780,15 +776,37 @@ public int CompareTo(Duration other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Duration other, Duration 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(Duration other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Duration otherTyped + && (tolerance is Duration toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Duration'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Duration other, Duration tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs index eb1ad0a3ae..3732303070 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs @@ -640,16 +640,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Dynam #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(DynamicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(DynamicViscosity other, DynamicViscosity 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 static bool operator ==(DynamicViscosity left, DynamicViscosity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(DynamicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(DynamicViscosity other, DynamicViscosity 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 static bool operator !=(DynamicViscosity left, DynamicViscosity right) { return !(left == right); @@ -657,8 +655,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Dynam /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(DynamicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(DynamicViscosity other, DynamicViscosity 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 DynamicViscosity otherQuantity)) @@ -669,8 +666,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(DynamicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(DynamicViscosity other, DynamicViscosity 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(DynamicViscosity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -754,15 +750,37 @@ public int CompareTo(DynamicViscosity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(DynamicViscosity other, DynamicViscosity 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(DynamicViscosity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is DynamicViscosity otherTyped + && (tolerance is DynamicViscosity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'DynamicViscosity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(DynamicViscosity other, DynamicViscosity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs index e71b52a4ee..676cefe537 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -523,16 +523,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricAdmittance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricAdmittance other, ElectricAdmittance 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 static bool operator ==(ElectricAdmittance left, ElectricAdmittance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricAdmittance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricAdmittance other, ElectricAdmittance 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 static bool operator !=(ElectricAdmittance left, ElectricAdmittance right) { return !(left == right); @@ -540,8 +538,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricAdmittance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricAdmittance other, ElectricAdmittance 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 ElectricAdmittance otherQuantity)) @@ -552,8 +549,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricAdmittance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricAdmittance other, ElectricAdmittance 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(ElectricAdmittance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -637,15 +633,37 @@ public int CompareTo(ElectricAdmittance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricAdmittance other, ElectricAdmittance 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(ElectricAdmittance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricAdmittance otherTyped + && (tolerance is ElectricAdmittance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricAdmittance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricAdmittance other, ElectricAdmittance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs index 3c0b3b2ec7..bed8124cdd 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -659,16 +659,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCharge, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCharge other, ElectricCharge 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 static bool operator ==(ElectricCharge left, ElectricCharge right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCharge, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCharge other, ElectricCharge 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 static bool operator !=(ElectricCharge left, ElectricCharge right) { return !(left == right); @@ -676,8 +674,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCharge, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCharge other, ElectricCharge 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 ElectricCharge otherQuantity)) @@ -688,8 +685,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCharge, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCharge other, ElectricCharge 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(ElectricCharge other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -773,15 +769,37 @@ public int CompareTo(ElectricCharge other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricCharge other, ElectricCharge 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(ElectricCharge other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricCharge otherTyped + && (tolerance is ElectricCharge toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricCharge'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricCharge other, ElectricCharge tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs index 5d22f8248d..d003058b2b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricChargeDensity other, ElectricChargeDensity 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 static bool operator ==(ElectricChargeDensity left, ElectricChargeDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricChargeDensity other, ElectricChargeDensity 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 static bool operator !=(ElectricChargeDensity left, ElectricChargeDensity right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricChargeDensity other, ElectricChargeDensity 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 ElectricChargeDensity otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricChargeDensity other, ElectricChargeDensity 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(ElectricChargeDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(ElectricChargeDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricChargeDensity other, ElectricChargeDensity 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(ElectricChargeDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricChargeDensity otherTyped + && (tolerance is ElectricChargeDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricChargeDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricChargeDensity other, ElectricChargeDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs index d5b1e09d3d..0969dfe189 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -545,16 +545,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricConductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricConductance other, ElectricConductance 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 static bool operator ==(ElectricConductance left, ElectricConductance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricConductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricConductance other, ElectricConductance 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 static bool operator !=(ElectricConductance left, ElectricConductance right) { return !(left == right); @@ -562,8 +560,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricConductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricConductance other, ElectricConductance 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 ElectricConductance otherQuantity)) @@ -574,8 +571,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricConductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricConductance other, ElectricConductance 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(ElectricConductance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -659,15 +655,37 @@ public int CompareTo(ElectricConductance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricConductance other, ElectricConductance 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(ElectricConductance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricConductance otherTyped + && (tolerance is ElectricConductance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricConductance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricConductance other, ElectricConductance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs index 3e9c568fe9..0f771dcc46 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs @@ -564,16 +564,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricConductivity other, ElectricConductivity 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 static bool operator ==(ElectricConductivity left, ElectricConductivity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricConductivity other, ElectricConductivity 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 static bool operator !=(ElectricConductivity left, ElectricConductivity right) { return !(left == right); @@ -581,8 +579,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricConductivity other, ElectricConductivity 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 ElectricConductivity otherQuantity)) @@ -593,8 +590,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricConductivity other, ElectricConductivity 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(ElectricConductivity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -678,15 +674,37 @@ public int CompareTo(ElectricConductivity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricConductivity other, ElectricConductivity 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(ElectricConductivity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricConductivity otherTyped + && (tolerance is ElectricConductivity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricConductivity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricConductivity other, ElectricConductivity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 5833e54875..e1e497fde6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -618,16 +618,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCurrent, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCurrent other, ElectricCurrent 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 static bool operator ==(ElectricCurrent left, ElectricCurrent right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCurrent, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCurrent other, ElectricCurrent 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 static bool operator !=(ElectricCurrent left, ElectricCurrent right) { return !(left == right); @@ -635,8 +633,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCurrent, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCurrent other, ElectricCurrent 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 ElectricCurrent otherQuantity)) @@ -647,8 +644,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCurrent, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCurrent other, ElectricCurrent 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(ElectricCurrent other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -732,15 +728,37 @@ public int CompareTo(ElectricCurrent other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricCurrent other, ElectricCurrent 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(ElectricCurrent other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricCurrent otherTyped + && (tolerance is ElectricCurrent toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricCurrent'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricCurrent other, ElectricCurrent tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs index f73aa42c69..7f87d89d75 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs @@ -507,16 +507,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCurrentDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCurrentDensity other, ElectricCurrentDensity 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 static bool operator ==(ElectricCurrentDensity left, ElectricCurrentDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCurrentDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCurrentDensity other, ElectricCurrentDensity 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 static bool operator !=(ElectricCurrentDensity left, ElectricCurrentDensity right) { return !(left == right); @@ -524,8 +522,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCurrentDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCurrentDensity other, ElectricCurrentDensity 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 ElectricCurrentDensity otherQuantity)) @@ -536,8 +533,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCurrentDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCurrentDensity other, ElectricCurrentDensity 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(ElectricCurrentDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -621,15 +617,37 @@ public int CompareTo(ElectricCurrentDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricCurrentDensity other, ElectricCurrentDensity 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(ElectricCurrentDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricCurrentDensity otherTyped + && (tolerance is ElectricCurrentDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricCurrentDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricCurrentDensity other, ElectricCurrentDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs index ee29ac5b7a..d1aadf044a 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -523,16 +523,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCurrentGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCurrentGradient other, ElectricCurrentGradient 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 static bool operator ==(ElectricCurrentGradient left, ElectricCurrentGradient right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricCurrentGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricCurrentGradient other, ElectricCurrentGradient 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 static bool operator !=(ElectricCurrentGradient left, ElectricCurrentGradient right) { return !(left == right); @@ -540,8 +538,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCurrentGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCurrentGradient other, ElectricCurrentGradient 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 ElectricCurrentGradient otherQuantity)) @@ -552,8 +549,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricCurrentGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricCurrentGradient other, ElectricCurrentGradient 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(ElectricCurrentGradient other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -637,15 +633,37 @@ public int CompareTo(ElectricCurrentGradient other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricCurrentGradient other, ElectricCurrentGradient 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(ElectricCurrentGradient other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricCurrentGradient otherTyped + && (tolerance is ElectricCurrentGradient toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricCurrentGradient'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricCurrentGradient other, ElectricCurrentGradient tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs index 8ab10f5056..50b53bb4a8 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricField other, ElectricField 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 static bool operator ==(ElectricField left, ElectricField right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricField other, ElectricField 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 static bool operator !=(ElectricField left, ElectricField right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricField other, ElectricField 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 ElectricField otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricField other, ElectricField 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(ElectricField other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(ElectricField other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricField other, ElectricField 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(ElectricField other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricField otherTyped + && (tolerance is ElectricField toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricField'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricField other, ElectricField tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs index 9fe8cc6a8c..e9ed0530c7 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs @@ -545,16 +545,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricInductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricInductance other, ElectricInductance 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 static bool operator ==(ElectricInductance left, ElectricInductance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricInductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricInductance other, ElectricInductance 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 static bool operator !=(ElectricInductance left, ElectricInductance right) { return !(left == right); @@ -562,8 +560,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricInductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricInductance other, ElectricInductance 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 ElectricInductance otherQuantity)) @@ -574,8 +571,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricInductance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricInductance other, ElectricInductance 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(ElectricInductance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -659,15 +655,37 @@ public int CompareTo(ElectricInductance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricInductance other, ElectricInductance 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(ElectricInductance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricInductance otherTyped + && (tolerance is ElectricInductance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricInductance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricInductance other, ElectricInductance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs index 1655b702a9..29f9e8b35f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -567,16 +567,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotential, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotential other, ElectricPotential 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 static bool operator ==(ElectricPotential left, ElectricPotential right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotential, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotential other, ElectricPotential 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 static bool operator !=(ElectricPotential left, ElectricPotential right) { return !(left == right); @@ -584,8 +582,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotential, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotential other, ElectricPotential 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 ElectricPotential otherQuantity)) @@ -596,8 +593,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotential, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotential other, ElectricPotential 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(ElectricPotential other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -681,15 +677,37 @@ public int CompareTo(ElectricPotential other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricPotential other, ElectricPotential 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(ElectricPotential other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricPotential otherTyped + && (tolerance is ElectricPotential toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricPotential'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricPotential other, ElectricPotential tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs index 8c243b0b9b..102bfe9304 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs @@ -542,16 +542,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotentialAc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialAc other, ElectricPotentialAc 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 static bool operator ==(ElectricPotentialAc left, ElectricPotentialAc right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotentialAc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialAc other, ElectricPotentialAc 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 static bool operator !=(ElectricPotentialAc left, ElectricPotentialAc right) { return !(left == right); @@ -559,8 +557,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotentialAc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotentialAc other, ElectricPotentialAc 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 ElectricPotentialAc otherQuantity)) @@ -571,8 +568,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotentialAc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotentialAc other, ElectricPotentialAc 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(ElectricPotentialAc other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -656,15 +652,37 @@ public int CompareTo(ElectricPotentialAc other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricPotentialAc other, ElectricPotentialAc 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(ElectricPotentialAc other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricPotentialAc otherTyped + && (tolerance is ElectricPotentialAc toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricPotentialAc'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs index 204fdb920b..c562f5df94 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -827,16 +827,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotentialChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialChangeRate other, ElectricPotentialChangeRate 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 static bool operator ==(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotentialChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialChangeRate other, ElectricPotentialChangeRate 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 static bool operator !=(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) { return !(left == right); @@ -844,8 +842,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotentialChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotentialChangeRate other, ElectricPotentialChangeRate 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 ElectricPotentialChangeRate otherQuantity)) @@ -856,8 +853,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotentialChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotentialChangeRate other, ElectricPotentialChangeRate 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(ElectricPotentialChangeRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -941,15 +937,37 @@ public int CompareTo(ElectricPotentialChangeRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricPotentialChangeRate other, ElectricPotentialChangeRate 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(ElectricPotentialChangeRate other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricPotentialChangeRate otherTyped + && (tolerance is ElectricPotentialChangeRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricPotentialChangeRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricPotentialChangeRate other, ElectricPotentialChangeRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs index 7e329382a4..210101cc08 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs @@ -542,16 +542,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotentialDc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialDc other, ElectricPotentialDc 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 static bool operator ==(ElectricPotentialDc left, ElectricPotentialDc right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricPotentialDc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialDc other, ElectricPotentialDc 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 static bool operator !=(ElectricPotentialDc left, ElectricPotentialDc right) { return !(left == right); @@ -559,8 +557,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotentialDc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotentialDc other, ElectricPotentialDc 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 ElectricPotentialDc otherQuantity)) @@ -571,8 +568,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricPotentialDc, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricPotentialDc other, ElectricPotentialDc 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(ElectricPotentialDc other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -656,15 +652,37 @@ public int CompareTo(ElectricPotentialDc other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricPotentialDc other, ElectricPotentialDc 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(ElectricPotentialDc other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricPotentialDc otherTyped + && (tolerance is ElectricPotentialDc toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricPotentialDc'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs index dca339be01..ed228d427a 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -580,16 +580,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricResistance other, ElectricResistance 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 static bool operator ==(ElectricResistance left, ElectricResistance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricResistance other, ElectricResistance 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 static bool operator !=(ElectricResistance left, ElectricResistance right) { return !(left == right); @@ -597,8 +595,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricResistance other, ElectricResistance 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 ElectricResistance otherQuantity)) @@ -609,8 +606,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricResistance other, ElectricResistance 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(ElectricResistance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -694,15 +690,37 @@ public int CompareTo(ElectricResistance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricResistance other, ElectricResistance 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(ElectricResistance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricResistance otherTyped + && (tolerance is ElectricResistance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricResistance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricResistance other, ElectricResistance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs index 0159a5d433..c88e4b639e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs @@ -716,16 +716,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricResistivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricResistivity other, ElectricResistivity 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 static bool operator ==(ElectricResistivity left, ElectricResistivity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricResistivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricResistivity other, ElectricResistivity 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 static bool operator !=(ElectricResistivity left, ElectricResistivity right) { return !(left == right); @@ -733,8 +731,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricResistivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricResistivity other, ElectricResistivity 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 ElectricResistivity otherQuantity)) @@ -745,8 +742,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricResistivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricResistivity other, ElectricResistivity 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(ElectricResistivity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -830,15 +826,37 @@ public int CompareTo(ElectricResistivity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricResistivity other, ElectricResistivity 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(ElectricResistivity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricResistivity otherTyped + && (tolerance is ElectricResistivity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricResistivity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricResistivity other, ElectricResistivity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs index 6a79037987..211dd2fb47 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs @@ -507,16 +507,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricSurfaceChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricSurfaceChargeDensity other, ElectricSurfaceChargeDensity 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 static bool operator ==(ElectricSurfaceChargeDensity left, ElectricSurfaceChargeDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ElectricSurfaceChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricSurfaceChargeDensity other, ElectricSurfaceChargeDensity 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 static bool operator !=(ElectricSurfaceChargeDensity left, ElectricSurfaceChargeDensity right) { return !(left == right); @@ -524,8 +522,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricSurfaceChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricSurfaceChargeDensity other, ElectricSurfaceChargeDensity 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 ElectricSurfaceChargeDensity otherQuantity)) @@ -536,8 +533,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ElectricSurfaceChargeDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ElectricSurfaceChargeDensity other, ElectricSurfaceChargeDensity 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(ElectricSurfaceChargeDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -621,15 +617,37 @@ public int CompareTo(ElectricSurfaceChargeDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ElectricSurfaceChargeDensity other, ElectricSurfaceChargeDensity 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(ElectricSurfaceChargeDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ElectricSurfaceChargeDensity otherTyped + && (tolerance is ElectricSurfaceChargeDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricSurfaceChargeDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricSurfaceChargeDensity other, ElectricSurfaceChargeDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index c762157cd9..90d82917f7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -1190,16 +1190,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Energy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Energy other, Energy 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 static bool operator ==(Energy left, Energy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Energy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Energy other, Energy 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 static bool operator !=(Energy left, Energy right) { return !(left == right); @@ -1207,8 +1205,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Energy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Energy other, Energy 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 Energy otherQuantity)) @@ -1219,8 +1216,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Energy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Energy other, Energy 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(Energy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1304,15 +1300,37 @@ public int CompareTo(Energy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Energy other, Energy 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(Energy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Energy otherTyped + && (tolerance is Energy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Energy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Energy other, Energy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs index 280a9d6a72..ddfd162708 100644 --- a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs @@ -675,16 +675,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(EnergyDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(EnergyDensity other, EnergyDensity 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 static bool operator ==(EnergyDensity left, EnergyDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(EnergyDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(EnergyDensity other, EnergyDensity 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 static bool operator !=(EnergyDensity left, EnergyDensity right) { return !(left == right); @@ -692,8 +690,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(EnergyDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(EnergyDensity other, EnergyDensity 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 EnergyDensity otherQuantity)) @@ -704,8 +701,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(EnergyDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(EnergyDensity other, EnergyDensity 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(EnergyDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -789,15 +785,37 @@ public int CompareTo(EnergyDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(EnergyDensity other, EnergyDensity 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(EnergyDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is EnergyDensity otherTyped + && (tolerance is EnergyDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'EnergyDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(EnergyDensity other, EnergyDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs index d66843e420..5244cc9452 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs @@ -580,16 +580,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Entro #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Entropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Entropy other, Entropy 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 static bool operator ==(Entropy left, Entropy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Entropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Entropy other, Entropy 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 static bool operator !=(Entropy left, Entropy right) { return !(left == right); @@ -597,8 +595,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Entro /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Entropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Entropy other, Entropy 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 Entropy otherQuantity)) @@ -609,8 +606,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Entropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Entropy other, Entropy 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(Entropy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -694,15 +690,37 @@ public int CompareTo(Entropy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Entropy other, Entropy 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(Entropy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Entropy otherTyped + && (tolerance is Entropy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Entropy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Entropy other, Entropy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs index 88c7b25449..ec80001397 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs @@ -745,16 +745,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Force, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Force other, Force 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 static bool operator ==(Force left, Force right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Force, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Force other, Force 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 static bool operator !=(Force left, Force right) { return !(left == right); @@ -762,8 +760,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Force, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Force other, Force 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 Force otherQuantity)) @@ -774,8 +771,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Force, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Force other, Force 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(Force other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -859,15 +855,37 @@ public int CompareTo(Force other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Force other, Force 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(Force other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Force otherTyped + && (tolerance is Force toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Force'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Force other, Force tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs index c0bc760270..1b3e5b7b74 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs @@ -732,16 +732,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ForceChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ForceChangeRate other, ForceChangeRate 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 static bool operator ==(ForceChangeRate left, ForceChangeRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ForceChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ForceChangeRate other, ForceChangeRate 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 static bool operator !=(ForceChangeRate left, ForceChangeRate right) { return !(left == right); @@ -749,8 +747,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ForceChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ForceChangeRate other, ForceChangeRate 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 ForceChangeRate otherQuantity)) @@ -761,8 +758,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ForceChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ForceChangeRate other, ForceChangeRate 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(ForceChangeRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -846,15 +842,37 @@ public int CompareTo(ForceChangeRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ForceChangeRate other, ForceChangeRate 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(ForceChangeRate other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ForceChangeRate otherTyped + && (tolerance is ForceChangeRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ForceChangeRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ForceChangeRate other, ForceChangeRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs index c147c0f280..37dcc95e9e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs @@ -1175,16 +1175,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ForcePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ForcePerLength other, ForcePerLength 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 static bool operator ==(ForcePerLength left, ForcePerLength right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ForcePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ForcePerLength other, ForcePerLength 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 static bool operator !=(ForcePerLength left, ForcePerLength right) { return !(left == right); @@ -1192,8 +1190,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ForcePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ForcePerLength other, ForcePerLength 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 ForcePerLength otherQuantity)) @@ -1204,8 +1201,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ForcePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ForcePerLength other, ForcePerLength 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(ForcePerLength other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1289,15 +1285,37 @@ public int CompareTo(ForcePerLength other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ForcePerLength other, ForcePerLength 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(ForcePerLength other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ForcePerLength otherTyped + && (tolerance is ForcePerLength toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ForcePerLength'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ForcePerLength other, ForcePerLength tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs index f0d6e735ed..f79728e42c 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs @@ -703,16 +703,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Frequ #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Frequency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Frequency other, Frequency 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 static bool operator ==(Frequency left, Frequency right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Frequency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Frequency other, Frequency 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 static bool operator !=(Frequency left, Frequency right) { return !(left == right); @@ -720,8 +718,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Frequ /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Frequency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Frequency other, Frequency 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 Frequency otherQuantity)) @@ -732,8 +729,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Frequency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Frequency other, Frequency 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(Frequency other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -817,15 +813,37 @@ public int CompareTo(Frequency other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Frequency other, Frequency 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(Frequency other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Frequency otherTyped + && (tolerance is Frequency toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Frequency'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Frequency other, Frequency tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs index 7b513711f6..130b3bd329 100644 --- a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs @@ -526,16 +526,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out FuelE #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(FuelEfficiency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(FuelEfficiency other, FuelEfficiency 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 static bool operator ==(FuelEfficiency left, FuelEfficiency right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(FuelEfficiency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(FuelEfficiency other, FuelEfficiency 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 static bool operator !=(FuelEfficiency left, FuelEfficiency right) { return !(left == right); @@ -543,8 +541,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out FuelE /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(FuelEfficiency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(FuelEfficiency other, FuelEfficiency 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 FuelEfficiency otherQuantity)) @@ -555,8 +552,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(FuelEfficiency, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(FuelEfficiency other, FuelEfficiency 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(FuelEfficiency other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -640,15 +636,37 @@ public int CompareTo(FuelEfficiency other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(FuelEfficiency other, FuelEfficiency 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(FuelEfficiency other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is FuelEfficiency otherTyped + && (tolerance is FuelEfficiency toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'FuelEfficiency'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(FuelEfficiency other, FuelEfficiency tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs index 2e1587b1d6..2398e95f5c 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs @@ -789,16 +789,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatF #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(HeatFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(HeatFlux other, HeatFlux 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 static bool operator ==(HeatFlux left, HeatFlux right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(HeatFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(HeatFlux other, HeatFlux 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 static bool operator !=(HeatFlux left, HeatFlux right) { return !(left == right); @@ -806,8 +804,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatF /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(HeatFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(HeatFlux other, HeatFlux 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 HeatFlux otherQuantity)) @@ -818,8 +815,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(HeatFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(HeatFlux other, HeatFlux 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(HeatFlux other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -903,15 +899,37 @@ public int CompareTo(HeatFlux other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(HeatFlux other, HeatFlux 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(HeatFlux other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is HeatFlux otherTyped + && (tolerance is HeatFlux toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'HeatFlux'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(HeatFlux other, HeatFlux tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index 36ebd8f183..1f9df7a7cf 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -563,16 +563,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatT #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(HeatTransferCoefficient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(HeatTransferCoefficient other, HeatTransferCoefficient 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 static bool operator ==(HeatTransferCoefficient left, HeatTransferCoefficient right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(HeatTransferCoefficient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(HeatTransferCoefficient other, HeatTransferCoefficient 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 static bool operator !=(HeatTransferCoefficient left, HeatTransferCoefficient right) { return !(left == right); @@ -580,8 +578,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatT /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(HeatTransferCoefficient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(HeatTransferCoefficient other, HeatTransferCoefficient 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 HeatTransferCoefficient otherQuantity)) @@ -592,8 +589,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(HeatTransferCoefficient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(HeatTransferCoefficient other, HeatTransferCoefficient 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(HeatTransferCoefficient other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -677,15 +673,37 @@ public int CompareTo(HeatTransferCoefficient other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(HeatTransferCoefficient other, HeatTransferCoefficient 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(HeatTransferCoefficient other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is HeatTransferCoefficient otherTyped + && (tolerance is HeatTransferCoefficient toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'HeatTransferCoefficient'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(HeatTransferCoefficient other, HeatTransferCoefficient tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs index 9a61690f4d..ed7c4316c2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs @@ -526,16 +526,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Illum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Illuminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Illuminance other, Illuminance 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 static bool operator ==(Illuminance left, Illuminance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Illuminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Illuminance other, Illuminance 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 static bool operator !=(Illuminance left, Illuminance right) { return !(left == right); @@ -543,8 +541,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Illum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Illuminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Illuminance other, Illuminance 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 Illuminance otherQuantity)) @@ -555,8 +552,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Illuminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Illuminance other, Illuminance 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(Illuminance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -640,15 +636,37 @@ public int CompareTo(Illuminance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Illuminance other, Illuminance 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(Illuminance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Illuminance otherTyped + && (tolerance is Illuminance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Illuminance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Illuminance other, Illuminance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs index 7f106772e6..3bf1a6d8e7 100644 --- a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs @@ -694,16 +694,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Impul #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Impulse, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Impulse other, Impulse 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 static bool operator ==(Impulse left, Impulse right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Impulse, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Impulse other, Impulse 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 static bool operator !=(Impulse left, Impulse right) { return !(left == right); @@ -711,8 +709,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Impul /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Impulse, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Impulse other, Impulse 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 Impulse otherQuantity)) @@ -723,8 +720,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Impulse, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Impulse other, Impulse 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(Impulse other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -808,15 +804,37 @@ public int CompareTo(Impulse other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Impulse other, Impulse 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(Impulse other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Impulse otherTyped + && (tolerance is Impulse toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Impulse'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Impulse other, Impulse tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Information.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.g.cs index 9bacae7e96..0640c7dbff 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.g.cs @@ -942,16 +942,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Infor #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Information, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Information other, Information 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 static bool operator ==(Information left, Information right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Information, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Information other, Information 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 static bool operator !=(Information left, Information right) { return !(left == right); @@ -959,8 +957,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Infor /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Information, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Information other, Information 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 Information otherQuantity)) @@ -971,8 +968,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Information, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Information other, Information 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(Information other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1056,15 +1052,37 @@ public int CompareTo(Information other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Information other, Information 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(Information other, decimal tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - decimal thisValue = this.Value; - decimal otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Information otherTyped + && (tolerance is Information toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Information'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Information other, Information tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs index d959da58da..96c0516301 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs @@ -713,16 +713,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Irrad #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Irradiance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Irradiance other, Irradiance 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 static bool operator ==(Irradiance left, Irradiance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Irradiance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Irradiance other, Irradiance 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 static bool operator !=(Irradiance left, Irradiance right) { return !(left == right); @@ -730,8 +728,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Irrad /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Irradiance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Irradiance other, Irradiance 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 Irradiance otherQuantity)) @@ -742,8 +739,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Irradiance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Irradiance other, Irradiance 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(Irradiance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -827,15 +823,37 @@ public int CompareTo(Irradiance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Irradiance other, Irradiance 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(Irradiance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Irradiance otherTyped + && (tolerance is Irradiance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Irradiance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Irradiance other, Irradiance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs index 49c9acc7ad..58f32c713e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs @@ -583,16 +583,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Irrad #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Irradiation, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Irradiation other, Irradiation 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 static bool operator ==(Irradiation left, Irradiation right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Irradiation, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Irradiation other, Irradiation 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 static bool operator !=(Irradiation left, Irradiation right) { return !(left == right); @@ -600,8 +598,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Irrad /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Irradiation, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Irradiation other, Irradiation 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 Irradiation otherQuantity)) @@ -612,8 +609,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Irradiation, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Irradiation other, Irradiation 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(Irradiation other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -697,15 +693,37 @@ public int CompareTo(Irradiation other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Irradiation other, Irradiation 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(Irradiation other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Irradiation otherTyped + && (tolerance is Irradiation toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Irradiation'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Irradiation other, Irradiation tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs index 8943c98193..c2227502c4 100644 --- a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs @@ -667,16 +667,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out JerkU #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Jerk, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Jerk other, Jerk 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 static bool operator ==(Jerk left, Jerk right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Jerk, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Jerk other, Jerk 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 static bool operator !=(Jerk left, Jerk right) { return !(left == right); @@ -684,8 +682,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out JerkU /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Jerk, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Jerk other, Jerk 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 Jerk otherQuantity)) @@ -696,8 +693,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Jerk, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Jerk other, Jerk 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(Jerk other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -781,15 +777,37 @@ public int CompareTo(Jerk other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Jerk other, Jerk 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(Jerk other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Jerk otherTyped + && (tolerance is Jerk toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Jerk'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Jerk other, Jerk tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index c6b6d2d859..e55cb266b9 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -629,16 +629,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Kinem #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(KinematicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(KinematicViscosity other, KinematicViscosity 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 static bool operator ==(KinematicViscosity left, KinematicViscosity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(KinematicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(KinematicViscosity other, KinematicViscosity 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 static bool operator !=(KinematicViscosity left, KinematicViscosity right) { return !(left == right); @@ -646,8 +644,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Kinem /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(KinematicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(KinematicViscosity other, KinematicViscosity 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 KinematicViscosity otherQuantity)) @@ -658,8 +655,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(KinematicViscosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(KinematicViscosity other, KinematicViscosity 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(KinematicViscosity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -743,15 +739,37 @@ public int CompareTo(KinematicViscosity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(KinematicViscosity other, KinematicViscosity 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(KinematicViscosity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is KinematicViscosity otherTyped + && (tolerance is KinematicViscosity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'KinematicViscosity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(KinematicViscosity other, KinematicViscosity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs index 2c3fb9b3c6..914bb5c26c 100644 --- a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs @@ -507,16 +507,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out LeakR #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(LeakRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LeakRate other, LeakRate 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 static bool operator ==(LeakRate left, LeakRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(LeakRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LeakRate other, LeakRate 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 static bool operator !=(LeakRate left, LeakRate right) { return !(left == right); @@ -524,8 +522,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out LeakR /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LeakRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LeakRate other, LeakRate 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 LeakRate otherQuantity)) @@ -536,8 +533,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LeakRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LeakRate other, LeakRate 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(LeakRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -621,15 +617,37 @@ public int CompareTo(LeakRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(LeakRate other, LeakRate 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(LeakRate other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is LeakRate otherTyped + && (tolerance is LeakRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'LeakRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(LeakRate other, LeakRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index bd0324ed5f..1fd58e04f2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -1184,16 +1184,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lengt #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Length, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, 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 static bool operator ==(Length left, Length right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Length, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, 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 static bool operator !=(Length left, Length right) { return !(left == right); @@ -1201,8 +1199,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lengt /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Length, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [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)) @@ -1213,8 +1210,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Length, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [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 }); @@ -1298,15 +1294,37 @@ public int CompareTo(Length other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [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, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Length otherTyped + && (tolerance is Length toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Length'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + 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); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Level.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.g.cs index f175e4459b..c763e65424 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.g.cs @@ -493,16 +493,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Level #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Level, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Level other, Level 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 static bool operator ==(Level left, Level right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Level, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Level other, Level 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 static bool operator !=(Level left, Level right) { return !(left == right); @@ -510,8 +508,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Level /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Level, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Level other, Level 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 Level otherQuantity)) @@ -522,8 +519,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Level, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Level other, Level 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(Level other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -607,15 +603,37 @@ public int CompareTo(Level other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Level other, Level 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(Level other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Level otherTyped + && (tolerance is Level toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Level'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Level other, Level tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs index b0e899934d..6fcb4fad2e 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs @@ -716,16 +716,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Linea #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(LinearDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LinearDensity other, LinearDensity 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 static bool operator ==(LinearDensity left, LinearDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(LinearDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LinearDensity other, LinearDensity 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 static bool operator !=(LinearDensity left, LinearDensity right) { return !(left == right); @@ -733,8 +731,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Linea /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LinearDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LinearDensity other, LinearDensity 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 LinearDensity otherQuantity)) @@ -745,8 +742,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LinearDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LinearDensity other, LinearDensity 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(LinearDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -830,15 +826,37 @@ public int CompareTo(LinearDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(LinearDensity other, LinearDensity 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(LinearDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is LinearDensity otherTyped + && (tolerance is LinearDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'LinearDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(LinearDensity other, LinearDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs index 671c648817..76510cb5e5 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -925,16 +925,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Linea #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(LinearPowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LinearPowerDensity other, LinearPowerDensity 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 static bool operator ==(LinearPowerDensity left, LinearPowerDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(LinearPowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LinearPowerDensity other, LinearPowerDensity 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 static bool operator !=(LinearPowerDensity left, LinearPowerDensity right) { return !(left == right); @@ -942,8 +940,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Linea /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LinearPowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LinearPowerDensity other, LinearPowerDensity 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 LinearPowerDensity otherQuantity)) @@ -954,8 +951,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LinearPowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LinearPowerDensity other, LinearPowerDensity 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(LinearPowerDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1039,15 +1035,37 @@ public int CompareTo(LinearPowerDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(LinearPowerDensity other, LinearPowerDensity 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(LinearPowerDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is LinearPowerDensity otherTyped + && (tolerance is LinearPowerDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'LinearPowerDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(LinearPowerDensity other, LinearPowerDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs index f1adbfe009..87836693de 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs @@ -640,16 +640,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Luminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Luminance other, Luminance 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 static bool operator ==(Luminance left, Luminance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Luminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Luminance other, Luminance 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 static bool operator !=(Luminance left, Luminance right) { return !(left == right); @@ -657,8 +655,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Luminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Luminance other, Luminance 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 Luminance otherQuantity)) @@ -669,8 +666,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Luminance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Luminance other, Luminance 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(Luminance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -754,15 +750,37 @@ public int CompareTo(Luminance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Luminance other, Luminance 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(Luminance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Luminance otherTyped + && (tolerance is Luminance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Luminance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Luminance other, Luminance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs index e8b2c721b0..eb943f5f1c 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs @@ -716,16 +716,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Luminosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Luminosity other, Luminosity 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 static bool operator ==(Luminosity left, Luminosity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Luminosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Luminosity other, Luminosity 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 static bool operator !=(Luminosity left, Luminosity right) { return !(left == right); @@ -733,8 +731,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Luminosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Luminosity other, Luminosity 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 Luminosity otherQuantity)) @@ -745,8 +742,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Luminosity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Luminosity other, Luminosity 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(Luminosity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -830,15 +826,37 @@ public int CompareTo(Luminosity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Luminosity other, Luminosity 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(Luminosity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Luminosity otherTyped + && (tolerance is Luminosity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Luminosity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Luminosity other, Luminosity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs index 6b27265185..bae3ab5606 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(LuminousFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LuminousFlux other, LuminousFlux 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 static bool operator ==(LuminousFlux left, LuminousFlux right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(LuminousFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LuminousFlux other, LuminousFlux 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 static bool operator !=(LuminousFlux left, LuminousFlux right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LuminousFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LuminousFlux other, LuminousFlux 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 LuminousFlux otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LuminousFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LuminousFlux other, LuminousFlux 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(LuminousFlux other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(LuminousFlux other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(LuminousFlux other, LuminousFlux 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(LuminousFlux other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is LuminousFlux otherTyped + && (tolerance is LuminousFlux toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'LuminousFlux'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(LuminousFlux other, LuminousFlux tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs index 4872fa2242..0663d94938 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(LuminousIntensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LuminousIntensity other, LuminousIntensity 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 static bool operator ==(LuminousIntensity left, LuminousIntensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(LuminousIntensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(LuminousIntensity other, LuminousIntensity 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 static bool operator !=(LuminousIntensity left, LuminousIntensity right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LuminousIntensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LuminousIntensity other, LuminousIntensity 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 LuminousIntensity otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(LuminousIntensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(LuminousIntensity other, LuminousIntensity 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(LuminousIntensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(LuminousIntensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(LuminousIntensity other, LuminousIntensity 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(LuminousIntensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is LuminousIntensity otherTyped + && (tolerance is LuminousIntensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'LuminousIntensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(LuminousIntensity other, LuminousIntensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs index d8821319dc..16bb353b2f 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs @@ -564,16 +564,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MagneticField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MagneticField other, MagneticField 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 static bool operator ==(MagneticField left, MagneticField right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MagneticField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MagneticField other, MagneticField 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 static bool operator !=(MagneticField left, MagneticField right) { return !(left == right); @@ -581,8 +579,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MagneticField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MagneticField other, MagneticField 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 MagneticField otherQuantity)) @@ -593,8 +590,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MagneticField, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MagneticField other, MagneticField 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(MagneticField other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -678,15 +674,37 @@ public int CompareTo(MagneticField other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MagneticField other, MagneticField 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(MagneticField other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MagneticField otherTyped + && (tolerance is MagneticField toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MagneticField'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MagneticField other, MagneticField tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs index b4a02e2457..f169a23961 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MagneticFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MagneticFlux other, MagneticFlux 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 static bool operator ==(MagneticFlux left, MagneticFlux right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MagneticFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MagneticFlux other, MagneticFlux 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 static bool operator !=(MagneticFlux left, MagneticFlux right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MagneticFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MagneticFlux other, MagneticFlux 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 MagneticFlux otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MagneticFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MagneticFlux other, MagneticFlux 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(MagneticFlux other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(MagneticFlux other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MagneticFlux other, MagneticFlux 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(MagneticFlux other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MagneticFlux otherTyped + && (tolerance is MagneticFlux toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MagneticFlux'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MagneticFlux other, MagneticFlux tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs index 519e288d50..53efd310f1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Magnetization, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Magnetization other, Magnetization 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 static bool operator ==(Magnetization left, Magnetization right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Magnetization, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Magnetization other, Magnetization 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 static bool operator !=(Magnetization left, Magnetization right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Magnetization, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Magnetization other, Magnetization 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 Magnetization otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Magnetization, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Magnetization other, Magnetization 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(Magnetization other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(Magnetization other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Magnetization other, Magnetization 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(Magnetization other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Magnetization otherTyped + && (tolerance is Magnetization toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Magnetization'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Magnetization other, Magnetization tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index 396e002d58..010b169b2d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -999,16 +999,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Mass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Mass other, Mass 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 static bool operator ==(Mass left, Mass right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Mass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Mass other, Mass 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 static bool operator !=(Mass left, Mass right) { return !(left == right); @@ -1016,8 +1014,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Mass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Mass other, Mass 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 Mass otherQuantity)) @@ -1028,8 +1025,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Mass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Mass other, Mass 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(Mass other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1113,15 +1109,37 @@ public int CompareTo(Mass other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Mass other, Mass 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(Mass other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Mass otherTyped + && (tolerance is Mass toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Mass'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Mass other, Mass tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs index 60036b0425..67a832bf71 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs @@ -1385,16 +1385,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassC #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassConcentration other, MassConcentration 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 static bool operator ==(MassConcentration left, MassConcentration right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassConcentration other, MassConcentration 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 static bool operator !=(MassConcentration left, MassConcentration right) { return !(left == right); @@ -1402,8 +1400,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassC /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassConcentration other, MassConcentration 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 MassConcentration otherQuantity)) @@ -1414,8 +1411,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassConcentration other, MassConcentration 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(MassConcentration other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1499,15 +1495,37 @@ public int CompareTo(MassConcentration other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MassConcentration other, MassConcentration 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(MassConcentration other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MassConcentration otherTyped + && (tolerance is MassConcentration toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MassConcentration'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MassConcentration other, MassConcentration tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index 408166d50a..ed74027626 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -1076,16 +1076,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassFlow other, MassFlow 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 static bool operator ==(MassFlow left, MassFlow right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassFlow other, MassFlow 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 static bool operator !=(MassFlow left, MassFlow right) { return !(left == right); @@ -1093,8 +1091,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassFlow other, MassFlow 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 MassFlow otherQuantity)) @@ -1105,8 +1102,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassFlow other, MassFlow 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(MassFlow other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1190,15 +1186,37 @@ public int CompareTo(MassFlow other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MassFlow other, MassFlow 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(MassFlow other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MassFlow otherTyped + && (tolerance is MassFlow toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MassFlow'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MassFlow other, MassFlow tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index 279e541850..35cbf6ad04 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -675,16 +675,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassFlux other, MassFlux 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 static bool operator ==(MassFlux left, MassFlux right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassFlux other, MassFlux 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 static bool operator !=(MassFlux left, MassFlux right) { return !(left == right); @@ -692,8 +690,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassFlux other, MassFlux 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 MassFlux otherQuantity)) @@ -704,8 +701,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassFlux, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassFlux other, MassFlux 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(MassFlux other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -789,15 +785,37 @@ public int CompareTo(MassFlux other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MassFlux other, MassFlux 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(MassFlux other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MassFlux otherTyped + && (tolerance is MassFlux toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MassFlux'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MassFlux other, MassFlux tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs index 8c824f4dc5..ea44af973b 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs @@ -906,16 +906,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassFraction, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassFraction other, MassFraction 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 static bool operator ==(MassFraction left, MassFraction right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassFraction, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassFraction other, MassFraction 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 static bool operator !=(MassFraction left, MassFraction right) { return !(left == right); @@ -923,8 +921,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassFraction, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassFraction other, MassFraction 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 MassFraction otherQuantity)) @@ -935,8 +932,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassFraction, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassFraction other, MassFraction 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(MassFraction other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1020,15 +1016,37 @@ public int CompareTo(MassFraction other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MassFraction other, MassFraction 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(MassFraction other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MassFraction otherTyped + && (tolerance is MassFraction toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MassFraction'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MassFraction other, MassFraction tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs index 4b67bdebff..49442ddc3e 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs @@ -979,16 +979,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassM #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassMomentOfInertia other, MassMomentOfInertia 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 static bool operator ==(MassMomentOfInertia left, MassMomentOfInertia right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MassMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MassMomentOfInertia other, MassMomentOfInertia 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 static bool operator !=(MassMomentOfInertia left, MassMomentOfInertia right) { return !(left == right); @@ -996,8 +994,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassM /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassMomentOfInertia other, MassMomentOfInertia 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 MassMomentOfInertia otherQuantity)) @@ -1008,8 +1005,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MassMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MassMomentOfInertia other, MassMomentOfInertia 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(MassMomentOfInertia other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1093,15 +1089,37 @@ public int CompareTo(MassMomentOfInertia other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MassMomentOfInertia other, MassMomentOfInertia 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(MassMomentOfInertia other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MassMomentOfInertia otherTyped + && (tolerance is MassMomentOfInertia toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MassMomentOfInertia'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MassMomentOfInertia other, MassMomentOfInertia tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs index 6f67309dbd..0ccc2dfb10 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarEnergy other, MolarEnergy 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 static bool operator ==(MolarEnergy left, MolarEnergy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarEnergy other, MolarEnergy 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 static bool operator !=(MolarEnergy left, MolarEnergy right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarEnergy other, MolarEnergy 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 MolarEnergy otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarEnergy other, MolarEnergy 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(MolarEnergy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(MolarEnergy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MolarEnergy other, MolarEnergy 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(MolarEnergy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MolarEnergy otherTyped + && (tolerance is MolarEnergy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MolarEnergy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MolarEnergy other, MolarEnergy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs index cd79b26ad1..71460a5bcd 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarEntropy other, MolarEntropy 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 static bool operator ==(MolarEntropy left, MolarEntropy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarEntropy other, MolarEntropy 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 static bool operator !=(MolarEntropy left, MolarEntropy right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarEntropy other, MolarEntropy 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 MolarEntropy otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarEntropy other, MolarEntropy 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(MolarEntropy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(MolarEntropy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MolarEntropy other, MolarEntropy 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(MolarEntropy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MolarEntropy otherTyped + && (tolerance is MolarEntropy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MolarEntropy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MolarEntropy other, MolarEntropy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs index 9759e8d22d..d0ef8f0754 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -618,16 +618,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarFlow other, MolarFlow 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 static bool operator ==(MolarFlow left, MolarFlow right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarFlow other, MolarFlow 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 static bool operator !=(MolarFlow left, MolarFlow right) { return !(left == right); @@ -635,8 +633,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarFlow other, MolarFlow 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 MolarFlow otherQuantity)) @@ -647,8 +644,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarFlow other, MolarFlow 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(MolarFlow other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -732,15 +728,37 @@ public int CompareTo(MolarFlow other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MolarFlow other, MolarFlow 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(MolarFlow other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MolarFlow otherTyped + && (tolerance is MolarFlow toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MolarFlow'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MolarFlow other, MolarFlow tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index 8de95c9961..caabb8d00c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -706,16 +706,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarMass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarMass other, MolarMass 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 static bool operator ==(MolarMass left, MolarMass right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(MolarMass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(MolarMass other, MolarMass 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 static bool operator !=(MolarMass left, MolarMass right) { return !(left == right); @@ -723,8 +721,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarMass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarMass other, MolarMass 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 MolarMass otherQuantity)) @@ -735,8 +732,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(MolarMass, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(MolarMass other, MolarMass 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(MolarMass other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -820,15 +816,37 @@ public int CompareTo(MolarMass other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(MolarMass other, MolarMass 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(MolarMass other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is MolarMass otherTyped + && (tolerance is MolarMass toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'MolarMass'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(MolarMass other, MolarMass tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index 6bbcc8ef82..8861e28cc0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -659,16 +659,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Molarity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Molarity other, Molarity 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 static bool operator ==(Molarity left, Molarity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Molarity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Molarity other, Molarity 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 static bool operator !=(Molarity left, Molarity right) { return !(left == right); @@ -676,8 +674,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Molarity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Molarity other, Molarity 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 Molarity otherQuantity)) @@ -688,8 +685,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Molarity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Molarity other, Molarity 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(Molarity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -773,15 +769,37 @@ public int CompareTo(Molarity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Molarity other, Molarity 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(Molarity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Molarity otherTyped + && (tolerance is Molarity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Molarity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Molarity other, Molarity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs index f799fbbd69..5c7cd6d9df 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Perme #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Permeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Permeability other, Permeability 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 static bool operator ==(Permeability left, Permeability right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Permeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Permeability other, Permeability 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 static bool operator !=(Permeability left, Permeability right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Perme /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Permeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Permeability other, Permeability 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 Permeability otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Permeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Permeability other, Permeability 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(Permeability other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(Permeability other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Permeability other, Permeability 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(Permeability other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Permeability otherTyped + && (tolerance is Permeability toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Permeability'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Permeability other, Permeability tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs index a3ed041fde..908f12e4c5 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Permi #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Permittivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Permittivity other, Permittivity 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 static bool operator ==(Permittivity left, Permittivity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Permittivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Permittivity other, Permittivity 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 static bool operator !=(Permittivity left, Permittivity right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Permi /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Permittivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Permittivity other, Permittivity 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 Permittivity otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Permittivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Permittivity other, Permittivity 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(Permittivity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(Permittivity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Permittivity other, Permittivity 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(Permittivity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Permittivity otherTyped + && (tolerance is Permittivity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Permittivity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Permittivity other, Permittivity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs index ca623e65f5..1dda135c8e 100644 --- a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs @@ -545,16 +545,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Porou #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(PorousMediumPermeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PorousMediumPermeability other, PorousMediumPermeability 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 static bool operator ==(PorousMediumPermeability left, PorousMediumPermeability right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(PorousMediumPermeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PorousMediumPermeability other, PorousMediumPermeability 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 static bool operator !=(PorousMediumPermeability left, PorousMediumPermeability right) { return !(left == right); @@ -562,8 +560,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Porou /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PorousMediumPermeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PorousMediumPermeability other, PorousMediumPermeability 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 PorousMediumPermeability otherQuantity)) @@ -574,8 +571,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PorousMediumPermeability, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PorousMediumPermeability other, PorousMediumPermeability 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(PorousMediumPermeability other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -659,15 +655,37 @@ public int CompareTo(PorousMediumPermeability other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(PorousMediumPermeability other, PorousMediumPermeability 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(PorousMediumPermeability other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is PorousMediumPermeability otherTyped + && (tolerance is PorousMediumPermeability toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'PorousMediumPermeability'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(PorousMediumPermeability other, PorousMediumPermeability tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index bfdbd51162..ee45a674fe 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -942,16 +942,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Power, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Power other, Power 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 static bool operator ==(Power left, Power right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Power, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Power other, Power 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 static bool operator !=(Power left, Power right) { return !(left == right); @@ -959,8 +957,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Power, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Power other, Power 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 Power otherQuantity)) @@ -971,8 +968,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Power, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Power other, Power 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(Power other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1056,15 +1052,37 @@ public int CompareTo(Power other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Power other, Power 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(Power other, decimal tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - decimal thisValue = this.Value; - decimal otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Power otherTyped + && (tolerance is Power toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Power'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Power other, Power tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs index 98524dd812..2b66d23aeb 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs @@ -1283,16 +1283,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(PowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PowerDensity other, PowerDensity 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 static bool operator ==(PowerDensity left, PowerDensity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(PowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PowerDensity other, PowerDensity 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 static bool operator !=(PowerDensity left, PowerDensity right) { return !(left == right); @@ -1300,8 +1298,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PowerDensity other, PowerDensity 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 PowerDensity otherQuantity)) @@ -1312,8 +1309,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PowerDensity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PowerDensity other, PowerDensity 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(PowerDensity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1397,15 +1393,37 @@ public int CompareTo(PowerDensity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(PowerDensity other, PowerDensity 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(PowerDensity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is PowerDensity otherTyped + && (tolerance is PowerDensity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'PowerDensity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(PowerDensity other, PowerDensity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs index cbbd8c2b8f..97e51c30d0 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs @@ -493,16 +493,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(PowerRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PowerRatio other, PowerRatio 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 static bool operator ==(PowerRatio left, PowerRatio right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(PowerRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PowerRatio other, PowerRatio 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 static bool operator !=(PowerRatio left, PowerRatio right) { return !(left == right); @@ -510,8 +508,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PowerRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PowerRatio other, PowerRatio 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 PowerRatio otherQuantity)) @@ -522,8 +519,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PowerRatio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PowerRatio other, PowerRatio 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(PowerRatio other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -607,15 +603,37 @@ public int CompareTo(PowerRatio other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(PowerRatio other, PowerRatio 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(PowerRatio other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is PowerRatio otherTyped + && (tolerance is PowerRatio toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'PowerRatio'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(PowerRatio other, PowerRatio tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index f9abbb6f9b..251a1e968e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -1409,16 +1409,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Pressure, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Pressure other, Pressure 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 static bool operator ==(Pressure left, Pressure right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Pressure, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Pressure other, Pressure 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 static bool operator !=(Pressure left, Pressure right) { return !(left == right); @@ -1426,8 +1424,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Pressure, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Pressure other, Pressure 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 Pressure otherQuantity)) @@ -1438,8 +1435,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Pressure, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Pressure other, Pressure 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(Pressure other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1523,15 +1519,37 @@ public int CompareTo(Pressure other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Pressure other, Pressure 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(Pressure other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Pressure otherTyped + && (tolerance is Pressure toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Pressure'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Pressure other, Pressure tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs index e1976e3ace..253ca8ae73 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs @@ -727,16 +727,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(PressureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PressureChangeRate other, PressureChangeRate 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 static bool operator ==(PressureChangeRate left, PressureChangeRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(PressureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(PressureChangeRate other, PressureChangeRate 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 static bool operator !=(PressureChangeRate left, PressureChangeRate right) { return !(left == right); @@ -744,8 +742,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PressureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PressureChangeRate other, PressureChangeRate 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 PressureChangeRate otherQuantity)) @@ -756,8 +753,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(PressureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(PressureChangeRate other, PressureChangeRate 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(PressureChangeRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -841,15 +837,37 @@ public int CompareTo(PressureChangeRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(PressureChangeRate other, PressureChangeRate 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(PressureChangeRate other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is PressureChangeRate otherTyped + && (tolerance is PressureChangeRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'PressureChangeRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(PressureChangeRate other, PressureChangeRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs index bb44dc2933..72bddc57fe 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs @@ -561,16 +561,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Ratio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Ratio other, Ratio 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 static bool operator ==(Ratio left, Ratio right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Ratio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Ratio other, Ratio 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 static bool operator !=(Ratio left, Ratio right) { return !(left == right); @@ -578,8 +576,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Ratio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Ratio other, Ratio 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 Ratio otherQuantity)) @@ -590,8 +587,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Ratio, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Ratio other, Ratio 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(Ratio other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -675,15 +671,37 @@ public int CompareTo(Ratio other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Ratio other, Ratio 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(Ratio other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Ratio otherTyped + && (tolerance is Ratio toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Ratio'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Ratio other, Ratio tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs index 6267989315..6218bbc2a1 100644 --- a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs @@ -485,16 +485,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(RatioChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RatioChangeRate other, RatioChangeRate 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 static bool operator ==(RatioChangeRate left, RatioChangeRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(RatioChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RatioChangeRate other, RatioChangeRate 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 static bool operator !=(RatioChangeRate left, RatioChangeRate right) { return !(left == right); @@ -502,8 +500,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RatioChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RatioChangeRate other, RatioChangeRate 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 RatioChangeRate otherQuantity)) @@ -514,8 +511,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RatioChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RatioChangeRate other, RatioChangeRate 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(RatioChangeRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -599,15 +595,37 @@ public int CompareTo(RatioChangeRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(RatioChangeRate other, RatioChangeRate 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(RatioChangeRate other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RatioChangeRate otherTyped + && (tolerance is RatioChangeRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RatioChangeRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RatioChangeRate other, RatioChangeRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs index 7f6dfffdc7..59930fef92 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out React #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReactiveEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReactiveEnergy other, ReactiveEnergy 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 static bool operator ==(ReactiveEnergy left, ReactiveEnergy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReactiveEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReactiveEnergy other, ReactiveEnergy 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 static bool operator !=(ReactiveEnergy left, ReactiveEnergy right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out React /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReactiveEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReactiveEnergy other, ReactiveEnergy 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 ReactiveEnergy otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReactiveEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReactiveEnergy other, ReactiveEnergy 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(ReactiveEnergy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(ReactiveEnergy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ReactiveEnergy other, ReactiveEnergy 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(ReactiveEnergy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ReactiveEnergy otherTyped + && (tolerance is ReactiveEnergy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ReactiveEnergy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ReactiveEnergy other, ReactiveEnergy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs index 5a1776d5e2..0f530580e8 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs @@ -523,16 +523,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out React #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReactivePower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReactivePower other, ReactivePower 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 static bool operator ==(ReactivePower left, ReactivePower right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReactivePower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReactivePower other, ReactivePower 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 static bool operator !=(ReactivePower left, ReactivePower right) { return !(left == right); @@ -540,8 +538,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out React /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReactivePower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReactivePower other, ReactivePower 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 ReactivePower otherQuantity)) @@ -552,8 +549,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReactivePower, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReactivePower other, ReactivePower 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(ReactivePower other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -637,15 +633,37 @@ public int CompareTo(ReactivePower other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ReactivePower other, ReactivePower 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(ReactivePower other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ReactivePower otherTyped + && (tolerance is ReactivePower toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ReactivePower'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ReactivePower other, ReactivePower tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs index c5ffc1a5c4..e4c4204eec 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs @@ -659,16 +659,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReciprocalArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReciprocalArea other, ReciprocalArea 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 static bool operator ==(ReciprocalArea left, ReciprocalArea right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReciprocalArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReciprocalArea other, ReciprocalArea 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 static bool operator !=(ReciprocalArea left, ReciprocalArea right) { return !(left == right); @@ -676,8 +674,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReciprocalArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReciprocalArea other, ReciprocalArea 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 ReciprocalArea otherQuantity)) @@ -688,8 +685,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReciprocalArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReciprocalArea other, ReciprocalArea 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(ReciprocalArea other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -773,15 +769,37 @@ public int CompareTo(ReciprocalArea other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ReciprocalArea other, ReciprocalArea 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(ReciprocalArea other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ReciprocalArea otherTyped + && (tolerance is ReciprocalArea toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ReciprocalArea'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ReciprocalArea other, ReciprocalArea tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index 80cc1cb9d4..252b52e59e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -640,16 +640,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReciprocalLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReciprocalLength other, ReciprocalLength 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 static bool operator ==(ReciprocalLength left, ReciprocalLength right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ReciprocalLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ReciprocalLength other, ReciprocalLength 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 static bool operator !=(ReciprocalLength left, ReciprocalLength right) { return !(left == right); @@ -657,8 +655,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReciprocalLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReciprocalLength other, ReciprocalLength 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 ReciprocalLength otherQuantity)) @@ -669,8 +666,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ReciprocalLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ReciprocalLength other, ReciprocalLength 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(ReciprocalLength other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -754,15 +750,37 @@ public int CompareTo(ReciprocalLength other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ReciprocalLength other, ReciprocalLength 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(ReciprocalLength other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ReciprocalLength otherTyped + && (tolerance is ReciprocalLength toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ReciprocalLength'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ReciprocalLength other, ReciprocalLength tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs index cd5e296d3c..e4ae0327a5 100644 --- a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs @@ -466,16 +466,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Relat #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(RelativeHumidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RelativeHumidity other, RelativeHumidity 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 static bool operator ==(RelativeHumidity left, RelativeHumidity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(RelativeHumidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RelativeHumidity other, RelativeHumidity 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 static bool operator !=(RelativeHumidity left, RelativeHumidity right) { return !(left == right); @@ -483,8 +481,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Relat /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RelativeHumidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RelativeHumidity other, RelativeHumidity 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 RelativeHumidity otherQuantity)) @@ -495,8 +492,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RelativeHumidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RelativeHumidity other, RelativeHumidity 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(RelativeHumidity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -580,15 +576,37 @@ public int CompareTo(RelativeHumidity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(RelativeHumidity other, RelativeHumidity 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(RelativeHumidity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RelativeHumidity otherTyped + && (tolerance is RelativeHumidity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RelativeHumidity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RelativeHumidity other, RelativeHumidity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs index f11b7e848f..4104792881 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs @@ -523,16 +523,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalAcceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalAcceleration other, RotationalAcceleration 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 static bool operator ==(RotationalAcceleration left, RotationalAcceleration right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalAcceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalAcceleration other, RotationalAcceleration 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 static bool operator !=(RotationalAcceleration left, RotationalAcceleration right) { return !(left == right); @@ -540,8 +538,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalAcceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalAcceleration other, RotationalAcceleration 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 RotationalAcceleration otherQuantity)) @@ -552,8 +549,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalAcceleration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalAcceleration other, RotationalAcceleration 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(RotationalAcceleration other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -637,15 +633,37 @@ public int CompareTo(RotationalAcceleration other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(RotationalAcceleration other, RotationalAcceleration 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(RotationalAcceleration other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RotationalAcceleration otherTyped + && (tolerance is RotationalAcceleration toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RotationalAcceleration'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RotationalAcceleration other, RotationalAcceleration tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index 9d1abc24bb..5ac639715b 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -706,16 +706,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalSpeed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalSpeed other, RotationalSpeed 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 static bool operator ==(RotationalSpeed left, RotationalSpeed right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalSpeed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalSpeed other, RotationalSpeed 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 static bool operator !=(RotationalSpeed left, RotationalSpeed right) { return !(left == right); @@ -723,8 +721,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalSpeed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalSpeed other, RotationalSpeed 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 RotationalSpeed otherQuantity)) @@ -735,8 +732,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalSpeed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalSpeed other, RotationalSpeed 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(RotationalSpeed other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -820,15 +816,37 @@ public int CompareTo(RotationalSpeed other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(RotationalSpeed other, RotationalSpeed 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(RotationalSpeed other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RotationalSpeed otherTyped + && (tolerance is RotationalSpeed toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RotationalSpeed'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RotationalSpeed other, RotationalSpeed tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs index 3b5c25472e..7946dbf28c 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs @@ -1074,16 +1074,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalStiffness, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalStiffness other, RotationalStiffness 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 static bool operator ==(RotationalStiffness left, RotationalStiffness right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalStiffness, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalStiffness other, RotationalStiffness 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 static bool operator !=(RotationalStiffness left, RotationalStiffness right) { return !(left == right); @@ -1091,8 +1089,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalStiffness, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalStiffness other, RotationalStiffness 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 RotationalStiffness otherQuantity)) @@ -1103,8 +1100,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalStiffness, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalStiffness other, RotationalStiffness 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(RotationalStiffness other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1188,15 +1184,37 @@ public int CompareTo(RotationalStiffness other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(RotationalStiffness other, RotationalStiffness 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(RotationalStiffness other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RotationalStiffness otherTyped + && (tolerance is RotationalStiffness toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RotationalStiffness'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RotationalStiffness other, RotationalStiffness tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs index 45eab6c224..b1735ce0b8 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs @@ -542,16 +542,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalStiffnessPerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalStiffnessPerLength other, RotationalStiffnessPerLength 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 static bool operator ==(RotationalStiffnessPerLength left, RotationalStiffnessPerLength right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(RotationalStiffnessPerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RotationalStiffnessPerLength other, RotationalStiffnessPerLength 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 static bool operator !=(RotationalStiffnessPerLength left, RotationalStiffnessPerLength right) { return !(left == right); @@ -559,8 +557,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalStiffnessPerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalStiffnessPerLength other, RotationalStiffnessPerLength 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 RotationalStiffnessPerLength otherQuantity)) @@ -571,8 +568,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(RotationalStiffnessPerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(RotationalStiffnessPerLength other, RotationalStiffnessPerLength 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(RotationalStiffnessPerLength other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -656,15 +652,37 @@ public int CompareTo(RotationalStiffnessPerLength other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(RotationalStiffnessPerLength other, RotationalStiffnessPerLength 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(RotationalStiffnessPerLength other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RotationalStiffnessPerLength otherTyped + && (tolerance is RotationalStiffnessPerLength toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RotationalStiffnessPerLength'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RotationalStiffnessPerLength other, RotationalStiffnessPerLength tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs index 869da4bfc8..375740fe5c 100644 --- a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs @@ -466,16 +466,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Scala #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Scalar, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Scalar other, Scalar 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 static bool operator ==(Scalar left, Scalar right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Scalar, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Scalar other, Scalar 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 static bool operator !=(Scalar left, Scalar right) { return !(left == right); @@ -483,8 +481,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Scala /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Scalar, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Scalar other, Scalar 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 Scalar otherQuantity)) @@ -495,8 +492,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Scalar, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Scalar other, Scalar 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(Scalar other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -580,15 +576,37 @@ public int CompareTo(Scalar other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Scalar other, Scalar 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(Scalar other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Scalar otherTyped + && (tolerance is Scalar toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Scalar'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Scalar other, Scalar tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs index a47828309c..05e620b8c6 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Solid #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(SolidAngle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SolidAngle other, SolidAngle 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 static bool operator ==(SolidAngle left, SolidAngle right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(SolidAngle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SolidAngle other, SolidAngle 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 static bool operator !=(SolidAngle left, SolidAngle right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Solid /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SolidAngle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SolidAngle other, SolidAngle 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 SolidAngle otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SolidAngle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SolidAngle other, SolidAngle 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(SolidAngle other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(SolidAngle other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(SolidAngle other, SolidAngle 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(SolidAngle other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is SolidAngle otherTyped + && (tolerance is SolidAngle toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'SolidAngle'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(SolidAngle other, SolidAngle tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs index 5bc5bb4b01..46fe41bc7f 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs @@ -1020,16 +1020,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificEnergy other, SpecificEnergy 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 static bool operator ==(SpecificEnergy left, SpecificEnergy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificEnergy other, SpecificEnergy 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 static bool operator !=(SpecificEnergy left, SpecificEnergy right) { return !(left == right); @@ -1037,8 +1035,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificEnergy other, SpecificEnergy 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 SpecificEnergy otherQuantity)) @@ -1049,8 +1046,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificEnergy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificEnergy other, SpecificEnergy 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(SpecificEnergy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1134,15 +1130,37 @@ public int CompareTo(SpecificEnergy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(SpecificEnergy other, SpecificEnergy 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(SpecificEnergy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is SpecificEnergy otherTyped + && (tolerance is SpecificEnergy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'SpecificEnergy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(SpecificEnergy other, SpecificEnergy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs index 2b5330fc24..e83e66dae4 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs @@ -618,16 +618,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificEntropy other, SpecificEntropy 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 static bool operator ==(SpecificEntropy left, SpecificEntropy right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificEntropy other, SpecificEntropy 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 static bool operator !=(SpecificEntropy left, SpecificEntropy right) { return !(left == right); @@ -635,8 +633,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificEntropy other, SpecificEntropy 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 SpecificEntropy otherQuantity)) @@ -647,8 +644,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificEntropy, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificEntropy other, SpecificEntropy 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(SpecificEntropy other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -732,15 +728,37 @@ public int CompareTo(SpecificEntropy other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(SpecificEntropy other, SpecificEntropy 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(SpecificEntropy other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is SpecificEntropy otherTyped + && (tolerance is SpecificEntropy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'SpecificEntropy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(SpecificEntropy other, SpecificEntropy tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs index 5ad44da6c1..18e8e24d04 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs @@ -526,16 +526,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificFuelConsumption other, SpecificFuelConsumption 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 static bool operator ==(SpecificFuelConsumption left, SpecificFuelConsumption right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificFuelConsumption other, SpecificFuelConsumption 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 static bool operator !=(SpecificFuelConsumption left, SpecificFuelConsumption right) { return !(left == right); @@ -543,8 +541,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificFuelConsumption other, SpecificFuelConsumption 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 SpecificFuelConsumption otherQuantity)) @@ -555,8 +552,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificFuelConsumption, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificFuelConsumption other, SpecificFuelConsumption 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(SpecificFuelConsumption other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -640,15 +636,37 @@ public int CompareTo(SpecificFuelConsumption other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(SpecificFuelConsumption other, SpecificFuelConsumption 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(SpecificFuelConsumption other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is SpecificFuelConsumption otherTyped + && (tolerance is SpecificFuelConsumption toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'SpecificFuelConsumption'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(SpecificFuelConsumption other, SpecificFuelConsumption tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs index 8bf013ba2d..b59b7621c1 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs @@ -504,16 +504,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificVolume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificVolume other, SpecificVolume 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 static bool operator ==(SpecificVolume left, SpecificVolume right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificVolume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificVolume other, SpecificVolume 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 static bool operator !=(SpecificVolume left, SpecificVolume right) { return !(left == right); @@ -521,8 +519,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificVolume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificVolume other, SpecificVolume 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 SpecificVolume otherQuantity)) @@ -533,8 +530,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificVolume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificVolume other, SpecificVolume 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(SpecificVolume other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -618,15 +614,37 @@ public int CompareTo(SpecificVolume other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(SpecificVolume other, SpecificVolume 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(SpecificVolume other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is SpecificVolume otherTyped + && (tolerance is SpecificVolume toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'SpecificVolume'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(SpecificVolume other, SpecificVolume tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs index 07c10183ef..4f378ea920 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs @@ -773,16 +773,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificWeight, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificWeight other, SpecificWeight 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 static bool operator ==(SpecificWeight left, SpecificWeight right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(SpecificWeight, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(SpecificWeight other, SpecificWeight 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 static bool operator !=(SpecificWeight left, SpecificWeight right) { return !(left == right); @@ -790,8 +788,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificWeight, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificWeight other, SpecificWeight 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 SpecificWeight otherQuantity)) @@ -802,8 +799,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(SpecificWeight, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(SpecificWeight other, SpecificWeight 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(SpecificWeight other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -887,15 +883,37 @@ public int CompareTo(SpecificWeight other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(SpecificWeight other, SpecificWeight 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(SpecificWeight other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is SpecificWeight otherTyped + && (tolerance is SpecificWeight toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'SpecificWeight'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(SpecificWeight other, SpecificWeight tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs index 1fccc6e4b3..9fe30f34df 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs @@ -1098,16 +1098,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speed #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Speed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Speed other, Speed 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 static bool operator ==(Speed left, Speed right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Speed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Speed other, Speed 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 static bool operator !=(Speed left, Speed right) { return !(left == right); @@ -1115,8 +1113,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speed /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Speed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Speed other, Speed 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 Speed otherQuantity)) @@ -1127,8 +1124,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Speed, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Speed other, Speed 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(Speed other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1212,15 +1208,37 @@ public int CompareTo(Speed other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Speed other, Speed 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(Speed other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Speed otherTyped + && (tolerance is Speed toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Speed'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Speed other, Speed tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs index f89661aea9..5635b16c1e 100644 --- a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs @@ -618,16 +618,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Stand #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(StandardVolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(StandardVolumeFlow other, StandardVolumeFlow 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 static bool operator ==(StandardVolumeFlow left, StandardVolumeFlow right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(StandardVolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(StandardVolumeFlow other, StandardVolumeFlow 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 static bool operator !=(StandardVolumeFlow left, StandardVolumeFlow right) { return !(left == right); @@ -635,8 +633,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Stand /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(StandardVolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(StandardVolumeFlow other, StandardVolumeFlow 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 StandardVolumeFlow otherQuantity)) @@ -647,8 +644,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(StandardVolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(StandardVolumeFlow other, StandardVolumeFlow 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(StandardVolumeFlow other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -732,15 +728,37 @@ public int CompareTo(StandardVolumeFlow other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(StandardVolumeFlow other, StandardVolumeFlow 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(StandardVolumeFlow other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is StandardVolumeFlow otherTyped + && (tolerance is StandardVolumeFlow toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'StandardVolumeFlow'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(StandardVolumeFlow other, StandardVolumeFlow tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs index eca5bdb8b4..a5e0c7cc10 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs @@ -588,16 +588,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Temperature, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Temperature other, Temperature 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 static bool operator ==(Temperature left, Temperature right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Temperature, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Temperature other, Temperature 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 static bool operator !=(Temperature left, Temperature right) { return !(left == right); @@ -605,8 +603,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Temperature, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Temperature other, Temperature 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 Temperature otherQuantity)) @@ -617,8 +614,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Temperature, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Temperature other, Temperature 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(Temperature other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -702,15 +698,37 @@ public int CompareTo(Temperature other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Temperature other, Temperature 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(Temperature other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Temperature otherTyped + && (tolerance is Temperature toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Temperature'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Temperature other, Temperature tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs index 0e449a91cc..fc77391e9f 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs @@ -637,16 +637,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(TemperatureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TemperatureChangeRate other, TemperatureChangeRate 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 static bool operator ==(TemperatureChangeRate left, TemperatureChangeRate right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(TemperatureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TemperatureChangeRate other, TemperatureChangeRate 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 static bool operator !=(TemperatureChangeRate left, TemperatureChangeRate right) { return !(left == right); @@ -654,8 +652,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TemperatureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TemperatureChangeRate other, TemperatureChangeRate 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 TemperatureChangeRate otherQuantity)) @@ -666,8 +663,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TemperatureChangeRate, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TemperatureChangeRate other, TemperatureChangeRate 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(TemperatureChangeRate other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -751,15 +747,37 @@ public int CompareTo(TemperatureChangeRate other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(TemperatureChangeRate other, TemperatureChangeRate 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(TemperatureChangeRate other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is TemperatureChangeRate otherTyped + && (tolerance is TemperatureChangeRate toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'TemperatureChangeRate'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(TemperatureChangeRate other, TemperatureChangeRate tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs index 3e2be136aa..c360176612 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs @@ -618,16 +618,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(TemperatureDelta, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TemperatureDelta other, TemperatureDelta 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 static bool operator ==(TemperatureDelta left, TemperatureDelta right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(TemperatureDelta, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TemperatureDelta other, TemperatureDelta 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 static bool operator !=(TemperatureDelta left, TemperatureDelta right) { return !(left == right); @@ -635,8 +633,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TemperatureDelta, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TemperatureDelta other, TemperatureDelta 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 TemperatureDelta otherQuantity)) @@ -647,8 +644,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TemperatureDelta, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TemperatureDelta other, TemperatureDelta 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(TemperatureDelta other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -732,15 +728,37 @@ public int CompareTo(TemperatureDelta other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(TemperatureDelta other, TemperatureDelta 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(TemperatureDelta other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is TemperatureDelta otherTyped + && (tolerance is TemperatureDelta toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'TemperatureDelta'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(TemperatureDelta other, TemperatureDelta tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs index 972b7a4cf8..b5dcf10547 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs @@ -523,16 +523,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(TemperatureGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TemperatureGradient other, TemperatureGradient 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 static bool operator ==(TemperatureGradient left, TemperatureGradient right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(TemperatureGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TemperatureGradient other, TemperatureGradient 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 static bool operator !=(TemperatureGradient left, TemperatureGradient right) { return !(left == right); @@ -540,8 +538,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TemperatureGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TemperatureGradient other, TemperatureGradient 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 TemperatureGradient otherQuantity)) @@ -552,8 +549,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TemperatureGradient, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TemperatureGradient other, TemperatureGradient 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(TemperatureGradient other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -637,15 +633,37 @@ public int CompareTo(TemperatureGradient other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(TemperatureGradient other, TemperatureGradient 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(TemperatureGradient other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is TemperatureGradient otherTyped + && (tolerance is TemperatureGradient toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'TemperatureGradient'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(TemperatureGradient other, TemperatureGradient tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs index 38984e4055..3d579a5d62 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs @@ -488,16 +488,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Therm #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ThermalConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ThermalConductivity other, ThermalConductivity 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 static bool operator ==(ThermalConductivity left, ThermalConductivity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ThermalConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ThermalConductivity other, ThermalConductivity 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 static bool operator !=(ThermalConductivity left, ThermalConductivity right) { return !(left == right); @@ -505,8 +503,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Therm /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ThermalConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ThermalConductivity other, ThermalConductivity 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 ThermalConductivity otherQuantity)) @@ -517,8 +514,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ThermalConductivity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ThermalConductivity other, ThermalConductivity 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(ThermalConductivity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -602,15 +598,37 @@ public int CompareTo(ThermalConductivity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ThermalConductivity other, ThermalConductivity 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(ThermalConductivity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ThermalConductivity otherTyped + && (tolerance is ThermalConductivity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ThermalConductivity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ThermalConductivity other, ThermalConductivity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs index 8f1d252108..78e8ff9110 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs @@ -561,16 +561,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Therm #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(ThermalResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ThermalResistance other, ThermalResistance 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 static bool operator ==(ThermalResistance left, ThermalResistance right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(ThermalResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ThermalResistance other, ThermalResistance 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 static bool operator !=(ThermalResistance left, ThermalResistance right) { return !(left == right); @@ -578,8 +576,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Therm /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ThermalResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ThermalResistance other, ThermalResistance 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 ThermalResistance otherQuantity)) @@ -590,8 +587,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(ThermalResistance, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(ThermalResistance other, ThermalResistance 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(ThermalResistance other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -675,15 +671,37 @@ public int CompareTo(ThermalResistance other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(ThermalResistance other, ThermalResistance 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(ThermalResistance other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is ThermalResistance otherTyped + && (tolerance is ThermalResistance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ThermalResistance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ThermalResistance other, ThermalResistance tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs index ab2fd891e1..850017d7dc 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs @@ -925,16 +925,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Torque, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Torque other, Torque 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 static bool operator ==(Torque left, Torque right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Torque, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Torque other, Torque 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 static bool operator !=(Torque left, Torque right) { return !(left == right); @@ -942,8 +940,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Torque, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Torque other, Torque 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 Torque otherQuantity)) @@ -954,8 +951,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Torque, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Torque other, Torque 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(Torque other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1039,15 +1035,37 @@ public int CompareTo(Torque other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Torque other, Torque 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(Torque other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Torque otherTyped + && (tolerance is Torque toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Torque'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Torque other, Torque tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs index 1c230398b6..c7ceaf0637 100644 --- a/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs @@ -849,16 +849,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(TorquePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TorquePerLength other, TorquePerLength 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 static bool operator ==(TorquePerLength left, TorquePerLength right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(TorquePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(TorquePerLength other, TorquePerLength 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 static bool operator !=(TorquePerLength left, TorquePerLength right) { return !(left == right); @@ -866,8 +864,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TorquePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TorquePerLength other, TorquePerLength 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 TorquePerLength otherQuantity)) @@ -878,8 +875,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(TorquePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(TorquePerLength other, TorquePerLength 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(TorquePerLength other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -963,15 +959,37 @@ public int CompareTo(TorquePerLength other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(TorquePerLength other, TorquePerLength 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(TorquePerLength other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is TorquePerLength otherTyped + && (tolerance is TorquePerLength toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'TorquePerLength'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(TorquePerLength other, TorquePerLength tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs index f4e8f29989..0c0551f1e1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs @@ -469,16 +469,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Turbi #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Turbidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Turbidity other, Turbidity 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 static bool operator ==(Turbidity left, Turbidity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Turbidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Turbidity other, Turbidity 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 static bool operator !=(Turbidity left, Turbidity right) { return !(left == right); @@ -486,8 +484,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Turbi /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Turbidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Turbidity other, Turbidity 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 Turbidity otherQuantity)) @@ -498,8 +495,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Turbidity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Turbidity other, Turbidity 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(Turbidity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -583,15 +579,37 @@ public int CompareTo(Turbidity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Turbidity other, Turbidity 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(Turbidity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Turbidity otherTyped + && (tolerance is Turbidity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Turbidity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Turbidity other, Turbidity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs index bdd6fade1e..baf20d4890 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs @@ -466,16 +466,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Vitam #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(VitaminA, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VitaminA other, VitaminA 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 static bool operator ==(VitaminA left, VitaminA right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(VitaminA, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VitaminA other, VitaminA 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 static bool operator !=(VitaminA left, VitaminA right) { return !(left == right); @@ -483,8 +481,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Vitam /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VitaminA, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VitaminA other, VitaminA 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 VitaminA otherQuantity)) @@ -495,8 +492,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VitaminA, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VitaminA other, VitaminA 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(VitaminA other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -580,15 +576,37 @@ public int CompareTo(VitaminA other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(VitaminA other, VitaminA 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(VitaminA other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is VitaminA otherTyped + && (tolerance is VitaminA toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'VitaminA'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(VitaminA other, VitaminA tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index 80e98d96b9..c64f46f91a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -1502,16 +1502,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(Volume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Volume other, Volume 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 static bool operator ==(Volume left, Volume right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(Volume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(Volume other, Volume 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 static bool operator !=(Volume left, Volume right) { return !(left == right); @@ -1519,8 +1517,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Volume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Volume other, Volume 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 Volume otherQuantity)) @@ -1531,8 +1528,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(Volume, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(Volume other, Volume 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(Volume other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1616,15 +1612,37 @@ public int CompareTo(Volume other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(Volume other, Volume 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(Volume other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is Volume otherTyped + && (tolerance is Volume toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Volume'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(Volume other, Volume tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs index ecf7511ad6..991cde53af 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs @@ -830,16 +830,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumeConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumeConcentration other, VolumeConcentration 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 static bool operator ==(VolumeConcentration left, VolumeConcentration right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumeConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumeConcentration other, VolumeConcentration 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 static bool operator !=(VolumeConcentration left, VolumeConcentration right) { return !(left == right); @@ -847,8 +845,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumeConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumeConcentration other, VolumeConcentration 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 VolumeConcentration otherQuantity)) @@ -859,8 +856,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumeConcentration, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumeConcentration other, VolumeConcentration 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(VolumeConcentration other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -944,15 +940,37 @@ public int CompareTo(VolumeConcentration other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(VolumeConcentration other, VolumeConcentration 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(VolumeConcentration other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is VolumeConcentration otherTyped + && (tolerance is VolumeConcentration toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'VolumeConcentration'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(VolumeConcentration other, VolumeConcentration tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index b5804aaf97..1575560297 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -1750,16 +1750,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumeFlow other, VolumeFlow 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 static bool operator ==(VolumeFlow left, VolumeFlow right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumeFlow other, VolumeFlow 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 static bool operator !=(VolumeFlow left, VolumeFlow right) { return !(left == right); @@ -1767,8 +1765,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumeFlow other, VolumeFlow 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 VolumeFlow otherQuantity)) @@ -1779,8 +1776,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumeFlow, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumeFlow other, VolumeFlow 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(VolumeFlow other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -1864,15 +1860,37 @@ public int CompareTo(VolumeFlow other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(VolumeFlow other, VolumeFlow 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(VolumeFlow other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is VolumeFlow otherTyped + && (tolerance is VolumeFlow toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'VolumeFlow'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(VolumeFlow other, VolumeFlow tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs index 8aeb0f5041..363bc1e180 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs @@ -485,16 +485,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumeFlowPerArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumeFlowPerArea other, VolumeFlowPerArea 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 static bool operator ==(VolumeFlowPerArea left, VolumeFlowPerArea right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumeFlowPerArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumeFlowPerArea other, VolumeFlowPerArea 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 static bool operator !=(VolumeFlowPerArea left, VolumeFlowPerArea right) { return !(left == right); @@ -502,8 +500,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumeFlowPerArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumeFlowPerArea other, VolumeFlowPerArea 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 VolumeFlowPerArea otherQuantity)) @@ -514,8 +511,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumeFlowPerArea, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumeFlowPerArea other, VolumeFlowPerArea 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(VolumeFlowPerArea other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -599,15 +595,37 @@ public int CompareTo(VolumeFlowPerArea other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(VolumeFlowPerArea other, VolumeFlowPerArea 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(VolumeFlowPerArea other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is VolumeFlowPerArea otherTyped + && (tolerance is VolumeFlowPerArea toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'VolumeFlowPerArea'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(VolumeFlowPerArea other, VolumeFlowPerArea tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs index 508b97ebc6..c3c5d1005f 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs @@ -618,16 +618,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumePerLength other, VolumePerLength 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 static bool operator ==(VolumePerLength left, VolumePerLength right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumePerLength other, VolumePerLength 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 static bool operator !=(VolumePerLength left, VolumePerLength right) { return !(left == right); @@ -635,8 +633,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumePerLength other, VolumePerLength 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 VolumePerLength otherQuantity)) @@ -647,8 +644,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumePerLength, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumePerLength other, VolumePerLength 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(VolumePerLength other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -732,15 +728,37 @@ public int CompareTo(VolumePerLength other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(VolumePerLength other, VolumePerLength 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(VolumePerLength other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is VolumePerLength otherTyped + && (tolerance is VolumePerLength toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'VolumePerLength'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(VolumePerLength other, VolumePerLength tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs index f00234e5a9..e5e7fa821b 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs @@ -621,16 +621,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumetricHeatCapacity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumetricHeatCapacity other, VolumetricHeatCapacity 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 static bool operator ==(VolumetricHeatCapacity left, VolumetricHeatCapacity right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(VolumetricHeatCapacity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(VolumetricHeatCapacity other, VolumetricHeatCapacity 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 static bool operator !=(VolumetricHeatCapacity left, VolumetricHeatCapacity right) { return !(left == right); @@ -638,8 +636,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumetricHeatCapacity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumetricHeatCapacity other, VolumetricHeatCapacity 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 VolumetricHeatCapacity otherQuantity)) @@ -650,8 +647,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(VolumetricHeatCapacity, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(VolumetricHeatCapacity other, VolumetricHeatCapacity 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(VolumetricHeatCapacity other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -735,15 +731,37 @@ public int CompareTo(VolumetricHeatCapacity other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(VolumetricHeatCapacity other, VolumetricHeatCapacity 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(VolumetricHeatCapacity other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is VolumetricHeatCapacity otherTyped + && (tolerance is VolumetricHeatCapacity toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'VolumetricHeatCapacity'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(VolumetricHeatCapacity other, VolumetricHeatCapacity tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs index 1eadff1253..28149b6b1e 100644 --- a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs @@ -561,16 +561,14 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Warpi #pragma warning disable CS0809 /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For quantity comparisons, use Equals(WarpingMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(WarpingMomentOfInertia other, WarpingMomentOfInertia 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 static bool operator ==(WarpingMomentOfInertia left, WarpingMomentOfInertia right) { return left.Equals(right); } /// Indicates strict inequality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("For null checks, use `x is not null` syntax to not invoke overloads. For quantity comparisons, use Equals(WarpingMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(WarpingMomentOfInertia other, WarpingMomentOfInertia 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 static bool operator !=(WarpingMomentOfInertia left, WarpingMomentOfInertia right) { return !(left == right); @@ -578,8 +576,7 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Warpi /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(WarpingMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(WarpingMomentOfInertia other, WarpingMomentOfInertia 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 WarpingMomentOfInertia otherQuantity)) @@ -590,8 +587,7 @@ public override bool Equals(object? obj) /// /// Indicates strict equality of two quantities, where both and are exactly equal. - /// Consider using to check equality across different units and to specify a floating-point number error tolerance. - [Obsolete("Consider using Equals(WarpingMomentOfInertia, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + [Obsolete("Use Equals(WarpingMomentOfInertia other, WarpingMomentOfInertia 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(WarpingMomentOfInertia other) { return new { Value, Unit }.Equals(new { other.Value, other.Unit }); @@ -675,15 +671,37 @@ public int CompareTo(WarpingMomentOfInertia other) /// The absolute or relative tolerance value. Must be greater than or equal to 0. /// The comparison type: either relative or absolute. /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + [Obsolete("Use Equals(WarpingMomentOfInertia other, WarpingMomentOfInertia 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(WarpingMomentOfInertia other, double tolerance, ComparisonType comparisonType) { if (tolerance < 0) - throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - double thisValue = this.Value; - double otherValueInThisUnits = other.As(this.Unit); + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } - return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is WarpingMomentOfInertia otherTyped + && (tolerance is WarpingMomentOfInertia toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'WarpingMomentOfInertia'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(WarpingMomentOfInertia other, WarpingMomentOfInertia tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); } /// diff --git a/UnitsNet/IQuantity.cs b/UnitsNet/IQuantity.cs index cb4ebdb6a4..a67d33d382 100644 --- a/UnitsNet/IQuantity.cs +++ b/UnitsNet/IQuantity.cs @@ -41,6 +41,29 @@ public interface IQuantity : IFormattable /// The converted value. double As(UnitSystem unitSystem); + /// + /// + /// Compare equality to given a for the maximum allowed +/- difference. + /// + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromMeters(2.1); + /// var tolerance = Length.FromCentimeters(10); + /// a.Equals(b, tolerance); // true, 2m equals 2.1m +/- 0.1m + /// + /// + /// + /// It is generally advised against specifying "zero" tolerance, due to the nature of floating-point operations. + /// + /// + /// The other quantity to compare to. Not equal if the quantity types are different. + /// The absolute tolerance value. Must be greater than or equal to zero. Must be same quantity type as . + /// True if the absolute difference between the two values is not greater than the specified tolerance. + /// Tolerance must be of the same quantity type. + bool Equals(IQuantity? other, IQuantity tolerance); + /// /// The unit this quantity was constructed with -or- BaseUnit if default ctor was used. /// @@ -146,10 +169,14 @@ public interface IQuantity : IQuantity, IV /// The type itself, for the CRT pattern. /// The underlying unit enum type. /// The underlying value type for internal representation. - public interface IQuantity : IQuantity #if NET7_0_OR_GREATER + public interface IQuantity + : IQuantity , IComparisonOperators , IParsable +#else + public interface IQuantity + : IQuantity #endif where TSelf : IQuantity where TUnitType : Enum @@ -159,5 +186,26 @@ public interface IQuantity : IQuantity + /// + /// Compare equality to given a for the maximum allowed +/- difference. + /// + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromMeters(2.1); + /// var tolerance = Length.FromCentimeters(10); + /// a.Equals(b, tolerance); // true, 2m equals 2.1m +/- 0.1m + /// + /// + /// + /// It is generally advised against specifying "zero" tolerance, due to the nature of floating-point operations. + /// + /// + /// The other quantity to compare to. + /// The absolute tolerance value. Must be greater than or equal to zero. + /// True if the absolute difference between the two values is not greater than the specified tolerance. + bool Equals(TSelf? other, TSelf tolerance); } }