diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs index 99f4f3f7ee..3b49f16a35 100644 --- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs @@ -77,7 +77,7 @@ namespace UnitsNet Writer.W("IDecimalQuantity, "); } - Writer.WL($"IComparable, IComparable<{_quantity.Name}>, IConvertible, IFormattable"); + Writer.WL($"IEquatable<{_quantity.Name}>, IComparable, IComparable<{_quantity.Name}>, IConvertible, IFormattable"); Writer.WL($@" {{ /// @@ -752,16 +752,80 @@ private void GenerateEqualityAndComparison() return left.Value > right.ToUnit(left.Unit).Value; }} + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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(""Consider using Equals(Angle, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + 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(""Consider using Equals(Angle, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + public static bool operator !=({_quantity.Name} left, {_quantity.Name} right) + {{ + return !(left == right); + }} + + /// + /// Indicates strict equality of two quantities, 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, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + public override bool Equals(object obj) + {{ + if (obj is null || !(obj is {_quantity.Name} otherQuantity)) + return false; + + return Equals(otherQuantity); + }} + /// + /// Indicates strict equality of two quantities, 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, {_valueType}, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance."")] + public bool Equals({_quantity.Name} other) + {{ + return new {{ Value, Unit }}.Equals(new {{ other.Value, other.Unit }}); + }} + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) {{ if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is {_quantity.Name} obj{_quantity.Name})) throw new ArgumentException(""Expected type {_quantity.Name}."", nameof(obj)); + if (!(obj is {_quantity.Name} otherQuantity)) throw new ArgumentException(""Expected type {_quantity.Name}."", nameof(obj)); - return CompareTo(obj{_quantity.Name}); + return CompareTo(otherQuantity); }} - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo({_quantity.Name} other) {{ return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -800,7 +864,7 @@ public int CompareTo({_quantity.Name} other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using {_valueType} internally. /// /// /// The other quantity to compare to. @@ -987,7 +1051,7 @@ private bool TryToUnit({_quantity.Name}Unit unit, out {_quantity.Name}? converte _ => null! }}; - return converted != null; + return converted is not null; }} /// diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 2ca56d24fa..c8ab5cafbc 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -45,16 +45,32 @@ internal class UnitTestBaseClassGenerator : GeneratorBase /// private readonly string _numberSuffix; + /// + /// Other unit, if more than one unit exists for quantity, otherwise same as . + /// + private readonly Unit _otherOrBaseUnit; + + /// + /// Example: "LengthUnit.Centimeter". + /// + private readonly string _otherOrBaseUnitFullName; + public UnitTestBaseClassGenerator(Quantity quantity) { _quantity = quantity; _baseUnit = quantity.Units.FirstOrDefault(u => u.SingularName == _quantity.BaseUnit) ?? throw new ArgumentException($"No unit found with SingularName equal to BaseUnit [{_quantity.BaseUnit}]. This unit must be defined.", nameof(quantity)); + _unitEnumName = $"{quantity.Name}Unit"; + _baseUnitEnglishAbbreviation = GetEnglishAbbreviation(_baseUnit); _baseUnitFullName = $"{_unitEnumName}.{_baseUnit.SingularName}"; _numberSuffix = quantity.ValueType == "decimal" ? "m" : ""; + + // Try to pick another unit, or fall back to base unit if only a single unit. + _otherOrBaseUnit = quantity.Units.Where(u => u != _baseUnit).DefaultIfEmpty(_baseUnit).First(); + _otherOrBaseUnitFullName = $"{_unitEnumName}.{_otherOrBaseUnit.SingularName}"; } private string GetUnitFullName(Unit unit) => $"{_unitEnumName}.{unit.SingularName}"; @@ -483,6 +499,52 @@ public void CompareToThrowsOnNull() Assert.Throws(() => {baseUnitVariableName}.CompareTo(null)); }} + [Theory] + [InlineData(1, {_baseUnitFullName}, 1, {_baseUnitFullName}, true)] // Same value and unit. + [InlineData(1, {_baseUnitFullName}, 2, {_baseUnitFullName}, false)] // Different value. + [InlineData(2, {_baseUnitFullName}, 1, {_otherOrBaseUnitFullName}, false)] // Different value and unit."); + if (_baseUnit != _otherOrBaseUnit) + { + Writer.WL($@" + [InlineData(1, {_baseUnitFullName}, 1, {_otherOrBaseUnitFullName}, false)] // Different unit."); + } + Writer.WL($@" + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual({_quantity.ValueType} valueA, {_unitEnumName} unitA, {_quantity.ValueType} valueB, {_unitEnumName} unitB, bool expectEqual) + {{ + var a = new {_quantity.Name}(valueA, unitA); + var b = new {_quantity.Name}(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + }} + + [Fact] + public void Equals_Null_ReturnsFalse() + {{ + var a = {_quantity.Name}.Zero; + + Assert.False(a.Equals((object)null)); + + // ""The result of the expression is always 'false'..."" + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + }} + [Fact] public void Equals_RelativeTolerance_IsImplemented() {{ diff --git a/UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj b/UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj index b07181b8a3..0c51a316ef 100644 --- a/UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj +++ b/UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj @@ -6,6 +6,7 @@ latest enable true + CS0618 diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj index ba0972cf84..0988d87921 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj @@ -5,6 +5,7 @@ UnitsNet.Serialization.JsonNet.Tests latest true + CS0618 diff --git a/UnitsNet.Tests/CustomCode/AreaDensityTests.cs b/UnitsNet.Tests/CustomCode/AreaDensityTests.cs index 8c48f4257f..e5b1b7102d 100644 --- a/UnitsNet.Tests/CustomCode/AreaDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/AreaDensityTests.cs @@ -40,7 +40,7 @@ public class AreaDensityTests : AreaDensityTestsBase public void AreaDensityTimesAreaEqualsMass() { Mass massOfOneA4Paper = AreaDensity.FromGramsPerSquareMeter(120) * Area.FromSquareCentimeters(625); - Assert.Equal(Mass.FromGrams(7.5), massOfOneA4Paper); + Assert.Equal(7.5, massOfOneA4Paper.Grams); } } } diff --git a/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs b/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs index 8df12e34e7..320609c8eb 100644 --- a/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs +++ b/UnitsNet.Tests/CustomCode/TemperatureDeltaTests.cs @@ -55,7 +55,7 @@ public void TemperatureDeltaTimesSpecificEntropyEqualsSpecificEnergy() public void EntropyTimesTemperatureDeltaEqualsEnergy() { Energy energy = Entropy.FromKilojoulesPerKelvin(3) * TemperatureDelta.FromKelvins(7); - Assert.Equal(Energy.FromKilojoules(21), energy); + Assert.Equal(21, energy.Kilojoules); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index 369927031a..af5e035678 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -1104,6 +1104,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => meterpersecondsquared.CompareTo(null)); } + [Theory] + [InlineData(1, AccelerationUnit.MeterPerSecondSquared, 1, AccelerationUnit.MeterPerSecondSquared, true)] // Same value and unit. + [InlineData(1, AccelerationUnit.MeterPerSecondSquared, 2, AccelerationUnit.MeterPerSecondSquared, false)] // Different value. + [InlineData(2, AccelerationUnit.MeterPerSecondSquared, 1, AccelerationUnit.CentimeterPerSecondSquared, false)] // Different value and unit. + [InlineData(1, AccelerationUnit.MeterPerSecondSquared, 1, AccelerationUnit.CentimeterPerSecondSquared, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AccelerationUnit unitA, double valueB, AccelerationUnit unitB, bool expectEqual) + { + var a = new Acceleration(valueA, unitA); + var b = new Acceleration(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Acceleration.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index c68625cc20..3b8c2cd02b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -781,6 +781,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => mole.CompareTo(null)); } + [Theory] + [InlineData(1, AmountOfSubstanceUnit.Mole, 1, AmountOfSubstanceUnit.Mole, true)] // Same value and unit. + [InlineData(1, AmountOfSubstanceUnit.Mole, 2, AmountOfSubstanceUnit.Mole, false)] // Different value. + [InlineData(2, AmountOfSubstanceUnit.Mole, 1, AmountOfSubstanceUnit.Centimole, false)] // Different value and unit. + [InlineData(1, AmountOfSubstanceUnit.Mole, 1, AmountOfSubstanceUnit.Centimole, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AmountOfSubstanceUnit unitA, double valueB, AmountOfSubstanceUnit unitB, bool expectEqual) + { + var a = new AmountOfSubstance(valueA, unitA); + var b = new AmountOfSubstance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = AmountOfSubstance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index d7efdd5c91..48ae60db3e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -422,6 +422,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decibelvolt.CompareTo(null)); } + [Theory] + [InlineData(1, AmplitudeRatioUnit.DecibelVolt, 1, AmplitudeRatioUnit.DecibelVolt, true)] // Same value and unit. + [InlineData(1, AmplitudeRatioUnit.DecibelVolt, 2, AmplitudeRatioUnit.DecibelVolt, false)] // Different value. + [InlineData(2, AmplitudeRatioUnit.DecibelVolt, 1, AmplitudeRatioUnit.DecibelMicrovolt, false)] // Different value and unit. + [InlineData(1, AmplitudeRatioUnit.DecibelVolt, 1, AmplitudeRatioUnit.DecibelMicrovolt, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AmplitudeRatioUnit unitA, double valueB, AmplitudeRatioUnit unitB, bool expectEqual) + { + var a = new AmplitudeRatio(valueA, unitA); + var b = new AmplitudeRatio(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = AmplitudeRatio.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index adba70f32d..73056b7401 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -1366,6 +1366,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => degree.CompareTo(null)); } + [Theory] + [InlineData(1, AngleUnit.Degree, 1, AngleUnit.Degree, true)] // Same value and unit. + [InlineData(1, AngleUnit.Degree, 2, AngleUnit.Degree, false)] // Different value. + [InlineData(2, AngleUnit.Degree, 1, AngleUnit.Arcminute, false)] // Different value and unit. + [InlineData(1, AngleUnit.Degree, 1, AngleUnit.Arcminute, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AngleUnit unitA, double valueB, AngleUnit unitB, bool expectEqual) + { + var a = new Angle(valueA, unitA); + var b = new Angle(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Angle.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs index 12ad235f41..0d8a0498a1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltamperehour.CompareTo(null)); } + [Theory] + [InlineData(1, ApparentEnergyUnit.VoltampereHour, 1, ApparentEnergyUnit.VoltampereHour, true)] // Same value and unit. + [InlineData(1, ApparentEnergyUnit.VoltampereHour, 2, ApparentEnergyUnit.VoltampereHour, false)] // Different value. + [InlineData(2, ApparentEnergyUnit.VoltampereHour, 1, ApparentEnergyUnit.KilovoltampereHour, false)] // Different value and unit. + [InlineData(1, ApparentEnergyUnit.VoltampereHour, 1, ApparentEnergyUnit.KilovoltampereHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ApparentEnergyUnit unitA, double valueB, ApparentEnergyUnit unitB, bool expectEqual) + { + var a = new ApparentEnergy(valueA, unitA); + var b = new ApparentEnergy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ApparentEnergy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs index 15d07b25a1..687266feed 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltampere.CompareTo(null)); } + [Theory] + [InlineData(1, ApparentPowerUnit.Voltampere, 1, ApparentPowerUnit.Voltampere, true)] // Same value and unit. + [InlineData(1, ApparentPowerUnit.Voltampere, 2, ApparentPowerUnit.Voltampere, false)] // Different value. + [InlineData(2, ApparentPowerUnit.Voltampere, 1, ApparentPowerUnit.Gigavoltampere, false)] // Different value and unit. + [InlineData(1, ApparentPowerUnit.Voltampere, 1, ApparentPowerUnit.Gigavoltampere, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ApparentPowerUnit unitA, double valueB, ApparentPowerUnit unitB, bool expectEqual) + { + var a = new ApparentPower(valueA, unitA); + var b = new ApparentPower(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ApparentPower.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index d44d1d1a00..145dff5b94 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -407,6 +407,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogrampersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, AreaDensityUnit.KilogramPerSquareMeter, 1, AreaDensityUnit.KilogramPerSquareMeter, true)] // Same value and unit. + [InlineData(1, AreaDensityUnit.KilogramPerSquareMeter, 2, AreaDensityUnit.KilogramPerSquareMeter, false)] // Different value. + [InlineData(2, AreaDensityUnit.KilogramPerSquareMeter, 1, AreaDensityUnit.GramPerSquareMeter, false)] // Different value and unit. + [InlineData(1, AreaDensityUnit.KilogramPerSquareMeter, 1, AreaDensityUnit.GramPerSquareMeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AreaDensityUnit unitA, double valueB, AreaDensityUnit unitB, bool expectEqual) + { + var a = new AreaDensity(valueA, unitA); + var b = new AreaDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = AreaDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 3cb17affa9..26ed1bf3a0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -632,6 +632,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => metertothefourth.CompareTo(null)); } + [Theory] + [InlineData(1, AreaMomentOfInertiaUnit.MeterToTheFourth, 1, AreaMomentOfInertiaUnit.MeterToTheFourth, true)] // Same value and unit. + [InlineData(1, AreaMomentOfInertiaUnit.MeterToTheFourth, 2, AreaMomentOfInertiaUnit.MeterToTheFourth, false)] // Different value. + [InlineData(2, AreaMomentOfInertiaUnit.MeterToTheFourth, 1, AreaMomentOfInertiaUnit.CentimeterToTheFourth, false)] // Different value and unit. + [InlineData(1, AreaMomentOfInertiaUnit.MeterToTheFourth, 1, AreaMomentOfInertiaUnit.CentimeterToTheFourth, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AreaMomentOfInertiaUnit unitA, double valueB, AreaMomentOfInertiaUnit unitB, bool expectEqual) + { + var a = new AreaMomentOfInertia(valueA, unitA); + var b = new AreaMomentOfInertia(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = AreaMomentOfInertia.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index 1f83a6a2ea..1fb5bd2a72 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -1394,6 +1394,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => squaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, AreaUnit.SquareMeter, 1, AreaUnit.SquareMeter, true)] // Same value and unit. + [InlineData(1, AreaUnit.SquareMeter, 2, AreaUnit.SquareMeter, false)] // Different value. + [InlineData(2, AreaUnit.SquareMeter, 1, AreaUnit.Acre, false)] // Different value and unit. + [InlineData(1, AreaUnit.SquareMeter, 1, AreaUnit.Acre, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, AreaUnit unitA, double valueB, AreaUnit unitB, bool expectEqual) + { + var a = new Area(valueA, unitA); + var b = new Area(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Area.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index 364b04f191..f7b89e7f31 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -1475,6 +1475,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => bitpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, BitRateUnit.BitPerSecond, 1, BitRateUnit.BitPerSecond, true)] // Same value and unit. + [InlineData(1, BitRateUnit.BitPerSecond, 2, BitRateUnit.BitPerSecond, false)] // Different value. + [InlineData(2, BitRateUnit.BitPerSecond, 1, BitRateUnit.BytePerSecond, false)] // Different value and unit. + [InlineData(1, BitRateUnit.BitPerSecond, 1, BitRateUnit.BytePerSecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(decimal valueA, BitRateUnit unitA, decimal valueB, BitRateUnit unitB, bool expectEqual) + { + var a = new BitRate(valueA, unitA); + var b = new BitRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = BitRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index 94112d45bb..1a8bab7b6a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogramperjoule.CompareTo(null)); } + [Theory] + [InlineData(1, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 1, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, true)] // Same value and unit. + [InlineData(1, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 2, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, false)] // Different value. + [InlineData(2, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 1, BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, false)] // Different value and unit. + [InlineData(1, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, 1, BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, BrakeSpecificFuelConsumptionUnit unitA, double valueB, BrakeSpecificFuelConsumptionUnit unitB, bool expectEqual) + { + var a = new BrakeSpecificFuelConsumption(valueA, unitA); + var b = new BrakeSpecificFuelConsumption(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = BrakeSpecificFuelConsumption.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs index 129aa0184e..32592d57ef 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs @@ -501,6 +501,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => farad.CompareTo(null)); } + [Theory] + [InlineData(1, CapacitanceUnit.Farad, 1, CapacitanceUnit.Farad, true)] // Same value and unit. + [InlineData(1, CapacitanceUnit.Farad, 2, CapacitanceUnit.Farad, false)] // Different value. + [InlineData(2, CapacitanceUnit.Farad, 1, CapacitanceUnit.Kilofarad, false)] // Different value and unit. + [InlineData(1, CapacitanceUnit.Farad, 1, CapacitanceUnit.Kilofarad, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, CapacitanceUnit unitA, double valueB, CapacitanceUnit unitB, bool expectEqual) + { + var a = new Capacitance(valueA, unitA); + var b = new Capacitance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Capacitance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index 15ca3023b6..2259b86de4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -455,6 +455,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => inversekelvin.CompareTo(null)); } + [Theory] + [InlineData(1, CoefficientOfThermalExpansionUnit.InverseKelvin, 1, CoefficientOfThermalExpansionUnit.InverseKelvin, true)] // Same value and unit. + [InlineData(1, CoefficientOfThermalExpansionUnit.InverseKelvin, 2, CoefficientOfThermalExpansionUnit.InverseKelvin, false)] // Different value. + [InlineData(2, CoefficientOfThermalExpansionUnit.InverseKelvin, 1, CoefficientOfThermalExpansionUnit.InverseDegreeCelsius, false)] // Different value and unit. + [InlineData(1, CoefficientOfThermalExpansionUnit.InverseKelvin, 1, CoefficientOfThermalExpansionUnit.InverseDegreeCelsius, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, CoefficientOfThermalExpansionUnit unitA, double valueB, CoefficientOfThermalExpansionUnit unitB, bool expectEqual) + { + var a = new CoefficientOfThermalExpansion(valueA, unitA); + var b = new CoefficientOfThermalExpansion(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = CoefficientOfThermalExpansion.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs index d410a29b88..89bf3c1135 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -691,6 +691,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => inversepascal.CompareTo(null)); } + [Theory] + [InlineData(1, CompressibilityUnit.InversePascal, 1, CompressibilityUnit.InversePascal, true)] // Same value and unit. + [InlineData(1, CompressibilityUnit.InversePascal, 2, CompressibilityUnit.InversePascal, false)] // Different value. + [InlineData(2, CompressibilityUnit.InversePascal, 1, CompressibilityUnit.InverseAtmosphere, false)] // Different value and unit. + [InlineData(1, CompressibilityUnit.InversePascal, 1, CompressibilityUnit.InverseAtmosphere, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, CompressibilityUnit unitA, double valueB, CompressibilityUnit unitB, bool expectEqual) + { + var a = new Compressibility(valueA, unitA); + var b = new Compressibility(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Compressibility.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index c97c759603..f3d840ee4d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -2159,6 +2159,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogrampercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, DensityUnit.KilogramPerCubicMeter, 1, DensityUnit.KilogramPerCubicMeter, true)] // Same value and unit. + [InlineData(1, DensityUnit.KilogramPerCubicMeter, 2, DensityUnit.KilogramPerCubicMeter, false)] // Different value. + [InlineData(2, DensityUnit.KilogramPerCubicMeter, 1, DensityUnit.CentigramPerDeciliter, false)] // Different value and unit. + [InlineData(1, DensityUnit.KilogramPerCubicMeter, 1, DensityUnit.CentigramPerDeciliter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, DensityUnit unitA, double valueB, DensityUnit unitB, bool expectEqual) + { + var a = new Density(valueA, unitA); + var b = new Density(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Density.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index 1a8a16a3dd..e1913b5c0d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -1839,6 +1839,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => second.CompareTo(null)); } + [Theory] + [InlineData(1, DurationUnit.Second, 1, DurationUnit.Second, true)] // Same value and unit. + [InlineData(1, DurationUnit.Second, 2, DurationUnit.Second, false)] // Different value. + [InlineData(2, DurationUnit.Second, 1, DurationUnit.Day, false)] // Different value and unit. + [InlineData(1, DurationUnit.Second, 1, DurationUnit.Day, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, DurationUnit unitA, double valueB, DurationUnit unitB, bool expectEqual) + { + var a = new Duration(valueA, unitA); + var b = new Duration(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Duration.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index 8673c98654..ec086a4a3d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -700,6 +700,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonsecondpermetersquared.CompareTo(null)); } + [Theory] + [InlineData(1, DynamicViscosityUnit.NewtonSecondPerMeterSquared, 1, DynamicViscosityUnit.NewtonSecondPerMeterSquared, true)] // Same value and unit. + [InlineData(1, DynamicViscosityUnit.NewtonSecondPerMeterSquared, 2, DynamicViscosityUnit.NewtonSecondPerMeterSquared, false)] // Different value. + [InlineData(2, DynamicViscosityUnit.NewtonSecondPerMeterSquared, 1, DynamicViscosityUnit.Centipoise, false)] // Different value and unit. + [InlineData(1, DynamicViscosityUnit.NewtonSecondPerMeterSquared, 1, DynamicViscosityUnit.Centipoise, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, DynamicViscosityUnit unitA, double valueB, DynamicViscosityUnit unitB, bool expectEqual) + { + var a = new DynamicViscosity(valueA, unitA); + var b = new DynamicViscosity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = DynamicViscosity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index 29d27b5208..afe99a1d8d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => siemens.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Siemens, true)] // Same value and unit. + [InlineData(1, ElectricAdmittanceUnit.Siemens, 2, ElectricAdmittanceUnit.Siemens, false)] // Different value. + [InlineData(2, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Microsiemens, false)] // Different value and unit. + [InlineData(1, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Microsiemens, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricAdmittanceUnit unitA, double valueB, ElectricAdmittanceUnit unitB, bool expectEqual) + { + var a = new ElectricAdmittance(valueA, unitA); + var b = new ElectricAdmittance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricAdmittance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index 9232f233d9..60472b3911 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => coulombpercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricChargeDensityUnit.CoulombPerCubicMeter, 1, ElectricChargeDensityUnit.CoulombPerCubicMeter, true)] // Same value and unit. + [InlineData(1, ElectricChargeDensityUnit.CoulombPerCubicMeter, 2, ElectricChargeDensityUnit.CoulombPerCubicMeter, false)] // Different value. + [InlineData(2, ElectricChargeDensityUnit.CoulombPerCubicMeter, 1, ElectricChargeDensityUnit.CoulombPerCubicMeter, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricChargeDensityUnit unitA, double valueB, ElectricChargeDensityUnit unitB, bool expectEqual) + { + var a = new ElectricChargeDensity(valueA, unitA); + var b = new ElectricChargeDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricChargeDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index db68600ad6..e598cffe2f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -505,6 +505,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => coulomb.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricChargeUnit.Coulomb, 1, ElectricChargeUnit.Coulomb, true)] // Same value and unit. + [InlineData(1, ElectricChargeUnit.Coulomb, 2, ElectricChargeUnit.Coulomb, false)] // Different value. + [InlineData(2, ElectricChargeUnit.Coulomb, 1, ElectricChargeUnit.AmpereHour, false)] // Different value and unit. + [InlineData(1, ElectricChargeUnit.Coulomb, 1, ElectricChargeUnit.AmpereHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricChargeUnit unitA, double valueB, ElectricChargeUnit unitB, bool expectEqual) + { + var a = new ElectricCharge(valueA, unitA); + var b = new ElectricCharge(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricCharge.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index 8c61121680..e29d269faa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => siemens.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Siemens, true)] // Same value and unit. + [InlineData(1, ElectricConductanceUnit.Siemens, 2, ElectricConductanceUnit.Siemens, false)] // Different value. + [InlineData(2, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Microsiemens, false)] // Different value and unit. + [InlineData(1, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Microsiemens, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricConductanceUnit unitA, double valueB, ElectricConductanceUnit unitB, bool expectEqual) + { + var a = new ElectricConductance(valueA, unitA); + var b = new ElectricConductance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricConductance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index 4da9225091..29d3a96f38 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -488,6 +488,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => siemenspermeter.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricConductivityUnit.SiemensPerMeter, 1, ElectricConductivityUnit.SiemensPerMeter, true)] // Same value and unit. + [InlineData(1, ElectricConductivityUnit.SiemensPerMeter, 2, ElectricConductivityUnit.SiemensPerMeter, false)] // Different value. + [InlineData(2, ElectricConductivityUnit.SiemensPerMeter, 1, ElectricConductivityUnit.MicrosiemensPerCentimeter, false)] // Different value and unit. + [InlineData(1, ElectricConductivityUnit.SiemensPerMeter, 1, ElectricConductivityUnit.MicrosiemensPerCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricConductivityUnit unitA, double valueB, ElectricConductivityUnit unitB, bool expectEqual) + { + var a = new ElectricConductivity(valueA, unitA); + var b = new ElectricConductivity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricConductivity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index e2e5e3a884..91d2799228 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => amperepersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricCurrentDensityUnit.AmperePerSquareMeter, 1, ElectricCurrentDensityUnit.AmperePerSquareMeter, true)] // Same value and unit. + [InlineData(1, ElectricCurrentDensityUnit.AmperePerSquareMeter, 2, ElectricCurrentDensityUnit.AmperePerSquareMeter, false)] // Different value. + [InlineData(2, ElectricCurrentDensityUnit.AmperePerSquareMeter, 1, ElectricCurrentDensityUnit.AmperePerSquareFoot, false)] // Different value and unit. + [InlineData(1, ElectricCurrentDensityUnit.AmperePerSquareMeter, 1, ElectricCurrentDensityUnit.AmperePerSquareFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricCurrentDensityUnit unitA, double valueB, ElectricCurrentDensityUnit unitB, bool expectEqual) + { + var a = new ElectricCurrentDensity(valueA, unitA); + var b = new ElectricCurrentDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricCurrentDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index 35bbba06d6..7fc9091d0e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => amperepersecond.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricCurrentGradientUnit.AmperePerSecond, 1, ElectricCurrentGradientUnit.AmperePerSecond, true)] // Same value and unit. + [InlineData(1, ElectricCurrentGradientUnit.AmperePerSecond, 2, ElectricCurrentGradientUnit.AmperePerSecond, false)] // Different value. + [InlineData(2, ElectricCurrentGradientUnit.AmperePerSecond, 1, ElectricCurrentGradientUnit.AmperePerMicrosecond, false)] // Different value and unit. + [InlineData(1, ElectricCurrentGradientUnit.AmperePerSecond, 1, ElectricCurrentGradientUnit.AmperePerMicrosecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricCurrentGradientUnit unitA, double valueB, ElectricCurrentGradientUnit unitB, bool expectEqual) + { + var a = new ElectricCurrentGradient(valueA, unitA); + var b = new ElectricCurrentGradient(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricCurrentGradient.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index 3fefb9fcae..0e6f68c753 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -536,6 +536,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => ampere.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricCurrentUnit.Ampere, 1, ElectricCurrentUnit.Ampere, true)] // Same value and unit. + [InlineData(1, ElectricCurrentUnit.Ampere, 2, ElectricCurrentUnit.Ampere, false)] // Different value. + [InlineData(2, ElectricCurrentUnit.Ampere, 1, ElectricCurrentUnit.Centiampere, false)] // Different value and unit. + [InlineData(1, ElectricCurrentUnit.Ampere, 1, ElectricCurrentUnit.Centiampere, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricCurrentUnit unitA, double valueB, ElectricCurrentUnit unitB, bool expectEqual) + { + var a = new ElectricCurrent(valueA, unitA); + var b = new ElectricCurrent(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricCurrent.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index 5f71e2aa59..3ca6bbb536 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricFieldUnit.VoltPerMeter, 1, ElectricFieldUnit.VoltPerMeter, true)] // Same value and unit. + [InlineData(1, ElectricFieldUnit.VoltPerMeter, 2, ElectricFieldUnit.VoltPerMeter, false)] // Different value. + [InlineData(2, ElectricFieldUnit.VoltPerMeter, 1, ElectricFieldUnit.VoltPerMeter, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricFieldUnit unitA, double valueB, ElectricFieldUnit unitB, bool expectEqual) + { + var a = new ElectricField(valueA, unitA); + var b = new ElectricField(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricField.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index f570fd9879..1eefe850c5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => henry.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricInductanceUnit.Henry, 1, ElectricInductanceUnit.Henry, true)] // Same value and unit. + [InlineData(1, ElectricInductanceUnit.Henry, 2, ElectricInductanceUnit.Henry, false)] // Different value. + [InlineData(2, ElectricInductanceUnit.Henry, 1, ElectricInductanceUnit.Microhenry, false)] // Different value and unit. + [InlineData(1, ElectricInductanceUnit.Henry, 1, ElectricInductanceUnit.Microhenry, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricInductanceUnit unitA, double valueB, ElectricInductanceUnit unitB, bool expectEqual) + { + var a = new ElectricInductance(valueA, unitA); + var b = new ElectricInductance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricInductance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs index eadd72a1be..e0ffc6815f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs @@ -431,6 +431,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltac.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricPotentialAcUnit.VoltAc, 1, ElectricPotentialAcUnit.VoltAc, true)] // Same value and unit. + [InlineData(1, ElectricPotentialAcUnit.VoltAc, 2, ElectricPotentialAcUnit.VoltAc, false)] // Different value. + [InlineData(2, ElectricPotentialAcUnit.VoltAc, 1, ElectricPotentialAcUnit.KilovoltAc, false)] // Different value and unit. + [InlineData(1, ElectricPotentialAcUnit.VoltAc, 1, ElectricPotentialAcUnit.KilovoltAc, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricPotentialAcUnit unitA, double valueB, ElectricPotentialAcUnit unitB, bool expectEqual) + { + var a = new ElectricPotentialAc(valueA, unitA); + var b = new ElectricPotentialAc(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricPotentialAc.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index 9b2e1843e0..905ace081d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -890,6 +890,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricPotentialChangeRateUnit.VoltPerSecond, 1, ElectricPotentialChangeRateUnit.VoltPerSecond, true)] // Same value and unit. + [InlineData(1, ElectricPotentialChangeRateUnit.VoltPerSecond, 2, ElectricPotentialChangeRateUnit.VoltPerSecond, false)] // Different value. + [InlineData(2, ElectricPotentialChangeRateUnit.VoltPerSecond, 1, ElectricPotentialChangeRateUnit.KilovoltPerHour, false)] // Different value and unit. + [InlineData(1, ElectricPotentialChangeRateUnit.VoltPerSecond, 1, ElectricPotentialChangeRateUnit.KilovoltPerHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricPotentialChangeRateUnit unitA, double valueB, ElectricPotentialChangeRateUnit unitB, bool expectEqual) + { + var a = new ElectricPotentialChangeRate(valueA, unitA); + var b = new ElectricPotentialChangeRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricPotentialChangeRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs index 9c75620dae..bcd0c589b0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs @@ -431,6 +431,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltdc.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricPotentialDcUnit.VoltDc, 1, ElectricPotentialDcUnit.VoltDc, true)] // Same value and unit. + [InlineData(1, ElectricPotentialDcUnit.VoltDc, 2, ElectricPotentialDcUnit.VoltDc, false)] // Different value. + [InlineData(2, ElectricPotentialDcUnit.VoltDc, 1, ElectricPotentialDcUnit.KilovoltDc, false)] // Different value and unit. + [InlineData(1, ElectricPotentialDcUnit.VoltDc, 1, ElectricPotentialDcUnit.KilovoltDc, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricPotentialDcUnit unitA, double valueB, ElectricPotentialDcUnit unitB, bool expectEqual) + { + var a = new ElectricPotentialDc(valueA, unitA); + var b = new ElectricPotentialDc(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricPotentialDc.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index 572a1fd853..603aee7188 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -529,6 +529,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => volt.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricPotentialUnit.Volt, 1, ElectricPotentialUnit.Volt, true)] // Same value and unit. + [InlineData(1, ElectricPotentialUnit.Volt, 2, ElectricPotentialUnit.Volt, false)] // Different value. + [InlineData(2, ElectricPotentialUnit.Volt, 1, ElectricPotentialUnit.Kilovolt, false)] // Different value and unit. + [InlineData(1, ElectricPotentialUnit.Volt, 1, ElectricPotentialUnit.Kilovolt, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricPotentialUnit unitA, double valueB, ElectricPotentialUnit unitB, bool expectEqual) + { + var a = new ElectricPotential(valueA, unitA); + var b = new ElectricPotential(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricPotential.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index 7ecb5bb8b0..65529c70de 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -466,6 +466,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => ohm.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricResistanceUnit.Ohm, 1, ElectricResistanceUnit.Ohm, true)] // Same value and unit. + [InlineData(1, ElectricResistanceUnit.Ohm, 2, ElectricResistanceUnit.Ohm, false)] // Different value. + [InlineData(2, ElectricResistanceUnit.Ohm, 1, ElectricResistanceUnit.Gigaohm, false)] // Different value and unit. + [InlineData(1, ElectricResistanceUnit.Ohm, 1, ElectricResistanceUnit.Gigaohm, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricResistanceUnit unitA, double valueB, ElectricResistanceUnit unitB, bool expectEqual) + { + var a = new ElectricResistance(valueA, unitA); + var b = new ElectricResistance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricResistance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index 145a7533e4..66c9aec560 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -724,6 +724,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => ohmmeter.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricResistivityUnit.OhmMeter, 1, ElectricResistivityUnit.OhmMeter, true)] // Same value and unit. + [InlineData(1, ElectricResistivityUnit.OhmMeter, 2, ElectricResistivityUnit.OhmMeter, false)] // Different value. + [InlineData(2, ElectricResistivityUnit.OhmMeter, 1, ElectricResistivityUnit.KiloohmCentimeter, false)] // Different value and unit. + [InlineData(1, ElectricResistivityUnit.OhmMeter, 1, ElectricResistivityUnit.KiloohmCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricResistivityUnit unitA, double valueB, ElectricResistivityUnit unitB, bool expectEqual) + { + var a = new ElectricResistivity(valueA, unitA); + var b = new ElectricResistivity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricResistivity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index 98b1414188..571b2b252b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => coulombpersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, 1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, true)] // Same value and unit. + [InlineData(1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, 2, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, false)] // Different value. + [InlineData(2, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, 1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, false)] // Different value and unit. + [InlineData(1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, 1, ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricSurfaceChargeDensityUnit unitA, double valueB, ElectricSurfaceChargeDensityUnit unitB, bool expectEqual) + { + var a = new ElectricSurfaceChargeDensity(valueA, unitA); + var b = new ElectricSurfaceChargeDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ElectricSurfaceChargeDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs index ab48d74243..abbaf496de 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs @@ -698,6 +698,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => joulepercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, EnergyDensityUnit.JoulePerCubicMeter, 1, EnergyDensityUnit.JoulePerCubicMeter, true)] // Same value and unit. + [InlineData(1, EnergyDensityUnit.JoulePerCubicMeter, 2, EnergyDensityUnit.JoulePerCubicMeter, false)] // Different value. + [InlineData(2, EnergyDensityUnit.JoulePerCubicMeter, 1, EnergyDensityUnit.GigajoulePerCubicMeter, false)] // Different value and unit. + [InlineData(1, EnergyDensityUnit.JoulePerCubicMeter, 1, EnergyDensityUnit.GigajoulePerCubicMeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, EnergyDensityUnit unitA, double valueB, EnergyDensityUnit unitB, bool expectEqual) + { + var a = new EnergyDensity(valueA, unitA); + var b = new EnergyDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = EnergyDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index b6eab436ff..c1f36315a2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -2090,6 +2090,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => joule.CompareTo(null)); } + [Theory] + [InlineData(1, EnergyUnit.Joule, 1, EnergyUnit.Joule, true)] // Same value and unit. + [InlineData(1, EnergyUnit.Joule, 2, EnergyUnit.Joule, false)] // Different value. + [InlineData(2, EnergyUnit.Joule, 1, EnergyUnit.BritishThermalUnit, false)] // Different value and unit. + [InlineData(1, EnergyUnit.Joule, 1, EnergyUnit.BritishThermalUnit, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, EnergyUnit unitA, double valueB, EnergyUnit unitB, bool expectEqual) + { + var a = new Energy(valueA, unitA); + var b = new Energy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Energy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index 5c4e0fba81..e32b26734e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -523,6 +523,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => jouleperkelvin.CompareTo(null)); } + [Theory] + [InlineData(1, EntropyUnit.JoulePerKelvin, 1, EntropyUnit.JoulePerKelvin, true)] // Same value and unit. + [InlineData(1, EntropyUnit.JoulePerKelvin, 2, EntropyUnit.JoulePerKelvin, false)] // Different value. + [InlineData(2, EntropyUnit.JoulePerKelvin, 1, EntropyUnit.CaloriePerKelvin, false)] // Different value and unit. + [InlineData(1, EntropyUnit.JoulePerKelvin, 1, EntropyUnit.CaloriePerKelvin, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, EntropyUnit unitA, double valueB, EntropyUnit unitB, bool expectEqual) + { + var a = new Entropy(valueA, unitA); + var b = new Entropy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Entropy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index 03a3a8a26a..aecb0ac156 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -899,6 +899,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, ForceChangeRateUnit.NewtonPerSecond, 1, ForceChangeRateUnit.NewtonPerSecond, true)] // Same value and unit. + [InlineData(1, ForceChangeRateUnit.NewtonPerSecond, 2, ForceChangeRateUnit.NewtonPerSecond, false)] // Different value. + [InlineData(2, ForceChangeRateUnit.NewtonPerSecond, 1, ForceChangeRateUnit.CentinewtonPerSecond, false)] // Different value and unit. + [InlineData(1, ForceChangeRateUnit.NewtonPerSecond, 1, ForceChangeRateUnit.CentinewtonPerSecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ForceChangeRateUnit unitA, double valueB, ForceChangeRateUnit unitB, bool expectEqual) + { + var a = new ForceChangeRate(valueA, unitA); + var b = new ForceChangeRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ForceChangeRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index 4fb3e67344..f7a8b85bd2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -1782,6 +1782,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, ForcePerLengthUnit.NewtonPerMeter, 1, ForcePerLengthUnit.NewtonPerMeter, true)] // Same value and unit. + [InlineData(1, ForcePerLengthUnit.NewtonPerMeter, 2, ForcePerLengthUnit.NewtonPerMeter, false)] // Different value. + [InlineData(2, ForcePerLengthUnit.NewtonPerMeter, 1, ForcePerLengthUnit.CentinewtonPerCentimeter, false)] // Different value and unit. + [InlineData(1, ForcePerLengthUnit.NewtonPerMeter, 1, ForcePerLengthUnit.CentinewtonPerCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ForcePerLengthUnit unitA, double valueB, ForcePerLengthUnit unitB, bool expectEqual) + { + var a = new ForcePerLength(valueA, unitA); + var b = new ForcePerLength(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ForcePerLength.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 5cf1bc320c..b31de791d1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -1217,6 +1217,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newton.CompareTo(null)); } + [Theory] + [InlineData(1, ForceUnit.Newton, 1, ForceUnit.Newton, true)] // Same value and unit. + [InlineData(1, ForceUnit.Newton, 2, ForceUnit.Newton, false)] // Different value. + [InlineData(2, ForceUnit.Newton, 1, ForceUnit.Decanewton, false)] // Different value and unit. + [InlineData(1, ForceUnit.Newton, 1, ForceUnit.Decanewton, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ForceUnit unitA, double valueB, ForceUnit unitB, bool expectEqual) + { + var a = new Force(valueA, unitA); + var b = new Force(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Force.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index 664a51f316..cc4aef4aca 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -831,6 +831,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => hertz.CompareTo(null)); } + [Theory] + [InlineData(1, FrequencyUnit.Hertz, 1, FrequencyUnit.Hertz, true)] // Same value and unit. + [InlineData(1, FrequencyUnit.Hertz, 2, FrequencyUnit.Hertz, false)] // Different value. + [InlineData(2, FrequencyUnit.Hertz, 1, FrequencyUnit.BeatPerMinute, false)] // Different value and unit. + [InlineData(1, FrequencyUnit.Hertz, 1, FrequencyUnit.BeatPerMinute, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, FrequencyUnit unitA, double valueB, FrequencyUnit unitB, bool expectEqual) + { + var a = new Frequency(valueA, unitA); + var b = new Frequency(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Frequency.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 561a6d1541..9e1ab85524 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => literper100kilometers.CompareTo(null)); } + [Theory] + [InlineData(1, FuelEfficiencyUnit.LiterPer100Kilometers, 1, FuelEfficiencyUnit.LiterPer100Kilometers, true)] // Same value and unit. + [InlineData(1, FuelEfficiencyUnit.LiterPer100Kilometers, 2, FuelEfficiencyUnit.LiterPer100Kilometers, false)] // Different value. + [InlineData(2, FuelEfficiencyUnit.LiterPer100Kilometers, 1, FuelEfficiencyUnit.KilometerPerLiter, false)] // Different value and unit. + [InlineData(1, FuelEfficiencyUnit.LiterPer100Kilometers, 1, FuelEfficiencyUnit.KilometerPerLiter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, FuelEfficiencyUnit unitA, double valueB, FuelEfficiencyUnit unitB, bool expectEqual) + { + var a = new FuelEfficiency(valueA, unitA); + var b = new FuelEfficiency(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = FuelEfficiency.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index f2116bb954..9a08cd99eb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -932,6 +932,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => wattpersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, HeatFluxUnit.WattPerSquareMeter, 1, HeatFluxUnit.WattPerSquareMeter, true)] // Same value and unit. + [InlineData(1, HeatFluxUnit.WattPerSquareMeter, 2, HeatFluxUnit.WattPerSquareMeter, false)] // Different value. + [InlineData(2, HeatFluxUnit.WattPerSquareMeter, 1, HeatFluxUnit.BtuPerHourSquareFoot, false)] // Different value and unit. + [InlineData(1, HeatFluxUnit.WattPerSquareMeter, 1, HeatFluxUnit.BtuPerHourSquareFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, HeatFluxUnit unitA, double valueB, HeatFluxUnit unitB, bool expectEqual) + { + var a = new HeatFlux(valueA, unitA); + var b = new HeatFlux(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = HeatFlux.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index 6e1d165436..6c5ea66165 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => wattpersquaremeterkelvin.CompareTo(null)); } + [Theory] + [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, true)] // Same value and unit. + [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 2, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, false)] // Different value. + [InlineData(2, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, false)] // Different value and unit. + [InlineData(1, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, 1, HeatTransferCoefficientUnit.BtuPerSquareFootDegreeFahrenheit, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, HeatTransferCoefficientUnit unitA, double valueB, HeatTransferCoefficientUnit unitB, bool expectEqual) + { + var a = new HeatTransferCoefficient(valueA, unitA); + var b = new HeatTransferCoefficient(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = HeatTransferCoefficient.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index c1f2dc701b..df936d55c7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -396,6 +396,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => lux.CompareTo(null)); } + [Theory] + [InlineData(1, IlluminanceUnit.Lux, 1, IlluminanceUnit.Lux, true)] // Same value and unit. + [InlineData(1, IlluminanceUnit.Lux, 2, IlluminanceUnit.Lux, false)] // Different value. + [InlineData(2, IlluminanceUnit.Lux, 1, IlluminanceUnit.Kilolux, false)] // Different value and unit. + [InlineData(1, IlluminanceUnit.Lux, 1, IlluminanceUnit.Kilolux, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, IlluminanceUnit unitA, double valueB, IlluminanceUnit unitB, bool expectEqual) + { + var a = new Illuminance(valueA, unitA); + var b = new Illuminance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Illuminance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index 11d7e9d323..d451f870bd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -877,6 +877,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => bit.CompareTo(null)); } + [Theory] + [InlineData(1, InformationUnit.Bit, 1, InformationUnit.Bit, true)] // Same value and unit. + [InlineData(1, InformationUnit.Bit, 2, InformationUnit.Bit, false)] // Different value. + [InlineData(2, InformationUnit.Bit, 1, InformationUnit.Byte, false)] // Different value and unit. + [InlineData(1, InformationUnit.Bit, 1, InformationUnit.Byte, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(decimal valueA, InformationUnit unitA, decimal valueB, InformationUnit unitB, bool expectEqual) + { + var a = new Information(valueA, unitA); + var b = new Information(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Information.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index 441d2dca10..30bb2a73b3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -724,6 +724,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => wattpersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, IrradianceUnit.WattPerSquareMeter, 1, IrradianceUnit.WattPerSquareMeter, true)] // Same value and unit. + [InlineData(1, IrradianceUnit.WattPerSquareMeter, 2, IrradianceUnit.WattPerSquareMeter, false)] // Different value. + [InlineData(2, IrradianceUnit.WattPerSquareMeter, 1, IrradianceUnit.KilowattPerSquareCentimeter, false)] // Different value and unit. + [InlineData(1, IrradianceUnit.WattPerSquareMeter, 1, IrradianceUnit.KilowattPerSquareCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, IrradianceUnit unitA, double valueB, IrradianceUnit unitB, bool expectEqual) + { + var a = new Irradiance(valueA, unitA); + var b = new Irradiance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Irradiance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index ea40190154..456fffe47e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -523,6 +523,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => joulepersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, IrradiationUnit.JoulePerSquareMeter, 1, IrradiationUnit.JoulePerSquareMeter, true)] // Same value and unit. + [InlineData(1, IrradiationUnit.JoulePerSquareMeter, 2, IrradiationUnit.JoulePerSquareMeter, false)] // Different value. + [InlineData(2, IrradiationUnit.JoulePerSquareMeter, 1, IrradiationUnit.JoulePerSquareCentimeter, false)] // Different value and unit. + [InlineData(1, IrradiationUnit.JoulePerSquareMeter, 1, IrradiationUnit.JoulePerSquareCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, IrradiationUnit unitA, double valueB, IrradiationUnit unitB, bool expectEqual) + { + var a = new Irradiation(valueA, unitA); + var b = new Irradiation(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Irradiation.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs index 2348b7f6ac..2ddde4b4d2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs @@ -927,6 +927,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => meterpersecondcubed.CompareTo(null)); } + [Theory] + [InlineData(1, JerkUnit.MeterPerSecondCubed, 1, JerkUnit.MeterPerSecondCubed, true)] // Same value and unit. + [InlineData(1, JerkUnit.MeterPerSecondCubed, 2, JerkUnit.MeterPerSecondCubed, false)] // Different value. + [InlineData(2, JerkUnit.MeterPerSecondCubed, 1, JerkUnit.CentimeterPerSecondCubed, false)] // Different value and unit. + [InlineData(1, JerkUnit.MeterPerSecondCubed, 1, JerkUnit.CentimeterPerSecondCubed, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, JerkUnit unitA, double valueB, JerkUnit unitB, bool expectEqual) + { + var a = new Jerk(valueA, unitA); + var b = new Jerk(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Jerk.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index b3e25ed4d1..cc14d082df 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -785,6 +785,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => squaremeterpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, KinematicViscosityUnit.SquareMeterPerSecond, 1, KinematicViscosityUnit.SquareMeterPerSecond, true)] // Same value and unit. + [InlineData(1, KinematicViscosityUnit.SquareMeterPerSecond, 2, KinematicViscosityUnit.SquareMeterPerSecond, false)] // Different value. + [InlineData(2, KinematicViscosityUnit.SquareMeterPerSecond, 1, KinematicViscosityUnit.Centistokes, false)] // Different value and unit. + [InlineData(1, KinematicViscosityUnit.SquareMeterPerSecond, 1, KinematicViscosityUnit.Centistokes, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, KinematicViscosityUnit unitA, double valueB, KinematicViscosityUnit unitB, bool expectEqual) + { + var a = new KinematicViscosity(valueA, unitA); + var b = new KinematicViscosity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = KinematicViscosity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs index d562077b14..624c1e33a4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LapseRateTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => degreecelsiusperkilometer.CompareTo(null)); } + [Theory] + [InlineData(1, LapseRateUnit.DegreeCelsiusPerKilometer, 1, LapseRateUnit.DegreeCelsiusPerKilometer, true)] // Same value and unit. + [InlineData(1, LapseRateUnit.DegreeCelsiusPerKilometer, 2, LapseRateUnit.DegreeCelsiusPerKilometer, false)] // Different value. + [InlineData(2, LapseRateUnit.DegreeCelsiusPerKilometer, 1, LapseRateUnit.DegreeCelsiusPerKilometer, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LapseRateUnit unitA, double valueB, LapseRateUnit unitB, bool expectEqual) + { + var a = new LapseRate(valueA, unitA); + var b = new LapseRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = LapseRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index b0bfe72b23..43505d89aa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -2342,6 +2342,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => meter.CompareTo(null)); } + [Theory] + [InlineData(1, LengthUnit.Meter, 1, LengthUnit.Meter, true)] // Same value and unit. + [InlineData(1, LengthUnit.Meter, 2, LengthUnit.Meter, false)] // Different value. + [InlineData(2, LengthUnit.Meter, 1, LengthUnit.Angstrom, false)] // Different value and unit. + [InlineData(1, LengthUnit.Meter, 1, LengthUnit.Angstrom, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LengthUnit unitA, double valueB, LengthUnit unitB, bool expectEqual) + { + var a = new Length(valueA, unitA); + var b = new Length(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Length.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index b163c6d690..1d4608d679 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -352,6 +352,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decibel.CompareTo(null)); } + [Theory] + [InlineData(1, LevelUnit.Decibel, 1, LevelUnit.Decibel, true)] // Same value and unit. + [InlineData(1, LevelUnit.Decibel, 2, LevelUnit.Decibel, false)] // Different value. + [InlineData(2, LevelUnit.Decibel, 1, LevelUnit.Neper, false)] // Different value and unit. + [InlineData(1, LevelUnit.Decibel, 1, LevelUnit.Neper, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LevelUnit unitA, double valueB, LevelUnit unitB, bool expectEqual) + { + var a = new Level(valueA, unitA); + var b = new Level(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Level.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index 06b421e2ab..d32b4f704b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -768,6 +768,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogrampermeter.CompareTo(null)); } + [Theory] + [InlineData(1, LinearDensityUnit.KilogramPerMeter, 1, LinearDensityUnit.KilogramPerMeter, true)] // Same value and unit. + [InlineData(1, LinearDensityUnit.KilogramPerMeter, 2, LinearDensityUnit.KilogramPerMeter, false)] // Different value. + [InlineData(2, LinearDensityUnit.KilogramPerMeter, 1, LinearDensityUnit.GramPerCentimeter, false)] // Different value and unit. + [InlineData(1, LinearDensityUnit.KilogramPerMeter, 1, LinearDensityUnit.GramPerCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LinearDensityUnit unitA, double valueB, LinearDensityUnit unitB, bool expectEqual) + { + var a = new LinearDensity(valueA, unitA); + var b = new LinearDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = LinearDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index 1a89abd89f..dae88a72c6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -1043,6 +1043,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => wattpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, LinearPowerDensityUnit.WattPerMeter, 1, LinearPowerDensityUnit.WattPerMeter, true)] // Same value and unit. + [InlineData(1, LinearPowerDensityUnit.WattPerMeter, 2, LinearPowerDensityUnit.WattPerMeter, false)] // Different value. + [InlineData(2, LinearPowerDensityUnit.WattPerMeter, 1, LinearPowerDensityUnit.GigawattPerCentimeter, false)] // Different value and unit. + [InlineData(1, LinearPowerDensityUnit.WattPerMeter, 1, LinearPowerDensityUnit.GigawattPerCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LinearPowerDensityUnit unitA, double valueB, LinearPowerDensityUnit unitB, bool expectEqual) + { + var a = new LinearPowerDensity(valueA, unitA); + var b = new LinearPowerDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = LinearPowerDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs index 10ecdb3f60..c5b184aa8b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs @@ -628,6 +628,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => candelapersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, LuminanceUnit.CandelaPerSquareMeter, 1, LuminanceUnit.CandelaPerSquareMeter, true)] // Same value and unit. + [InlineData(1, LuminanceUnit.CandelaPerSquareMeter, 2, LuminanceUnit.CandelaPerSquareMeter, false)] // Different value. + [InlineData(2, LuminanceUnit.CandelaPerSquareMeter, 1, LuminanceUnit.CandelaPerSquareFoot, false)] // Different value and unit. + [InlineData(1, LuminanceUnit.CandelaPerSquareMeter, 1, LuminanceUnit.CandelaPerSquareFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LuminanceUnit unitA, double valueB, LuminanceUnit unitB, bool expectEqual) + { + var a = new Luminance(valueA, unitA); + var b = new Luminance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Luminance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index d56fa7953e..a92b569ac8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -724,6 +724,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => watt.CompareTo(null)); } + [Theory] + [InlineData(1, LuminosityUnit.Watt, 1, LuminosityUnit.Watt, true)] // Same value and unit. + [InlineData(1, LuminosityUnit.Watt, 2, LuminosityUnit.Watt, false)] // Different value. + [InlineData(2, LuminosityUnit.Watt, 1, LuminosityUnit.Decawatt, false)] // Different value and unit. + [InlineData(1, LuminosityUnit.Watt, 1, LuminosityUnit.Decawatt, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LuminosityUnit unitA, double valueB, LuminosityUnit unitB, bool expectEqual) + { + var a = new Luminosity(valueA, unitA); + var b = new Luminosity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Luminosity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index 208ed4cbf9..50ea467dd9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => lumen.CompareTo(null)); } + [Theory] + [InlineData(1, LuminousFluxUnit.Lumen, 1, LuminousFluxUnit.Lumen, true)] // Same value and unit. + [InlineData(1, LuminousFluxUnit.Lumen, 2, LuminousFluxUnit.Lumen, false)] // Different value. + [InlineData(2, LuminousFluxUnit.Lumen, 1, LuminousFluxUnit.Lumen, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LuminousFluxUnit unitA, double valueB, LuminousFluxUnit unitB, bool expectEqual) + { + var a = new LuminousFlux(valueA, unitA); + var b = new LuminousFlux(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = LuminousFlux.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index da524e7077..67a5c996b3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => candela.CompareTo(null)); } + [Theory] + [InlineData(1, LuminousIntensityUnit.Candela, 1, LuminousIntensityUnit.Candela, true)] // Same value and unit. + [InlineData(1, LuminousIntensityUnit.Candela, 2, LuminousIntensityUnit.Candela, false)] // Different value. + [InlineData(2, LuminousIntensityUnit.Candela, 1, LuminousIntensityUnit.Candela, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, LuminousIntensityUnit unitA, double valueB, LuminousIntensityUnit unitB, bool expectEqual) + { + var a = new LuminousIntensity(valueA, unitA); + var b = new LuminousIntensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = LuminousIntensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index 206474b9dc..2a6646df54 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -488,6 +488,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => tesla.CompareTo(null)); } + [Theory] + [InlineData(1, MagneticFieldUnit.Tesla, 1, MagneticFieldUnit.Tesla, true)] // Same value and unit. + [InlineData(1, MagneticFieldUnit.Tesla, 2, MagneticFieldUnit.Tesla, false)] // Different value. + [InlineData(2, MagneticFieldUnit.Tesla, 1, MagneticFieldUnit.Gauss, false)] // Different value and unit. + [InlineData(1, MagneticFieldUnit.Tesla, 1, MagneticFieldUnit.Gauss, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MagneticFieldUnit unitA, double valueB, MagneticFieldUnit unitB, bool expectEqual) + { + var a = new MagneticField(valueA, unitA); + var b = new MagneticField(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MagneticField.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index c60ea26274..935b675489 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => weber.CompareTo(null)); } + [Theory] + [InlineData(1, MagneticFluxUnit.Weber, 1, MagneticFluxUnit.Weber, true)] // Same value and unit. + [InlineData(1, MagneticFluxUnit.Weber, 2, MagneticFluxUnit.Weber, false)] // Different value. + [InlineData(2, MagneticFluxUnit.Weber, 1, MagneticFluxUnit.Weber, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MagneticFluxUnit unitA, double valueB, MagneticFluxUnit unitB, bool expectEqual) + { + var a = new MagneticFlux(valueA, unitA); + var b = new MagneticFlux(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MagneticFlux.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index 27481dec8d..6dee668baf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => amperepermeter.CompareTo(null)); } + [Theory] + [InlineData(1, MagnetizationUnit.AmperePerMeter, 1, MagnetizationUnit.AmperePerMeter, true)] // Same value and unit. + [InlineData(1, MagnetizationUnit.AmperePerMeter, 2, MagnetizationUnit.AmperePerMeter, false)] // Different value. + [InlineData(2, MagnetizationUnit.AmperePerMeter, 1, MagnetizationUnit.AmperePerMeter, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MagnetizationUnit unitA, double valueB, MagnetizationUnit unitB, bool expectEqual) + { + var a = new Magnetization(valueA, unitA); + var b = new Magnetization(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Magnetization.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index cc0560bbbb..6bc9ae6944 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -2089,6 +2089,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogrampercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, MassConcentrationUnit.KilogramPerCubicMeter, 1, MassConcentrationUnit.KilogramPerCubicMeter, true)] // Same value and unit. + [InlineData(1, MassConcentrationUnit.KilogramPerCubicMeter, 2, MassConcentrationUnit.KilogramPerCubicMeter, false)] // Different value. + [InlineData(2, MassConcentrationUnit.KilogramPerCubicMeter, 1, MassConcentrationUnit.CentigramPerDeciliter, false)] // Different value and unit. + [InlineData(1, MassConcentrationUnit.KilogramPerCubicMeter, 1, MassConcentrationUnit.CentigramPerDeciliter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MassConcentrationUnit unitA, double valueB, MassConcentrationUnit unitB, bool expectEqual) + { + var a = new MassConcentration(valueA, unitA); + var b = new MassConcentration(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MassConcentration.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index 89627309ae..c2cd778fd7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -1675,6 +1675,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => grampersecond.CompareTo(null)); } + [Theory] + [InlineData(1, MassFlowUnit.GramPerSecond, 1, MassFlowUnit.GramPerSecond, true)] // Same value and unit. + [InlineData(1, MassFlowUnit.GramPerSecond, 2, MassFlowUnit.GramPerSecond, false)] // Different value. + [InlineData(2, MassFlowUnit.GramPerSecond, 1, MassFlowUnit.CentigramPerDay, false)] // Different value and unit. + [InlineData(1, MassFlowUnit.GramPerSecond, 1, MassFlowUnit.CentigramPerDay, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MassFlowUnit unitA, double valueB, MassFlowUnit unitB, bool expectEqual) + { + var a = new MassFlow(valueA, unitA); + var b = new MassFlow(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MassFlow.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 91c3178d40..72745c3312 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -698,6 +698,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogrampersecondpersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, MassFluxUnit.KilogramPerSecondPerSquareMeter, 1, MassFluxUnit.KilogramPerSecondPerSquareMeter, true)] // Same value and unit. + [InlineData(1, MassFluxUnit.KilogramPerSecondPerSquareMeter, 2, MassFluxUnit.KilogramPerSecondPerSquareMeter, false)] // Different value. + [InlineData(2, MassFluxUnit.KilogramPerSecondPerSquareMeter, 1, MassFluxUnit.GramPerHourPerSquareCentimeter, false)] // Different value and unit. + [InlineData(1, MassFluxUnit.KilogramPerSecondPerSquareMeter, 1, MassFluxUnit.GramPerHourPerSquareCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MassFluxUnit unitA, double valueB, MassFluxUnit unitB, bool expectEqual) + { + var a = new MassFlux(valueA, unitA); + var b = new MassFlux(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MassFlux.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index fb4a1163c8..6ad70e4b15 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -1142,6 +1142,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decimalfraction.CompareTo(null)); } + [Theory] + [InlineData(1, MassFractionUnit.DecimalFraction, 1, MassFractionUnit.DecimalFraction, true)] // Same value and unit. + [InlineData(1, MassFractionUnit.DecimalFraction, 2, MassFractionUnit.DecimalFraction, false)] // Different value. + [InlineData(2, MassFractionUnit.DecimalFraction, 1, MassFractionUnit.CentigramPerGram, false)] // Different value and unit. + [InlineData(1, MassFractionUnit.DecimalFraction, 1, MassFractionUnit.CentigramPerGram, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MassFractionUnit unitA, double valueB, MassFractionUnit unitB, bool expectEqual) + { + var a = new MassFraction(valueA, unitA); + var b = new MassFraction(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MassFraction.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index a2d27035a9..82f3e2e6c8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -1258,6 +1258,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogramsquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, MassMomentOfInertiaUnit.KilogramSquareMeter, 1, MassMomentOfInertiaUnit.KilogramSquareMeter, true)] // Same value and unit. + [InlineData(1, MassMomentOfInertiaUnit.KilogramSquareMeter, 2, MassMomentOfInertiaUnit.KilogramSquareMeter, false)] // Different value. + [InlineData(2, MassMomentOfInertiaUnit.KilogramSquareMeter, 1, MassMomentOfInertiaUnit.GramSquareCentimeter, false)] // Different value and unit. + [InlineData(1, MassMomentOfInertiaUnit.KilogramSquareMeter, 1, MassMomentOfInertiaUnit.GramSquareCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MassMomentOfInertiaUnit unitA, double valueB, MassMomentOfInertiaUnit unitB, bool expectEqual) + { + var a = new MassMomentOfInertia(valueA, unitA); + var b = new MassMomentOfInertia(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MassMomentOfInertia.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index b91f58b8f4..8f89dcb6a9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -2165,6 +2165,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogram.CompareTo(null)); } + [Theory] + [InlineData(1, MassUnit.Kilogram, 1, MassUnit.Kilogram, true)] // Same value and unit. + [InlineData(1, MassUnit.Kilogram, 2, MassUnit.Kilogram, false)] // Different value. + [InlineData(2, MassUnit.Kilogram, 1, MassUnit.Centigram, false)] // Different value and unit. + [InlineData(1, MassUnit.Kilogram, 1, MassUnit.Centigram, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MassUnit unitA, double valueB, MassUnit unitB, bool expectEqual) + { + var a = new Mass(valueA, unitA); + var b = new Mass(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Mass.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 6e0e75c6e1..da7ef803bd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => joulepermole.CompareTo(null)); } + [Theory] + [InlineData(1, MolarEnergyUnit.JoulePerMole, 1, MolarEnergyUnit.JoulePerMole, true)] // Same value and unit. + [InlineData(1, MolarEnergyUnit.JoulePerMole, 2, MolarEnergyUnit.JoulePerMole, false)] // Different value. + [InlineData(2, MolarEnergyUnit.JoulePerMole, 1, MolarEnergyUnit.KilojoulePerMole, false)] // Different value and unit. + [InlineData(1, MolarEnergyUnit.JoulePerMole, 1, MolarEnergyUnit.KilojoulePerMole, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MolarEnergyUnit unitA, double valueB, MolarEnergyUnit unitB, bool expectEqual) + { + var a = new MolarEnergy(valueA, unitA); + var b = new MolarEnergy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MolarEnergy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index 45386c5665..7100a708e1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => joulepermolekelvin.CompareTo(null)); } + [Theory] + [InlineData(1, MolarEntropyUnit.JoulePerMoleKelvin, 1, MolarEntropyUnit.JoulePerMoleKelvin, true)] // Same value and unit. + [InlineData(1, MolarEntropyUnit.JoulePerMoleKelvin, 2, MolarEntropyUnit.JoulePerMoleKelvin, false)] // Different value. + [InlineData(2, MolarEntropyUnit.JoulePerMoleKelvin, 1, MolarEntropyUnit.KilojoulePerMoleKelvin, false)] // Different value and unit. + [InlineData(1, MolarEntropyUnit.JoulePerMoleKelvin, 1, MolarEntropyUnit.KilojoulePerMoleKelvin, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MolarEntropyUnit unitA, double valueB, MolarEntropyUnit unitB, bool expectEqual) + { + var a = new MolarEntropy(valueA, unitA); + var b = new MolarEntropy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MolarEntropy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index f8524af4da..484f8a6e4a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -986,6 +986,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kilogrampermole.CompareTo(null)); } + [Theory] + [InlineData(1, MolarMassUnit.KilogramPerMole, 1, MolarMassUnit.KilogramPerMole, true)] // Same value and unit. + [InlineData(1, MolarMassUnit.KilogramPerMole, 2, MolarMassUnit.KilogramPerMole, false)] // Different value. + [InlineData(2, MolarMassUnit.KilogramPerMole, 1, MolarMassUnit.CentigramPerMole, false)] // Different value and unit. + [InlineData(1, MolarMassUnit.KilogramPerMole, 1, MolarMassUnit.CentigramPerMole, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MolarMassUnit unitA, double valueB, MolarMassUnit unitB, bool expectEqual) + { + var a = new MolarMass(valueA, unitA); + var b = new MolarMass(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = MolarMass.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index 4f84016d2a..6e59581986 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -692,6 +692,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => molespercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, MolarityUnit.MolesPerCubicMeter, 1, MolarityUnit.MolesPerCubicMeter, true)] // Same value and unit. + [InlineData(1, MolarityUnit.MolesPerCubicMeter, 2, MolarityUnit.MolesPerCubicMeter, false)] // Different value. + [InlineData(2, MolarityUnit.MolesPerCubicMeter, 1, MolarityUnit.CentimolePerLiter, false)] // Different value and unit. + [InlineData(1, MolarityUnit.MolesPerCubicMeter, 1, MolarityUnit.CentimolePerLiter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, MolarityUnit unitA, double valueB, MolarityUnit unitB, bool expectEqual) + { + var a = new Molarity(valueA, unitA); + var b = new Molarity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Molarity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index b03b669739..81c52d6521 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => henrypermeter.CompareTo(null)); } + [Theory] + [InlineData(1, PermeabilityUnit.HenryPerMeter, 1, PermeabilityUnit.HenryPerMeter, true)] // Same value and unit. + [InlineData(1, PermeabilityUnit.HenryPerMeter, 2, PermeabilityUnit.HenryPerMeter, false)] // Different value. + [InlineData(2, PermeabilityUnit.HenryPerMeter, 1, PermeabilityUnit.HenryPerMeter, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PermeabilityUnit unitA, double valueB, PermeabilityUnit unitB, bool expectEqual) + { + var a = new Permeability(valueA, unitA); + var b = new Permeability(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Permeability.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index bf1e279d93..fb271b6d5b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => faradpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, PermittivityUnit.FaradPerMeter, 1, PermittivityUnit.FaradPerMeter, true)] // Same value and unit. + [InlineData(1, PermittivityUnit.FaradPerMeter, 2, PermittivityUnit.FaradPerMeter, false)] // Different value. + [InlineData(2, PermittivityUnit.FaradPerMeter, 1, PermittivityUnit.FaradPerMeter, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PermittivityUnit unitA, double valueB, PermittivityUnit unitB, bool expectEqual) + { + var a = new Permittivity(valueA, unitA); + var b = new Permittivity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Permittivity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs index 7872e0f7b2..9448088ace 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs @@ -453,6 +453,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => squaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, PorousMediumPermeabilityUnit.SquareMeter, 1, PorousMediumPermeabilityUnit.SquareMeter, true)] // Same value and unit. + [InlineData(1, PorousMediumPermeabilityUnit.SquareMeter, 2, PorousMediumPermeabilityUnit.SquareMeter, false)] // Different value. + [InlineData(2, PorousMediumPermeabilityUnit.SquareMeter, 1, PorousMediumPermeabilityUnit.Darcy, false)] // Different value and unit. + [InlineData(1, PorousMediumPermeabilityUnit.SquareMeter, 1, PorousMediumPermeabilityUnit.Darcy, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PorousMediumPermeabilityUnit unitA, double valueB, PorousMediumPermeabilityUnit unitB, bool expectEqual) + { + var a = new PorousMediumPermeability(valueA, unitA); + var b = new PorousMediumPermeability(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = PorousMediumPermeability.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index 88c468611d..8c58a205f7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -1730,6 +1730,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => wattpercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, PowerDensityUnit.WattPerCubicMeter, 1, PowerDensityUnit.WattPerCubicMeter, true)] // Same value and unit. + [InlineData(1, PowerDensityUnit.WattPerCubicMeter, 2, PowerDensityUnit.WattPerCubicMeter, false)] // Different value. + [InlineData(2, PowerDensityUnit.WattPerCubicMeter, 1, PowerDensityUnit.DecawattPerCubicFoot, false)] // Different value and unit. + [InlineData(1, PowerDensityUnit.WattPerCubicMeter, 1, PowerDensityUnit.DecawattPerCubicFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PowerDensityUnit unitA, double valueB, PowerDensityUnit unitB, bool expectEqual) + { + var a = new PowerDensity(valueA, unitA); + var b = new PowerDensity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = PowerDensity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index e411e27045..5bfb2cf143 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -376,6 +376,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decibelwatt.CompareTo(null)); } + [Theory] + [InlineData(1, PowerRatioUnit.DecibelWatt, 1, PowerRatioUnit.DecibelWatt, true)] // Same value and unit. + [InlineData(1, PowerRatioUnit.DecibelWatt, 2, PowerRatioUnit.DecibelWatt, false)] // Different value. + [InlineData(2, PowerRatioUnit.DecibelWatt, 1, PowerRatioUnit.DecibelMilliwatt, false)] // Different value and unit. + [InlineData(1, PowerRatioUnit.DecibelWatt, 1, PowerRatioUnit.DecibelMilliwatt, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PowerRatioUnit unitA, double valueB, PowerRatioUnit unitB, bool expectEqual) + { + var a = new PowerRatio(valueA, unitA); + var b = new PowerRatio(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = PowerRatio.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index 699c327702..8b265aadb9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -1169,6 +1169,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => watt.CompareTo(null)); } + [Theory] + [InlineData(1, PowerUnit.Watt, 1, PowerUnit.Watt, true)] // Same value and unit. + [InlineData(1, PowerUnit.Watt, 2, PowerUnit.Watt, false)] // Different value. + [InlineData(2, PowerUnit.Watt, 1, PowerUnit.BoilerHorsepower, false)] // Different value and unit. + [InlineData(1, PowerUnit.Watt, 1, PowerUnit.BoilerHorsepower, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(decimal valueA, PowerUnit unitA, decimal valueB, PowerUnit unitB, bool expectEqual) + { + var a = new Power(valueA, unitA); + var b = new Power(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Power.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index e6ce1addf0..3cebe87f40 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -1392,6 +1392,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => pascalpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, PressureChangeRateUnit.PascalPerSecond, 1, PressureChangeRateUnit.PascalPerSecond, true)] // Same value and unit. + [InlineData(1, PressureChangeRateUnit.PascalPerSecond, 2, PressureChangeRateUnit.PascalPerSecond, false)] // Different value. + [InlineData(2, PressureChangeRateUnit.PascalPerSecond, 1, PressureChangeRateUnit.AtmospherePerSecond, false)] // Different value and unit. + [InlineData(1, PressureChangeRateUnit.PascalPerSecond, 1, PressureChangeRateUnit.AtmospherePerSecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PressureChangeRateUnit unitA, double valueB, PressureChangeRateUnit unitB, bool expectEqual) + { + var a = new PressureChangeRate(valueA, unitA); + var b = new PressureChangeRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = PressureChangeRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index e13f61c734..5421f26c52 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -2773,6 +2773,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => pascal.CompareTo(null)); } + [Theory] + [InlineData(1, PressureUnit.Pascal, 1, PressureUnit.Pascal, true)] // Same value and unit. + [InlineData(1, PressureUnit.Pascal, 2, PressureUnit.Pascal, false)] // Different value. + [InlineData(2, PressureUnit.Pascal, 1, PressureUnit.Atmosphere, false)] // Different value and unit. + [InlineData(1, PressureUnit.Pascal, 1, PressureUnit.Atmosphere, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, PressureUnit unitA, double valueB, PressureUnit unitB, bool expectEqual) + { + var a = new Pressure(valueA, unitA); + var b = new Pressure(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Pressure.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index a2c7663d02..e40a3c475b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -348,6 +348,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decimalfractionpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, RatioChangeRateUnit.DecimalFractionPerSecond, 1, RatioChangeRateUnit.DecimalFractionPerSecond, true)] // Same value and unit. + [InlineData(1, RatioChangeRateUnit.DecimalFractionPerSecond, 2, RatioChangeRateUnit.DecimalFractionPerSecond, false)] // Different value. + [InlineData(2, RatioChangeRateUnit.DecimalFractionPerSecond, 1, RatioChangeRateUnit.PercentPerSecond, false)] // Different value and unit. + [InlineData(1, RatioChangeRateUnit.DecimalFractionPerSecond, 1, RatioChangeRateUnit.PercentPerSecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RatioChangeRateUnit unitA, double valueB, RatioChangeRateUnit unitB, bool expectEqual) + { + var a = new RatioChangeRate(valueA, unitA); + var b = new RatioChangeRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RatioChangeRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index a1852e6120..e04b81d01d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -488,6 +488,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decimalfraction.CompareTo(null)); } + [Theory] + [InlineData(1, RatioUnit.DecimalFraction, 1, RatioUnit.DecimalFraction, true)] // Same value and unit. + [InlineData(1, RatioUnit.DecimalFraction, 2, RatioUnit.DecimalFraction, false)] // Different value. + [InlineData(2, RatioUnit.DecimalFraction, 1, RatioUnit.PartPerBillion, false)] // Different value and unit. + [InlineData(1, RatioUnit.DecimalFraction, 1, RatioUnit.PartPerBillion, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RatioUnit unitA, double valueB, RatioUnit unitB, bool expectEqual) + { + var a = new Ratio(valueA, unitA); + var b = new Ratio(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Ratio.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs index e1c636db0c..fa58df0fa6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltamperereactivehour.CompareTo(null)); } + [Theory] + [InlineData(1, ReactiveEnergyUnit.VoltampereReactiveHour, 1, ReactiveEnergyUnit.VoltampereReactiveHour, true)] // Same value and unit. + [InlineData(1, ReactiveEnergyUnit.VoltampereReactiveHour, 2, ReactiveEnergyUnit.VoltampereReactiveHour, false)] // Different value. + [InlineData(2, ReactiveEnergyUnit.VoltampereReactiveHour, 1, ReactiveEnergyUnit.KilovoltampereReactiveHour, false)] // Different value and unit. + [InlineData(1, ReactiveEnergyUnit.VoltampereReactiveHour, 1, ReactiveEnergyUnit.KilovoltampereReactiveHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ReactiveEnergyUnit unitA, double valueB, ReactiveEnergyUnit unitB, bool expectEqual) + { + var a = new ReactiveEnergy(valueA, unitA); + var b = new ReactiveEnergy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ReactiveEnergy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs index e26822c8cc..6e25f69d15 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => voltamperereactive.CompareTo(null)); } + [Theory] + [InlineData(1, ReactivePowerUnit.VoltampereReactive, 1, ReactivePowerUnit.VoltampereReactive, true)] // Same value and unit. + [InlineData(1, ReactivePowerUnit.VoltampereReactive, 2, ReactivePowerUnit.VoltampereReactive, false)] // Different value. + [InlineData(2, ReactivePowerUnit.VoltampereReactive, 1, ReactivePowerUnit.GigavoltampereReactive, false)] // Different value and unit. + [InlineData(1, ReactivePowerUnit.VoltampereReactive, 1, ReactivePowerUnit.GigavoltampereReactive, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ReactivePowerUnit unitA, double valueB, ReactivePowerUnit unitB, bool expectEqual) + { + var a = new ReactivePower(valueA, unitA); + var b = new ReactivePower(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ReactivePower.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs index a4f1991631..ef95ea5499 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs @@ -663,6 +663,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => inversesquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, ReciprocalAreaUnit.InverseSquareMeter, 1, ReciprocalAreaUnit.InverseSquareMeter, true)] // Same value and unit. + [InlineData(1, ReciprocalAreaUnit.InverseSquareMeter, 2, ReciprocalAreaUnit.InverseSquareMeter, false)] // Different value. + [InlineData(2, ReciprocalAreaUnit.InverseSquareMeter, 1, ReciprocalAreaUnit.InverseSquareCentimeter, false)] // Different value and unit. + [InlineData(1, ReciprocalAreaUnit.InverseSquareMeter, 1, ReciprocalAreaUnit.InverseSquareCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ReciprocalAreaUnit unitA, double valueB, ReciprocalAreaUnit unitB, bool expectEqual) + { + var a = new ReciprocalArea(valueA, unitA); + var b = new ReciprocalArea(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ReciprocalArea.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index 2ec91984be..44e02e8cfa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -868,6 +868,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => inversemeter.CompareTo(null)); } + [Theory] + [InlineData(1, ReciprocalLengthUnit.InverseMeter, 1, ReciprocalLengthUnit.InverseMeter, true)] // Same value and unit. + [InlineData(1, ReciprocalLengthUnit.InverseMeter, 2, ReciprocalLengthUnit.InverseMeter, false)] // Different value. + [InlineData(2, ReciprocalLengthUnit.InverseMeter, 1, ReciprocalLengthUnit.InverseCentimeter, false)] // Different value and unit. + [InlineData(1, ReciprocalLengthUnit.InverseMeter, 1, ReciprocalLengthUnit.InverseCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ReciprocalLengthUnit unitA, double valueB, ReciprocalLengthUnit unitB, bool expectEqual) + { + var a = new ReciprocalLength(valueA, unitA); + var b = new ReciprocalLength(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ReciprocalLength.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs index e6aa601591..28419821d0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => percent.CompareTo(null)); } + [Theory] + [InlineData(1, RelativeHumidityUnit.Percent, 1, RelativeHumidityUnit.Percent, true)] // Same value and unit. + [InlineData(1, RelativeHumidityUnit.Percent, 2, RelativeHumidityUnit.Percent, false)] // Different value. + [InlineData(2, RelativeHumidityUnit.Percent, 1, RelativeHumidityUnit.Percent, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RelativeHumidityUnit unitA, double valueB, RelativeHumidityUnit unitB, bool expectEqual) + { + var a = new RelativeHumidity(valueA, unitA); + var b = new RelativeHumidity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RelativeHumidity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index 7a3c77030f..29e39f1b12 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -442,6 +442,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => radianpersecondsquared.CompareTo(null)); } + [Theory] + [InlineData(1, RotationalAccelerationUnit.RadianPerSecondSquared, 1, RotationalAccelerationUnit.RadianPerSecondSquared, true)] // Same value and unit. + [InlineData(1, RotationalAccelerationUnit.RadianPerSecondSquared, 2, RotationalAccelerationUnit.RadianPerSecondSquared, false)] // Different value. + [InlineData(2, RotationalAccelerationUnit.RadianPerSecondSquared, 1, RotationalAccelerationUnit.DegreePerSecondSquared, false)] // Different value and unit. + [InlineData(1, RotationalAccelerationUnit.RadianPerSecondSquared, 1, RotationalAccelerationUnit.DegreePerSecondSquared, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RotationalAccelerationUnit unitA, double valueB, RotationalAccelerationUnit unitB, bool expectEqual) + { + var a = new RotationalAcceleration(valueA, unitA); + var b = new RotationalAcceleration(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RotationalAcceleration.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index 0cc141e030..f1e5cd1ce9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -1165,6 +1165,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => radianpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, RotationalSpeedUnit.RadianPerSecond, 1, RotationalSpeedUnit.RadianPerSecond, true)] // Same value and unit. + [InlineData(1, RotationalSpeedUnit.RadianPerSecond, 2, RotationalSpeedUnit.RadianPerSecond, false)] // Different value. + [InlineData(2, RotationalSpeedUnit.RadianPerSecond, 1, RotationalSpeedUnit.CentiradianPerSecond, false)] // Different value and unit. + [InlineData(1, RotationalSpeedUnit.RadianPerSecond, 1, RotationalSpeedUnit.CentiradianPerSecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RotationalSpeedUnit unitA, double valueB, RotationalSpeedUnit unitB, bool expectEqual) + { + var a = new RotationalSpeed(valueA, unitA); + var b = new RotationalSpeed(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RotationalSpeed.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index 55d8548739..51aaf4ad4e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -645,6 +645,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonmeterperradianpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 1, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, true)] // Same value and unit. + [InlineData(1, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 2, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, false)] // Different value. + [InlineData(2, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 1, RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, false)] // Different value and unit. + [InlineData(1, RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, 1, RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RotationalStiffnessPerLengthUnit unitA, double valueB, RotationalStiffnessPerLengthUnit unitB, bool expectEqual) + { + var a = new RotationalStiffnessPerLength(valueA, unitA); + var b = new RotationalStiffnessPerLength(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RotationalStiffnessPerLength.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index 3d1daf3be4..419c109d57 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -2917,6 +2917,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonmeterperradian.CompareTo(null)); } + [Theory] + [InlineData(1, RotationalStiffnessUnit.NewtonMeterPerRadian, 1, RotationalStiffnessUnit.NewtonMeterPerRadian, true)] // Same value and unit. + [InlineData(1, RotationalStiffnessUnit.NewtonMeterPerRadian, 2, RotationalStiffnessUnit.NewtonMeterPerRadian, false)] // Different value. + [InlineData(2, RotationalStiffnessUnit.NewtonMeterPerRadian, 1, RotationalStiffnessUnit.CentinewtonMeterPerDegree, false)] // Different value and unit. + [InlineData(1, RotationalStiffnessUnit.NewtonMeterPerRadian, 1, RotationalStiffnessUnit.CentinewtonMeterPerDegree, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RotationalStiffnessUnit unitA, double valueB, RotationalStiffnessUnit unitB, bool expectEqual) + { + var a = new RotationalStiffness(valueA, unitA); + var b = new RotationalStiffness(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RotationalStiffness.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs index e921464326..a012816a0f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => amount.CompareTo(null)); } + [Theory] + [InlineData(1, ScalarUnit.Amount, 1, ScalarUnit.Amount, true)] // Same value and unit. + [InlineData(1, ScalarUnit.Amount, 2, ScalarUnit.Amount, false)] // Different value. + [InlineData(2, ScalarUnit.Amount, 1, ScalarUnit.Amount, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ScalarUnit unitA, double valueB, ScalarUnit unitB, bool expectEqual) + { + var a = new Scalar(valueA, unitA); + var b = new Scalar(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Scalar.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index 417daff6e3..212b54309f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => steradian.CompareTo(null)); } + [Theory] + [InlineData(1, SolidAngleUnit.Steradian, 1, SolidAngleUnit.Steradian, true)] // Same value and unit. + [InlineData(1, SolidAngleUnit.Steradian, 2, SolidAngleUnit.Steradian, false)] // Different value. + [InlineData(2, SolidAngleUnit.Steradian, 1, SolidAngleUnit.Steradian, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SolidAngleUnit unitA, double valueB, SolidAngleUnit unitB, bool expectEqual) + { + var a = new SolidAngle(valueA, unitA); + var b = new SolidAngle(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = SolidAngle.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index 9b9987c0e6..1715ced22a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -1293,6 +1293,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => jouleperkilogram.CompareTo(null)); } + [Theory] + [InlineData(1, SpecificEnergyUnit.JoulePerKilogram, 1, SpecificEnergyUnit.JoulePerKilogram, true)] // Same value and unit. + [InlineData(1, SpecificEnergyUnit.JoulePerKilogram, 2, SpecificEnergyUnit.JoulePerKilogram, false)] // Different value. + [InlineData(2, SpecificEnergyUnit.JoulePerKilogram, 1, SpecificEnergyUnit.BtuPerPound, false)] // Different value and unit. + [InlineData(1, SpecificEnergyUnit.JoulePerKilogram, 1, SpecificEnergyUnit.BtuPerPound, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SpecificEnergyUnit unitA, double valueB, SpecificEnergyUnit unitB, bool expectEqual) + { + var a = new SpecificEnergy(valueA, unitA); + var b = new SpecificEnergy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = SpecificEnergy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index a01c658cec..a44601541d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -617,6 +617,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => jouleperkilogramkelvin.CompareTo(null)); } + [Theory] + [InlineData(1, SpecificEntropyUnit.JoulePerKilogramKelvin, 1, SpecificEntropyUnit.JoulePerKilogramKelvin, true)] // Same value and unit. + [InlineData(1, SpecificEntropyUnit.JoulePerKilogramKelvin, 2, SpecificEntropyUnit.JoulePerKilogramKelvin, false)] // Different value. + [InlineData(2, SpecificEntropyUnit.JoulePerKilogramKelvin, 1, SpecificEntropyUnit.BtuPerPoundFahrenheit, false)] // Different value and unit. + [InlineData(1, SpecificEntropyUnit.JoulePerKilogramKelvin, 1, SpecificEntropyUnit.BtuPerPoundFahrenheit, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SpecificEntropyUnit unitA, double valueB, SpecificEntropyUnit unitB, bool expectEqual) + { + var a = new SpecificEntropy(valueA, unitA); + var b = new SpecificEntropy(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = SpecificEntropy.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs index ece7c532e8..d7238c98c3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => gramperkilonewtonsecond.CompareTo(null)); } + [Theory] + [InlineData(1, SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, 1, SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, true)] // Same value and unit. + [InlineData(1, SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, 2, SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, false)] // Different value. + [InlineData(2, SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, 1, SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, false)] // Different value and unit. + [InlineData(1, SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, 1, SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SpecificFuelConsumptionUnit unitA, double valueB, SpecificFuelConsumptionUnit unitB, bool expectEqual) + { + var a = new SpecificFuelConsumption(valueA, unitA); + var b = new SpecificFuelConsumption(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = SpecificFuelConsumption.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 9ed64f53b2..57270eb380 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -383,6 +383,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => cubicmeterperkilogram.CompareTo(null)); } + [Theory] + [InlineData(1, SpecificVolumeUnit.CubicMeterPerKilogram, 1, SpecificVolumeUnit.CubicMeterPerKilogram, true)] // Same value and unit. + [InlineData(1, SpecificVolumeUnit.CubicMeterPerKilogram, 2, SpecificVolumeUnit.CubicMeterPerKilogram, false)] // Different value. + [InlineData(2, SpecificVolumeUnit.CubicMeterPerKilogram, 1, SpecificVolumeUnit.CubicFootPerPound, false)] // Different value and unit. + [InlineData(1, SpecificVolumeUnit.CubicMeterPerKilogram, 1, SpecificVolumeUnit.CubicFootPerPound, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SpecificVolumeUnit unitA, double valueB, SpecificVolumeUnit unitB, bool expectEqual) + { + var a = new SpecificVolume(valueA, unitA); + var b = new SpecificVolume(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = SpecificVolume.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index c74da17c14..d917bee5c2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -873,6 +873,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonpercubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, SpecificWeightUnit.NewtonPerCubicMeter, 1, SpecificWeightUnit.NewtonPerCubicMeter, true)] // Same value and unit. + [InlineData(1, SpecificWeightUnit.NewtonPerCubicMeter, 2, SpecificWeightUnit.NewtonPerCubicMeter, false)] // Different value. + [InlineData(2, SpecificWeightUnit.NewtonPerCubicMeter, 1, SpecificWeightUnit.KilogramForcePerCubicCentimeter, false)] // Different value and unit. + [InlineData(1, SpecificWeightUnit.NewtonPerCubicMeter, 1, SpecificWeightUnit.KilogramForcePerCubicCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SpecificWeightUnit unitA, double valueB, SpecificWeightUnit unitB, bool expectEqual) + { + var a = new SpecificWeight(valueA, unitA); + var b = new SpecificWeight(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = SpecificWeight.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index 8baea9ee09..b71050cc7f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -2153,6 +2153,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => meterpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, SpeedUnit.MeterPerSecond, 1, SpeedUnit.MeterPerSecond, true)] // Same value and unit. + [InlineData(1, SpeedUnit.MeterPerSecond, 2, SpeedUnit.MeterPerSecond, false)] // Different value. + [InlineData(2, SpeedUnit.MeterPerSecond, 1, SpeedUnit.CentimeterPerHour, false)] // Different value and unit. + [InlineData(1, SpeedUnit.MeterPerSecond, 1, SpeedUnit.CentimeterPerHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, SpeedUnit unitA, double valueB, SpeedUnit unitB, bool expectEqual) + { + var a = new Speed(valueA, unitA); + var b = new Speed(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Speed.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs index 86bf65404c..7d51646626 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs @@ -593,6 +593,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => standardcubicmeterpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, StandardVolumeFlowUnit.StandardCubicMeterPerSecond, 1, StandardVolumeFlowUnit.StandardCubicMeterPerSecond, true)] // Same value and unit. + [InlineData(1, StandardVolumeFlowUnit.StandardCubicMeterPerSecond, 2, StandardVolumeFlowUnit.StandardCubicMeterPerSecond, false)] // Different value. + [InlineData(2, StandardVolumeFlowUnit.StandardCubicMeterPerSecond, 1, StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, false)] // Different value and unit. + [InlineData(1, StandardVolumeFlowUnit.StandardCubicMeterPerSecond, 1, StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, StandardVolumeFlowUnit unitA, double valueB, StandardVolumeFlowUnit unitB, bool expectEqual) + { + var a = new StandardVolumeFlow(valueA, unitA); + var b = new StandardVolumeFlow(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = StandardVolumeFlow.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index e40c502e76..75c8ba9ad5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -628,6 +628,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => degreecelsiuspersecond.CompareTo(null)); } + [Theory] + [InlineData(1, TemperatureChangeRateUnit.DegreeCelsiusPerSecond, 1, TemperatureChangeRateUnit.DegreeCelsiusPerSecond, true)] // Same value and unit. + [InlineData(1, TemperatureChangeRateUnit.DegreeCelsiusPerSecond, 2, TemperatureChangeRateUnit.DegreeCelsiusPerSecond, false)] // Different value. + [InlineData(2, TemperatureChangeRateUnit.DegreeCelsiusPerSecond, 1, TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, false)] // Different value and unit. + [InlineData(1, TemperatureChangeRateUnit.DegreeCelsiusPerSecond, 1, TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TemperatureChangeRateUnit unitA, double valueB, TemperatureChangeRateUnit unitB, bool expectEqual) + { + var a = new TemperatureChangeRate(valueA, unitA); + var b = new TemperatureChangeRate(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = TemperatureChangeRate.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index 872d646a91..7194acfbec 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -593,6 +593,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kelvin.CompareTo(null)); } + [Theory] + [InlineData(1, TemperatureDeltaUnit.Kelvin, 1, TemperatureDeltaUnit.Kelvin, true)] // Same value and unit. + [InlineData(1, TemperatureDeltaUnit.Kelvin, 2, TemperatureDeltaUnit.Kelvin, false)] // Different value. + [InlineData(2, TemperatureDeltaUnit.Kelvin, 1, TemperatureDeltaUnit.DegreeCelsius, false)] // Different value and unit. + [InlineData(1, TemperatureDeltaUnit.Kelvin, 1, TemperatureDeltaUnit.DegreeCelsius, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TemperatureDeltaUnit unitA, double valueB, TemperatureDeltaUnit unitB, bool expectEqual) + { + var a = new TemperatureDelta(valueA, unitA); + var b = new TemperatureDelta(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = TemperatureDelta.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs index e560df6b3c..38aeb5d4e4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs @@ -418,6 +418,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kelvinpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, TemperatureGradientUnit.KelvinPerMeter, 1, TemperatureGradientUnit.KelvinPerMeter, true)] // Same value and unit. + [InlineData(1, TemperatureGradientUnit.KelvinPerMeter, 2, TemperatureGradientUnit.KelvinPerMeter, false)] // Different value. + [InlineData(2, TemperatureGradientUnit.KelvinPerMeter, 1, TemperatureGradientUnit.DegreeCelsiusPerKilometer, false)] // Different value and unit. + [InlineData(1, TemperatureGradientUnit.KelvinPerMeter, 1, TemperatureGradientUnit.DegreeCelsiusPerKilometer, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TemperatureGradientUnit unitA, double valueB, TemperatureGradientUnit unitB, bool expectEqual) + { + var a = new TemperatureGradient(valueA, unitA); + var b = new TemperatureGradient(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = TemperatureGradient.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index bbdf042097..b706d8f6bf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -616,6 +616,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => kelvin.CompareTo(null)); } + [Theory] + [InlineData(1, TemperatureUnit.Kelvin, 1, TemperatureUnit.Kelvin, true)] // Same value and unit. + [InlineData(1, TemperatureUnit.Kelvin, 2, TemperatureUnit.Kelvin, false)] // Different value. + [InlineData(2, TemperatureUnit.Kelvin, 1, TemperatureUnit.DegreeCelsius, false)] // Different value and unit. + [InlineData(1, TemperatureUnit.Kelvin, 1, TemperatureUnit.DegreeCelsius, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TemperatureUnit unitA, double valueB, TemperatureUnit unitB, bool expectEqual) + { + var a = new Temperature(valueA, unitA); + var b = new Temperature(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Temperature.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index 27f9980e7c..3b2d58bbf2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -348,6 +348,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => wattpermeterkelvin.CompareTo(null)); } + [Theory] + [InlineData(1, ThermalConductivityUnit.WattPerMeterKelvin, 1, ThermalConductivityUnit.WattPerMeterKelvin, true)] // Same value and unit. + [InlineData(1, ThermalConductivityUnit.WattPerMeterKelvin, 2, ThermalConductivityUnit.WattPerMeterKelvin, false)] // Different value. + [InlineData(2, ThermalConductivityUnit.WattPerMeterKelvin, 1, ThermalConductivityUnit.BtuPerHourFootFahrenheit, false)] // Different value and unit. + [InlineData(1, ThermalConductivityUnit.WattPerMeterKelvin, 1, ThermalConductivityUnit.BtuPerHourFootFahrenheit, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ThermalConductivityUnit unitA, double valueB, ThermalConductivityUnit unitB, bool expectEqual) + { + var a = new ThermalConductivity(valueA, unitA); + var b = new ThermalConductivity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ThermalConductivity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs index 5a9a9f6934..fa54803112 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalResistanceTestsBase.g.cs @@ -488,6 +488,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => squaremeterkelvinperkilowatt.CompareTo(null)); } + [Theory] + [InlineData(1, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, 1, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, true)] // Same value and unit. + [InlineData(1, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, 2, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, false)] // Different value. + [InlineData(2, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, 1, ThermalResistanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, false)] // Different value and unit. + [InlineData(1, ThermalResistanceUnit.SquareMeterKelvinPerKilowatt, 1, ThermalResistanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ThermalResistanceUnit unitA, double valueB, ThermalResistanceUnit unitB, bool expectEqual) + { + var a = new ThermalResistance(valueA, unitA); + var b = new ThermalResistance(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = ThermalResistance.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs index 6561c41e5f..ca45b092cd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorquePerLengthTestsBase.g.cs @@ -1085,6 +1085,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonmeterpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, TorquePerLengthUnit.NewtonMeterPerMeter, 1, TorquePerLengthUnit.NewtonMeterPerMeter, true)] // Same value and unit. + [InlineData(1, TorquePerLengthUnit.NewtonMeterPerMeter, 2, TorquePerLengthUnit.NewtonMeterPerMeter, false)] // Different value. + [InlineData(2, TorquePerLengthUnit.NewtonMeterPerMeter, 1, TorquePerLengthUnit.KilogramForceCentimeterPerMeter, false)] // Different value and unit. + [InlineData(1, TorquePerLengthUnit.NewtonMeterPerMeter, 1, TorquePerLengthUnit.KilogramForceCentimeterPerMeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TorquePerLengthUnit unitA, double valueB, TorquePerLengthUnit unitB, bool expectEqual) + { + var a = new TorquePerLength(valueA, unitA); + var b = new TorquePerLength(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = TorquePerLength.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index ba996fb144..2518da77a0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -1225,6 +1225,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => newtonmeter.CompareTo(null)); } + [Theory] + [InlineData(1, TorqueUnit.NewtonMeter, 1, TorqueUnit.NewtonMeter, true)] // Same value and unit. + [InlineData(1, TorqueUnit.NewtonMeter, 2, TorqueUnit.NewtonMeter, false)] // Different value. + [InlineData(2, TorqueUnit.NewtonMeter, 1, TorqueUnit.GramForceCentimeter, false)] // Different value and unit. + [InlineData(1, TorqueUnit.NewtonMeter, 1, TorqueUnit.GramForceCentimeter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TorqueUnit unitA, double valueB, TorqueUnit unitB, bool expectEqual) + { + var a = new Torque(valueA, unitA); + var b = new Torque(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Torque.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index 1810b75cef..85e81be46b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => ntu.CompareTo(null)); } + [Theory] + [InlineData(1, TurbidityUnit.NTU, 1, TurbidityUnit.NTU, true)] // Same value and unit. + [InlineData(1, TurbidityUnit.NTU, 2, TurbidityUnit.NTU, false)] // Different value. + [InlineData(2, TurbidityUnit.NTU, 1, TurbidityUnit.NTU, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, TurbidityUnit unitA, double valueB, TurbidityUnit unitB, bool expectEqual) + { + var a = new Turbidity(valueA, unitA); + var b = new Turbidity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Turbidity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index 5f592b4a7b..9888fa37c3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -313,6 +313,46 @@ public void CompareToThrowsOnNull() Assert.Throws(() => internationalunit.CompareTo(null)); } + [Theory] + [InlineData(1, VitaminAUnit.InternationalUnit, 1, VitaminAUnit.InternationalUnit, true)] // Same value and unit. + [InlineData(1, VitaminAUnit.InternationalUnit, 2, VitaminAUnit.InternationalUnit, false)] // Different value. + [InlineData(2, VitaminAUnit.InternationalUnit, 1, VitaminAUnit.InternationalUnit, false)] // Different value and unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VitaminAUnit unitA, double valueB, VitaminAUnit unitB, bool expectEqual) + { + var a = new VitaminA(valueA, unitA); + var b = new VitaminA(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = VitaminA.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index fa7daa6e0d..ee2ff359cf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -1002,6 +1002,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => decimalfraction.CompareTo(null)); } + [Theory] + [InlineData(1, VolumeConcentrationUnit.DecimalFraction, 1, VolumeConcentrationUnit.DecimalFraction, true)] // Same value and unit. + [InlineData(1, VolumeConcentrationUnit.DecimalFraction, 2, VolumeConcentrationUnit.DecimalFraction, false)] // Different value. + [InlineData(2, VolumeConcentrationUnit.DecimalFraction, 1, VolumeConcentrationUnit.CentilitersPerLiter, false)] // Different value and unit. + [InlineData(1, VolumeConcentrationUnit.DecimalFraction, 1, VolumeConcentrationUnit.CentilitersPerLiter, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VolumeConcentrationUnit unitA, double valueB, VolumeConcentrationUnit unitB, bool expectEqual) + { + var a = new VolumeConcentration(valueA, unitA); + var b = new VolumeConcentration(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = VolumeConcentration.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs index b39f7a1fb4..1a403dc603 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs @@ -348,6 +348,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => cubicmeterpersecondpersquaremeter.CompareTo(null)); } + [Theory] + [InlineData(1, VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, 1, VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, true)] // Same value and unit. + [InlineData(1, VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, 2, VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, false)] // Different value. + [InlineData(2, VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, 1, VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, false)] // Different value and unit. + [InlineData(1, VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, 1, VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VolumeFlowPerAreaUnit unitA, double valueB, VolumeFlowPerAreaUnit unitB, bool expectEqual) + { + var a = new VolumeFlowPerArea(valueA, unitA); + var b = new VolumeFlowPerArea(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = VolumeFlowPerArea.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index 3730bfc089..1dbbb861ef 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -4110,6 +4110,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => cubicmeterpersecond.CompareTo(null)); } + [Theory] + [InlineData(1, VolumeFlowUnit.CubicMeterPerSecond, 1, VolumeFlowUnit.CubicMeterPerSecond, true)] // Same value and unit. + [InlineData(1, VolumeFlowUnit.CubicMeterPerSecond, 2, VolumeFlowUnit.CubicMeterPerSecond, false)] // Different value. + [InlineData(2, VolumeFlowUnit.CubicMeterPerSecond, 1, VolumeFlowUnit.AcreFootPerDay, false)] // Different value and unit. + [InlineData(1, VolumeFlowUnit.CubicMeterPerSecond, 1, VolumeFlowUnit.AcreFootPerDay, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VolumeFlowUnit unitA, double valueB, VolumeFlowUnit unitB, bool expectEqual) + { + var a = new VolumeFlow(valueA, unitA); + var b = new VolumeFlow(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = VolumeFlow.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index e436c7baef..6880712263 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -523,6 +523,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => cubicmeterpermeter.CompareTo(null)); } + [Theory] + [InlineData(1, VolumePerLengthUnit.CubicMeterPerMeter, 1, VolumePerLengthUnit.CubicMeterPerMeter, true)] // Same value and unit. + [InlineData(1, VolumePerLengthUnit.CubicMeterPerMeter, 2, VolumePerLengthUnit.CubicMeterPerMeter, false)] // Different value. + [InlineData(2, VolumePerLengthUnit.CubicMeterPerMeter, 1, VolumePerLengthUnit.CubicYardPerFoot, false)] // Different value and unit. + [InlineData(1, VolumePerLengthUnit.CubicMeterPerMeter, 1, VolumePerLengthUnit.CubicYardPerFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VolumePerLengthUnit unitA, double valueB, VolumePerLengthUnit unitB, bool expectEqual) + { + var a = new VolumePerLength(valueA, unitA); + var b = new VolumePerLength(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = VolumePerLength.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index e1baf572b9..1cc0c942e3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -3094,6 +3094,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => cubicmeter.CompareTo(null)); } + [Theory] + [InlineData(1, VolumeUnit.CubicMeter, 1, VolumeUnit.CubicMeter, true)] // Same value and unit. + [InlineData(1, VolumeUnit.CubicMeter, 2, VolumeUnit.CubicMeter, false)] // Different value. + [InlineData(2, VolumeUnit.CubicMeter, 1, VolumeUnit.AcreFoot, false)] // Different value and unit. + [InlineData(1, VolumeUnit.CubicMeter, 1, VolumeUnit.AcreFoot, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VolumeUnit unitA, double valueB, VolumeUnit unitB, bool expectEqual) + { + var a = new Volume(valueA, unitA); + var b = new Volume(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = Volume.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs index 25ee9d7cc0..2f193bf140 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs @@ -593,6 +593,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => joulepercubicmeterkelvin.CompareTo(null)); } + [Theory] + [InlineData(1, VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, 1, VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, true)] // Same value and unit. + [InlineData(1, VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, 2, VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, false)] // Different value. + [InlineData(2, VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, 1, VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, false)] // Different value and unit. + [InlineData(1, VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, 1, VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, VolumetricHeatCapacityUnit unitA, double valueB, VolumetricHeatCapacityUnit unitB, bool expectEqual) + { + var a = new VolumetricHeatCapacity(valueA, unitA); + var b = new VolumetricHeatCapacity(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = VolumetricHeatCapacity.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index 891229efd6..2a8bf2e01c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -632,6 +632,47 @@ public void CompareToThrowsOnNull() Assert.Throws(() => metertothesixth.CompareTo(null)); } + [Theory] + [InlineData(1, WarpingMomentOfInertiaUnit.MeterToTheSixth, 1, WarpingMomentOfInertiaUnit.MeterToTheSixth, true)] // Same value and unit. + [InlineData(1, WarpingMomentOfInertiaUnit.MeterToTheSixth, 2, WarpingMomentOfInertiaUnit.MeterToTheSixth, false)] // Different value. + [InlineData(2, WarpingMomentOfInertiaUnit.MeterToTheSixth, 1, WarpingMomentOfInertiaUnit.CentimeterToTheSixth, false)] // Different value and unit. + [InlineData(1, WarpingMomentOfInertiaUnit.MeterToTheSixth, 1, WarpingMomentOfInertiaUnit.CentimeterToTheSixth, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, WarpingMomentOfInertiaUnit unitA, double valueB, WarpingMomentOfInertiaUnit unitB, bool expectEqual) + { + var a = new WarpingMomentOfInertia(valueA, unitA); + var b = new WarpingMomentOfInertia(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = WarpingMomentOfInertia.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + [Fact] public void Equals_RelativeTolerance_IsImplemented() { diff --git a/UnitsNet.Tests/UnitsNet.Tests.csproj b/UnitsNet.Tests/UnitsNet.Tests.csproj index bad664ac01..c39367da2b 100644 --- a/UnitsNet.Tests/UnitsNet.Tests.csproj +++ b/UnitsNet.Tests/UnitsNet.Tests.csproj @@ -5,6 +5,7 @@ UnitsNet.Tests latest true + CS0618 diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 576f94fc12..6f46045043 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Acceleration, in physics, is the rate at which the velocity of an object changes over time. An object's acceleration is the net result of any and all forces acting on the object, as described by Newton's Second Law. The SI unit for acceleration is the Meter per second squared (m/s²). Accelerations are vector quantities (they have magnitude and direction) and add according to the parallelogram law. As a vector, the calculated net force is equal to the product of the object's mass (a scalar quantity) and the acceleration. /// [DataContract] - public readonly partial struct Acceleration : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Acceleration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -712,16 +712,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Accel return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Acceleration left, Acceleration right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Acceleration otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Acceleration other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Acceleration objAcceleration)) throw new ArgumentException("Expected type Acceleration.", nameof(obj)); + if (!(obj is Acceleration otherQuantity)) throw new ArgumentException("Expected type Acceleration.", nameof(obj)); - return CompareTo(objAcceleration); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Acceleration other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -760,7 +824,7 @@ public int CompareTo(Acceleration other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -917,7 +981,7 @@ private bool TryToUnit(AccelerationUnit unit, out Acceleration? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs index 76e9593fda..872a8d9f7b 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Mole is the amount of substance containing Avagadro's Number (6.02 x 10 ^ 23) of real particles such as molecules,atoms, ions or radicals. /// [DataContract] - public readonly partial struct AmountOfSubstance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct AmountOfSubstance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -717,16 +717,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Amoun return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(AmountOfSubstance left, AmountOfSubstance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is AmountOfSubstance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(AmountOfSubstance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is AmountOfSubstance objAmountOfSubstance)) throw new ArgumentException("Expected type AmountOfSubstance.", nameof(obj)); + if (!(obj is AmountOfSubstance otherQuantity)) throw new ArgumentException("Expected type AmountOfSubstance.", nameof(obj)); - return CompareTo(objAmountOfSubstance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(AmountOfSubstance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -765,7 +829,7 @@ public int CompareTo(AmountOfSubstance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -924,7 +988,7 @@ private bool TryToUnit(AmountOfSubstanceUnit unit, out AmountOfSubstance? conver _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs index 74da1a5124..921ee0f215 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The strength of a signal expressed in decibels (dB) relative to one volt RMS. /// [DataContract] - public readonly partial struct AmplitudeRatio : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct AmplitudeRatio : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -516,16 +516,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ampli return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(AmplitudeRatio left, AmplitudeRatio right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is AmplitudeRatio otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(AmplitudeRatio other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is AmplitudeRatio objAmplitudeRatio)) throw new ArgumentException("Expected type AmplitudeRatio.", nameof(obj)); + if (!(obj is AmplitudeRatio otherQuantity)) throw new ArgumentException("Expected type AmplitudeRatio.", nameof(obj)); - return CompareTo(objAmplitudeRatio); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(AmplitudeRatio other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -564,7 +628,7 @@ public int CompareTo(AmplitudeRatio other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -701,7 +765,7 @@ private bool TryToUnit(AmplitudeRatioUnit unit, out AmplitudeRatio? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index 9079e5dd85..8ae2c7efc3 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In geometry, an angle is the figure formed by two rays, called the sides of the angle, sharing a common endpoint, called the vertex of the angle. /// [DataContract] - public readonly partial struct Angle : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Angle : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -748,16 +748,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Angle return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Angle left, Angle right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Angle otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Angle other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Angle objAngle)) throw new ArgumentException("Expected type Angle.", nameof(obj)); + if (!(obj is Angle otherQuantity)) throw new ArgumentException("Expected type Angle.", nameof(obj)); - return CompareTo(objAngle); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Angle other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -796,7 +860,7 @@ public int CompareTo(Angle other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -957,7 +1021,7 @@ private bool TryToUnit(AngleUnit unit, out Angle? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs index 4106feda46..bb8384a01c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A unit for expressing the integral of apparent power over time, equal to the product of 1 volt-ampere and 1 hour, or to 3600 joules. /// [DataContract] - public readonly partial struct ApparentEnergy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ApparentEnergy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Appar return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ApparentEnergy left, ApparentEnergy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ApparentEnergy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ApparentEnergy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ApparentEnergy objApparentEnergy)) throw new ArgumentException("Expected type ApparentEnergy.", nameof(obj)); + if (!(obj is ApparentEnergy otherQuantity)) throw new ArgumentException("Expected type ApparentEnergy.", nameof(obj)); - return CompareTo(objApparentEnergy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ApparentEnergy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(ApparentEnergy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(ApparentEnergyUnit unit, out ApparentEnergy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs index 2235f17459..0699cf9e05 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. Apparent power is the product of the root-mean-square of voltage and current. /// [DataContract] - public readonly partial struct ApparentPower : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ApparentPower : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -508,16 +508,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Appar return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ApparentPower left, ApparentPower right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ApparentPower otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ApparentPower other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ApparentPower objApparentPower)) throw new ArgumentException("Expected type ApparentPower.", nameof(obj)); + if (!(obj is ApparentPower otherQuantity)) throw new ArgumentException("Expected type ApparentPower.", nameof(obj)); - return CompareTo(objApparentPower); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ApparentPower other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -556,7 +620,7 @@ public int CompareTo(ApparentPower other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -693,7 +757,7 @@ private bool TryToUnit(ApparentPowerUnit unit, out ApparentPower? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index c418b69571..7abecbe02b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Area is a quantity that expresses the extent of a two-dimensional surface or shape, or planar lamina, in the plane. Area can be understood as the amount of material with a given thickness that would be necessary to fashion a model of the shape, or the amount of paint necessary to cover the surface with a single coat.[1] It is the two-dimensional analog of the length of a curve (a one-dimensional concept) or the volume of a solid (a three-dimensional concept). /// [DataContract] - public readonly partial struct Area : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Area : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -725,16 +725,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaU return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Area left, Area right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Area otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Area other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Area objArea)) throw new ArgumentException("Expected type Area.", nameof(obj)); + if (!(obj is Area otherQuantity)) throw new ArgumentException("Expected type Area.", nameof(obj)); - return CompareTo(objArea); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Area other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -773,7 +837,7 @@ public int CompareTo(Area other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -930,7 +994,7 @@ private bool TryToUnit(AreaUnit unit, out Area? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs index 48b6364f2f..e18754d2f1 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The area density of a two-dimensional object is calculated as the mass per unit area. For paper this is also called grammage. /// [DataContract] - public readonly partial struct AreaDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct AreaDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaD return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(AreaDensity left, AreaDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is AreaDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(AreaDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is AreaDensity objAreaDensity)) throw new ArgumentException("Expected type AreaDensity.", nameof(obj)); + if (!(obj is AreaDensity otherQuantity)) throw new ArgumentException("Expected type AreaDensity.", nameof(obj)); - return CompareTo(objAreaDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(AreaDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(AreaDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(AreaDensityUnit unit, out AreaDensity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs index f7900819fc..3ed484bee5 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A geometric property of an area that reflects how its points are distributed with regard to an axis. /// [DataContract] - public readonly partial struct AreaMomentOfInertia : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct AreaMomentOfInertia : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -546,16 +546,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out AreaM return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(AreaMomentOfInertia left, AreaMomentOfInertia right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is AreaMomentOfInertia otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(AreaMomentOfInertia other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is AreaMomentOfInertia objAreaMomentOfInertia)) throw new ArgumentException("Expected type AreaMomentOfInertia.", nameof(obj)); + if (!(obj is AreaMomentOfInertia otherQuantity)) throw new ArgumentException("Expected type AreaMomentOfInertia.", nameof(obj)); - return CompareTo(objAreaMomentOfInertia); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(AreaMomentOfInertia other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -594,7 +658,7 @@ public int CompareTo(AreaMomentOfInertia other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -735,7 +799,7 @@ private bool TryToUnit(AreaMomentOfInertiaUnit unit, out AreaMomentOfInertia? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs index 5eb7072ec3..dcb500d79d 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Bit_rate /// [DataContract] - public readonly partial struct BitRate : IQuantity, IDecimalQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct BitRate : IQuantity, IDecimalQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -932,16 +932,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out BitRa return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(BitRate left, BitRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is BitRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public bool Equals(BitRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is BitRate objBitRate)) throw new ArgumentException("Expected type BitRate.", nameof(obj)); + if (!(obj is BitRate otherQuantity)) throw new ArgumentException("Expected type BitRate.", nameof(obj)); - return CompareTo(objBitRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(BitRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -980,7 +1044,7 @@ public int CompareTo(BitRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using decimal internally. /// /// /// The other quantity to compare to. @@ -1172,7 +1236,7 @@ private bool TryToUnit(BitRateUnit unit, out BitRate? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs index e62ed04a01..a27f3ac938 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Brake specific fuel consumption (BSFC) is a measure of the fuel efficiency of any prime mover that burns fuel and produces rotational, or shaft, power. It is typically used for comparing the efficiency of internal combustion engines with a shaft output. /// [DataContract] - public readonly partial struct BrakeSpecificFuelConsumption : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct BrakeSpecificFuelConsumption : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Brake return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(BrakeSpecificFuelConsumption left, BrakeSpecificFuelConsumption right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is BrakeSpecificFuelConsumption otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(BrakeSpecificFuelConsumption other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is BrakeSpecificFuelConsumption objBrakeSpecificFuelConsumption)) throw new ArgumentException("Expected type BrakeSpecificFuelConsumption.", nameof(obj)); + if (!(obj is BrakeSpecificFuelConsumption otherQuantity)) throw new ArgumentException("Expected type BrakeSpecificFuelConsumption.", nameof(obj)); - return CompareTo(objBrakeSpecificFuelConsumption); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(BrakeSpecificFuelConsumption other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(BrakeSpecificFuelConsumption other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(BrakeSpecificFuelConsumptionUnit unit, out BrakeSpecificF _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs index cc5c707328..c835cd11af 100644 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Capacitance /// [DataContract] - public readonly partial struct Capacitance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Capacitance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -568,16 +568,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Capac return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Capacitance left, Capacitance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Capacitance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Capacitance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Capacitance objCapacitance)) throw new ArgumentException("Expected type Capacitance.", nameof(obj)); + if (!(obj is Capacitance otherQuantity)) throw new ArgumentException("Expected type Capacitance.", nameof(obj)); - return CompareTo(objCapacitance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Capacitance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -616,7 +680,7 @@ public int CompareTo(Capacitance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -759,7 +823,7 @@ private bool TryToUnit(CapacitanceUnit unit, out Capacitance? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs index aec2f603df..b74d70e9bb 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A unit that represents a fractional change in size in response to a change in temperature. /// [DataContract] - public readonly partial struct CoefficientOfThermalExpansion : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct CoefficientOfThermalExpansion : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Coeff return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(CoefficientOfThermalExpansion left, CoefficientOfThermalExpansion right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is CoefficientOfThermalExpansion otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(CoefficientOfThermalExpansion other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is CoefficientOfThermalExpansion objCoefficientOfThermalExpansion)) throw new ArgumentException("Expected type CoefficientOfThermalExpansion.", nameof(obj)); + if (!(obj is CoefficientOfThermalExpansion otherQuantity)) throw new ArgumentException("Expected type CoefficientOfThermalExpansion.", nameof(obj)); - return CompareTo(objCoefficientOfThermalExpansion); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(CoefficientOfThermalExpansion other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(CoefficientOfThermalExpansion other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(CoefficientOfThermalExpansionUnit unit, out CoefficientOf _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs index 2124d195a9..7b36103334 100644 --- a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// /// [DataContract] - public readonly partial struct Compressibility : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Compressibility : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -565,16 +565,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Compr return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Compressibility left, Compressibility right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Compressibility otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Compressibility other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Compressibility objCompressibility)) throw new ArgumentException("Expected type Compressibility.", nameof(obj)); + if (!(obj is Compressibility otherQuantity)) throw new ArgumentException("Expected type Compressibility.", nameof(obj)); - return CompareTo(objCompressibility); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Compressibility other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -613,7 +677,7 @@ public int CompareTo(Compressibility other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -756,7 +820,7 @@ private bool TryToUnit(CompressibilityUnit unit, out Compressibility? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs index f8e69b636d..4173fdfbf9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// http://en.wikipedia.org/wiki/Density /// [DataContract] - public readonly partial struct Density : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Density : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1408,16 +1408,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Densi return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Density left, Density right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Density otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Density other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Density objDensity)) throw new ArgumentException("Expected type Density.", nameof(obj)); + if (!(obj is Density otherQuantity)) throw new ArgumentException("Expected type Density.", nameof(obj)); - return CompareTo(objDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Density other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1456,7 +1520,7 @@ public int CompareTo(Density other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1687,7 +1751,7 @@ private bool TryToUnit(DensityUnit unit, out Density? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs index 8fe54fb0d9..6a9c10da47 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Time is a dimension in which events can be ordered from the past through the present into the future, and also the measure of durations of events and the intervals between them. /// [DataContract] - public readonly partial struct Duration : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Duration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -651,16 +651,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Durat return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Duration left, Duration right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Duration otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Duration other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Duration objDuration)) throw new ArgumentException("Expected type Duration.", nameof(obj)); + if (!(obj is Duration otherQuantity)) throw new ArgumentException("Expected type Duration.", nameof(obj)); - return CompareTo(objDuration); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Duration other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -699,7 +763,7 @@ public int CompareTo(Duration other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -850,7 +914,7 @@ private bool TryToUnit(DurationUnit unit, out Duration? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs index c402327701..a85cde6033 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Viscosity#Dynamic_.28shear.29_viscosity /// [DataContract] - public readonly partial struct DynamicViscosity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct DynamicViscosity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -625,16 +625,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Dynam return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(DynamicViscosity left, DynamicViscosity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is DynamicViscosity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(DynamicViscosity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is DynamicViscosity objDynamicViscosity)) throw new ArgumentException("Expected type DynamicViscosity.", nameof(obj)); + if (!(obj is DynamicViscosity otherQuantity)) throw new ArgumentException("Expected type DynamicViscosity.", nameof(obj)); - return CompareTo(objDynamicViscosity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(DynamicViscosity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -673,7 +737,7 @@ public int CompareTo(DynamicViscosity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -822,7 +886,7 @@ private bool TryToUnit(DynamicViscosityUnit unit, out DynamicViscosity? converte _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs index 702e7d9b4d..3b95388c54 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Electric admittance is a measure of how easily a circuit or device will allow a current to flow. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S). /// [DataContract] - public readonly partial struct ElectricAdmittance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricAdmittance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -508,16 +508,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricAdmittance left, ElectricAdmittance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricAdmittance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricAdmittance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricAdmittance objElectricAdmittance)) throw new ArgumentException("Expected type ElectricAdmittance.", nameof(obj)); + if (!(obj is ElectricAdmittance otherQuantity)) throw new ArgumentException("Expected type ElectricAdmittance.", nameof(obj)); - return CompareTo(objElectricAdmittance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricAdmittance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -556,7 +620,7 @@ public int CompareTo(ElectricAdmittance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -693,7 +757,7 @@ private bool TryToUnit(ElectricAdmittanceUnit unit, out ElectricAdmittance? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs index ec762d9d56..43ab7dfe29 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Electric_charge /// [DataContract] - public readonly partial struct ElectricCharge : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricCharge : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -530,16 +530,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricCharge left, ElectricCharge right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricCharge otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricCharge other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricCharge objElectricCharge)) throw new ArgumentException("Expected type ElectricCharge.", nameof(obj)); + if (!(obj is ElectricCharge otherQuantity)) throw new ArgumentException("Expected type ElectricCharge.", nameof(obj)); - return CompareTo(objElectricCharge); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricCharge other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -578,7 +642,7 @@ public int CompareTo(ElectricCharge other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -717,7 +781,7 @@ private bool TryToUnit(ElectricChargeUnit unit, out ElectricCharge? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs index b9964274b8..e005500e9d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Charge_density /// [DataContract] - public readonly partial struct ElectricChargeDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricChargeDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricChargeDensity left, ElectricChargeDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricChargeDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricChargeDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricChargeDensity objElectricChargeDensity)) throw new ArgumentException("Expected type ElectricChargeDensity.", nameof(obj)); + if (!(obj is ElectricChargeDensity otherQuantity)) throw new ArgumentException("Expected type ElectricChargeDensity.", nameof(obj)); - return CompareTo(objElectricChargeDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricChargeDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(ElectricChargeDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(ElectricChargeDensityUnit unit, out ElectricChargeDensity _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs index 5c1e46b7f9..d58c0a5081 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance /// [DataContract] - public readonly partial struct ElectricConductance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricConductance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -492,16 +492,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricConductance left, ElectricConductance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricConductance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricConductance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricConductance objElectricConductance)) throw new ArgumentException("Expected type ElectricConductance.", nameof(obj)); + if (!(obj is ElectricConductance otherQuantity)) throw new ArgumentException("Expected type ElectricConductance.", nameof(obj)); - return CompareTo(objElectricConductance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricConductance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -540,7 +604,7 @@ public int CompareTo(ElectricConductance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -675,7 +739,7 @@ private bool TryToUnit(ElectricConductanceUnit unit, out ElectricConductance? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs index 9398bb6d6a..4acf19915d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity /// [DataContract] - public readonly partial struct ElectricConductivity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricConductivity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -549,16 +549,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricConductivity left, ElectricConductivity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricConductivity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricConductivity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricConductivity objElectricConductivity)) throw new ArgumentException("Expected type ElectricConductivity.", nameof(obj)); + if (!(obj is ElectricConductivity otherQuantity)) throw new ArgumentException("Expected type ElectricConductivity.", nameof(obj)); - return CompareTo(objElectricConductivity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricConductivity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -597,7 +661,7 @@ public int CompareTo(ElectricConductivity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -738,7 +802,7 @@ private bool TryToUnit(ElectricConductivityUnit unit, out ElectricConductivity? _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 4b135166bf..95ec5eab83 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// An electric current is a flow of electric charge. In electric circuits this charge is often carried by moving electrons in a wire. It can also be carried by ions in an electrolyte, or by both ions and electrons such as in a plasma. /// [DataContract] - public readonly partial struct ElectricCurrent : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricCurrent : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -584,16 +584,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricCurrent left, ElectricCurrent right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricCurrent otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricCurrent other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricCurrent objElectricCurrent)) throw new ArgumentException("Expected type ElectricCurrent.", nameof(obj)); + if (!(obj is ElectricCurrent otherQuantity)) throw new ArgumentException("Expected type ElectricCurrent.", nameof(obj)); - return CompareTo(objElectricCurrent); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricCurrent other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -632,7 +696,7 @@ public int CompareTo(ElectricCurrent other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -777,7 +841,7 @@ private bool TryToUnit(ElectricCurrentUnit unit, out ElectricCurrent? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs index 079f822f5e..a4aeb7d9e9 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Current_density /// [DataContract] - public readonly partial struct ElectricCurrentDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricCurrentDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -492,16 +492,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricCurrentDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricCurrentDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricCurrentDensity objElectricCurrentDensity)) throw new ArgumentException("Expected type ElectricCurrentDensity.", nameof(obj)); + if (!(obj is ElectricCurrentDensity otherQuantity)) throw new ArgumentException("Expected type ElectricCurrentDensity.", nameof(obj)); - return CompareTo(objElectricCurrentDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricCurrentDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -540,7 +604,7 @@ public int CompareTo(ElectricCurrentDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -675,7 +739,7 @@ private bool TryToUnit(ElectricCurrentDensityUnit unit, out ElectricCurrentDensi _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs index 419eb6f735..75f0a4b101 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In electromagnetism, the current gradient describes how the current changes in time. /// [DataContract] - public readonly partial struct ElectricCurrentGradient : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricCurrentGradient : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -508,16 +508,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricCurrentGradient otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricCurrentGradient other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricCurrentGradient objElectricCurrentGradient)) throw new ArgumentException("Expected type ElectricCurrentGradient.", nameof(obj)); + if (!(obj is ElectricCurrentGradient otherQuantity)) throw new ArgumentException("Expected type ElectricCurrentGradient.", nameof(obj)); - return CompareTo(objElectricCurrentGradient); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricCurrentGradient other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -556,7 +620,7 @@ public int CompareTo(ElectricCurrentGradient other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -693,7 +757,7 @@ private bool TryToUnit(ElectricCurrentGradientUnit unit, out ElectricCurrentGrad _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs index 7c51cf0ec9..b17fc5a194 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Electric_field /// [DataContract] - public readonly partial struct ElectricField : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricField : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricField left, ElectricField right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricField otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricField other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricField objElectricField)) throw new ArgumentException("Expected type ElectricField.", nameof(obj)); + if (!(obj is ElectricField otherQuantity)) throw new ArgumentException("Expected type ElectricField.", nameof(obj)); - return CompareTo(objElectricField); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricField other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(ElectricField other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(ElectricFieldUnit unit, out ElectricField? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs index 9b760aff32..00492301b1 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Inductance /// [DataContract] - public readonly partial struct ElectricInductance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricInductance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -511,16 +511,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricInductance left, ElectricInductance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricInductance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricInductance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricInductance objElectricInductance)) throw new ArgumentException("Expected type ElectricInductance.", nameof(obj)); + if (!(obj is ElectricInductance otherQuantity)) throw new ArgumentException("Expected type ElectricInductance.", nameof(obj)); - return CompareTo(objElectricInductance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricInductance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -559,7 +623,7 @@ public int CompareTo(ElectricInductance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -696,7 +760,7 @@ private bool TryToUnit(ElectricInductanceUnit unit, out ElectricInductance? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs index 70cf5a6f67..448cb4d46a 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point. /// [DataContract] - public readonly partial struct ElectricPotential : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricPotential : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -532,16 +532,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricPotential left, ElectricPotential right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricPotential otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricPotential other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricPotential objElectricPotential)) throw new ArgumentException("Expected type ElectricPotential.", nameof(obj)); + if (!(obj is ElectricPotential otherQuantity)) throw new ArgumentException("Expected type ElectricPotential.", nameof(obj)); - return CompareTo(objElectricPotential); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricPotential other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -580,7 +644,7 @@ public int CompareTo(ElectricPotential other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -719,7 +783,7 @@ private bool TryToUnit(ElectricPotentialUnit unit, out ElectricPotential? conver _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs index 0e901edbf6..fe6c3b384b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The Electric Potential of a system known to use Alternating Current. /// [DataContract] - public readonly partial struct ElectricPotentialAc : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricPotentialAc : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -527,16 +527,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricPotentialAc left, ElectricPotentialAc right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricPotentialAc otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricPotentialAc other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricPotentialAc objElectricPotentialAc)) throw new ArgumentException("Expected type ElectricPotentialAc.", nameof(obj)); + if (!(obj is ElectricPotentialAc otherQuantity)) throw new ArgumentException("Expected type ElectricPotentialAc.", nameof(obj)); - return CompareTo(objElectricPotentialAc); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricPotentialAc other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -575,7 +639,7 @@ public int CompareTo(ElectricPotentialAc other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -714,7 +778,7 @@ private bool TryToUnit(ElectricPotentialAcUnit unit, out ElectricPotentialAc? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs index 2d903a3775..08f359e742 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// ElectricPotential change rate is the ratio of the electric potential change to the time during which the change occurred (value of electric potential changes per unit time). /// [DataContract] - public readonly partial struct ElectricPotentialChangeRate : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricPotentialChangeRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -812,16 +812,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricPotentialChangeRate left, ElectricPotentialChangeRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricPotentialChangeRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricPotentialChangeRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricPotentialChangeRate objElectricPotentialChangeRate)) throw new ArgumentException("Expected type ElectricPotentialChangeRate.", nameof(obj)); + if (!(obj is ElectricPotentialChangeRate otherQuantity)) throw new ArgumentException("Expected type ElectricPotentialChangeRate.", nameof(obj)); - return CompareTo(objElectricPotentialChangeRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricPotentialChangeRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -860,7 +924,7 @@ public int CompareTo(ElectricPotentialChangeRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1029,7 +1093,7 @@ private bool TryToUnit(ElectricPotentialChangeRateUnit unit, out ElectricPotenti _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs index 6234835396..ac3ec904c3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The Electric Potential of a system known to use Direct Current. /// [DataContract] - public readonly partial struct ElectricPotentialDc : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricPotentialDc : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -527,16 +527,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricPotentialDc left, ElectricPotentialDc right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricPotentialDc otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricPotentialDc other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricPotentialDc objElectricPotentialDc)) throw new ArgumentException("Expected type ElectricPotentialDc.", nameof(obj)); + if (!(obj is ElectricPotentialDc otherQuantity)) throw new ArgumentException("Expected type ElectricPotentialDc.", nameof(obj)); - return CompareTo(objElectricPotentialDc); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricPotentialDc other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -575,7 +639,7 @@ public int CompareTo(ElectricPotentialDc other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -714,7 +778,7 @@ private bool TryToUnit(ElectricPotentialDcUnit unit, out ElectricPotentialDc? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs index 15cf46a18b..3b797e76a6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The electrical resistance of an electrical conductor is the opposition to the passage of an electric current through that conductor. /// [DataContract] - public readonly partial struct ElectricResistance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricResistance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -546,16 +546,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricResistance left, ElectricResistance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricResistance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricResistance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricResistance objElectricResistance)) throw new ArgumentException("Expected type ElectricResistance.", nameof(obj)); + if (!(obj is ElectricResistance otherQuantity)) throw new ArgumentException("Expected type ElectricResistance.", nameof(obj)); - return CompareTo(objElectricResistance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricResistance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -594,7 +658,7 @@ public int CompareTo(ElectricResistance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -735,7 +799,7 @@ private bool TryToUnit(ElectricResistanceUnit unit, out ElectricResistance? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs index b3857f6e0b..09e09fe932 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity /// [DataContract] - public readonly partial struct ElectricResistivity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricResistivity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -701,16 +701,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricResistivity left, ElectricResistivity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricResistivity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricResistivity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricResistivity objElectricResistivity)) throw new ArgumentException("Expected type ElectricResistivity.", nameof(obj)); + if (!(obj is ElectricResistivity otherQuantity)) throw new ArgumentException("Expected type ElectricResistivity.", nameof(obj)); - return CompareTo(objElectricResistivity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricResistivity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -749,7 +813,7 @@ public int CompareTo(ElectricResistivity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -906,7 +970,7 @@ private bool TryToUnit(ElectricResistivityUnit unit, out ElectricResistivity? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs index c795aaedc2..9237afd6ec 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Charge_density /// [DataContract] - public readonly partial struct ElectricSurfaceChargeDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ElectricSurfaceChargeDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -492,16 +492,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ElectricSurfaceChargeDensity left, ElectricSurfaceChargeDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ElectricSurfaceChargeDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ElectricSurfaceChargeDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricSurfaceChargeDensity objElectricSurfaceChargeDensity)) throw new ArgumentException("Expected type ElectricSurfaceChargeDensity.", nameof(obj)); + if (!(obj is ElectricSurfaceChargeDensity otherQuantity)) throw new ArgumentException("Expected type ElectricSurfaceChargeDensity.", nameof(obj)); - return CompareTo(objElectricSurfaceChargeDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ElectricSurfaceChargeDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -540,7 +604,7 @@ public int CompareTo(ElectricSurfaceChargeDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -675,7 +739,7 @@ private bool TryToUnit(ElectricSurfaceChargeDensityUnit unit, out ElectricSurfac _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index cd54933b23..4dc79514d1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The joule, symbol J, is a derived unit of energy, work, or amount of heat in the International System of Units. It is equal to the energy transferred (or work done) when applying a force of one newton through a distance of one metre (1 newton metre or N·m), or in passing an electric current of one ampere through a resistance of one ohm for one second. Many other units of energy are included. Please do not confuse this definition of the calorie with the one colloquially used by the food industry, the large calorie, which is equivalent to 1 kcal. Thermochemical definition of the calorie is used. For BTU, the IT definition is used. /// [DataContract] - public readonly partial struct Energy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Energy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1175,16 +1175,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Energy left, Energy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Energy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Energy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Energy objEnergy)) throw new ArgumentException("Expected type Energy.", nameof(obj)); + if (!(obj is Energy otherQuantity)) throw new ArgumentException("Expected type Energy.", nameof(obj)); - return CompareTo(objEnergy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Energy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1223,7 +1287,7 @@ public int CompareTo(Energy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1428,7 +1492,7 @@ private bool TryToUnit(EnergyUnit unit, out Energy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs index 0115f410d9..ff4e567ac2 100644 --- a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// /// [DataContract] - public readonly partial struct EnergyDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct EnergyDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -660,16 +660,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(EnergyDensity left, EnergyDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is EnergyDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(EnergyDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is EnergyDensity objEnergyDensity)) throw new ArgumentException("Expected type EnergyDensity.", nameof(obj)); + if (!(obj is EnergyDensity otherQuantity)) throw new ArgumentException("Expected type EnergyDensity.", nameof(obj)); - return CompareTo(objEnergyDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(EnergyDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -708,7 +772,7 @@ public int CompareTo(EnergyDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -861,7 +925,7 @@ private bool TryToUnit(EnergyDensityUnit unit, out EnergyDensity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs index 8d2bc12c8a..009703b3a0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Entropy is an important concept in the branch of science known as thermodynamics. The idea of "irreversibility" is central to the understanding of entropy. It is often said that entropy is an expression of the disorder, or randomness of a system, or of our lack of information about it. Entropy is an extensive property. It has the dimension of energy divided by temperature, which has a unit of joules per kelvin (J/K) in the International System of Units /// [DataContract] - public readonly partial struct Entropy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Entropy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -565,16 +565,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Entro return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Entropy left, Entropy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Entropy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Entropy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Entropy objEntropy)) throw new ArgumentException("Expected type Entropy.", nameof(obj)); + if (!(obj is Entropy otherQuantity)) throw new ArgumentException("Expected type Entropy.", nameof(obj)); - return CompareTo(objEntropy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Entropy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -613,7 +677,7 @@ public int CompareTo(Entropy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -756,7 +820,7 @@ private bool TryToUnit(EntropyUnit unit, out Entropy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs index 73b60d4278..fcd7f31a1b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In physics, a force is any influence that causes an object to undergo a certain change, either concerning its movement, direction, or geometrical construction. In other words, a force can cause an object with mass to change its velocity (which includes to begin moving from a state of rest), i.e., to accelerate, or a flexible object to deform, or both. Force can also be described by intuitive concepts such as a push or a pull. A force has both magnitude and direction, making it a vector quantity. It is measured in the SI unit of newtons and represented by the symbol F. /// [DataContract] - public readonly partial struct Force : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Force : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -730,16 +730,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Force left, Force right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Force otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Force other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Force objForce)) throw new ArgumentException("Expected type Force.", nameof(obj)); + if (!(obj is Force otherQuantity)) throw new ArgumentException("Expected type Force.", nameof(obj)); - return CompareTo(objForce); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Force other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -778,7 +842,7 @@ public int CompareTo(Force other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -937,7 +1001,7 @@ private bool TryToUnit(ForceUnit unit, out Force? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs index 80cbe233ce..b6837c60a1 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Force change rate is the ratio of the force change to the time during which the change occurred (value of force changes per unit time). /// [DataContract] - public readonly partial struct ForceChangeRate : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ForceChangeRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -717,16 +717,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ForceChangeRate left, ForceChangeRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ForceChangeRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ForceChangeRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ForceChangeRate objForceChangeRate)) throw new ArgumentException("Expected type ForceChangeRate.", nameof(obj)); + if (!(obj is ForceChangeRate otherQuantity)) throw new ArgumentException("Expected type ForceChangeRate.", nameof(obj)); - return CompareTo(objForceChangeRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ForceChangeRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -765,7 +829,7 @@ public int CompareTo(ForceChangeRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -924,7 +988,7 @@ private bool TryToUnit(ForceChangeRateUnit unit, out ForceChangeRate? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs index 894e7e2c8c..2d82206ae2 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The magnitude of force per unit length. /// [DataContract] - public readonly partial struct ForcePerLength : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ForcePerLength : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1160,16 +1160,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ForcePerLength left, ForcePerLength right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ForcePerLength otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ForcePerLength other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ForcePerLength objForcePerLength)) throw new ArgumentException("Expected type ForcePerLength.", nameof(obj)); + if (!(obj is ForcePerLength otherQuantity)) throw new ArgumentException("Expected type ForcePerLength.", nameof(obj)); - return CompareTo(objForcePerLength); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ForcePerLength other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1208,7 +1272,7 @@ public int CompareTo(ForcePerLength other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1413,7 +1477,7 @@ private bool TryToUnit(ForcePerLengthUnit unit, out ForcePerLength? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs index 9320b73229..420e826ad3 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The number of occurrences of a repeating event per unit time. /// [DataContract] - public readonly partial struct Frequency : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Frequency : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -648,16 +648,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Frequ return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Frequency left, Frequency right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Frequency otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Frequency other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Frequency objFrequency)) throw new ArgumentException("Expected type Frequency.", nameof(obj)); + if (!(obj is Frequency otherQuantity)) throw new ArgumentException("Expected type Frequency.", nameof(obj)); - return CompareTo(objFrequency); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Frequency other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -696,7 +760,7 @@ public int CompareTo(Frequency other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -847,7 +911,7 @@ private bool TryToUnit(FrequencyUnit unit, out Frequency? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs index 717ac2219a..5b43b6a8d1 100644 --- a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Fuel_efficiency /// [DataContract] - public readonly partial struct FuelEfficiency : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct FuelEfficiency : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -511,16 +511,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out FuelE return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(FuelEfficiency left, FuelEfficiency right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is FuelEfficiency otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(FuelEfficiency other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is FuelEfficiency objFuelEfficiency)) throw new ArgumentException("Expected type FuelEfficiency.", nameof(obj)); + if (!(obj is FuelEfficiency otherQuantity)) throw new ArgumentException("Expected type FuelEfficiency.", nameof(obj)); - return CompareTo(objFuelEfficiency); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(FuelEfficiency other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -559,7 +623,7 @@ public int CompareTo(FuelEfficiency other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -696,7 +760,7 @@ private bool TryToUnit(FuelEfficiencyUnit unit, out FuelEfficiency? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs index 8bb0b3660b..23d40b13cc 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Heat flux is the flow of energy per unit of area per unit of time /// [DataContract] - public readonly partial struct HeatFlux : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct HeatFlux : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -774,16 +774,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatF return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(HeatFlux left, HeatFlux right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is HeatFlux otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(HeatFlux other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is HeatFlux objHeatFlux)) throw new ArgumentException("Expected type HeatFlux.", nameof(obj)); + if (!(obj is HeatFlux otherQuantity)) throw new ArgumentException("Expected type HeatFlux.", nameof(obj)); - return CompareTo(objHeatFlux); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(HeatFlux other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -822,7 +886,7 @@ public int CompareTo(HeatFlux other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -987,7 +1051,7 @@ private bool TryToUnit(HeatFluxUnit unit, out HeatFlux? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index 648b980d75..4bee4ba156 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The heat transfer coefficient or film coefficient, or film effectiveness, in thermodynamics and in mechanics is the proportionality constant between the heat flux and the thermodynamic driving force for the flow of heat (i.e., the temperature difference, ΔT) /// [DataContract] - public readonly partial struct HeatTransferCoefficient : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct HeatTransferCoefficient : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out HeatT return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(HeatTransferCoefficient left, HeatTransferCoefficient right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is HeatTransferCoefficient otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(HeatTransferCoefficient other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is HeatTransferCoefficient objHeatTransferCoefficient)) throw new ArgumentException("Expected type HeatTransferCoefficient.", nameof(obj)); + if (!(obj is HeatTransferCoefficient otherQuantity)) throw new ArgumentException("Expected type HeatTransferCoefficient.", nameof(obj)); - return CompareTo(objHeatTransferCoefficient); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(HeatTransferCoefficient other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(HeatTransferCoefficient other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(HeatTransferCoefficientUnit unit, out HeatTransferCoeffic _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs index d3ddacb34a..ecfbc7016d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Illuminance /// [DataContract] - public readonly partial struct Illuminance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Illuminance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -511,16 +511,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Illum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Illuminance left, Illuminance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Illuminance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Illuminance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Illuminance objIlluminance)) throw new ArgumentException("Expected type Illuminance.", nameof(obj)); + if (!(obj is Illuminance otherQuantity)) throw new ArgumentException("Expected type Illuminance.", nameof(obj)); - return CompareTo(objIlluminance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Illuminance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -559,7 +623,7 @@ public int CompareTo(Illuminance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -696,7 +760,7 @@ private bool TryToUnit(IlluminanceUnit unit, out Illuminance? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Information.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.g.cs index 809680f82d..5c2b9f0bdb 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In computing and telecommunications, a unit of information is the capacity of some standard data storage system or communication channel, used to measure the capacities of other systems and channels. In information theory, units of information are also used to measure the information contents or entropy of random variables. /// [DataContract] - public readonly partial struct Information : IQuantity, IDecimalQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Information : IQuantity, IDecimalQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -929,16 +929,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Infor return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Information left, Information right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Information otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public bool Equals(Information other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Information objInformation)) throw new ArgumentException("Expected type Information.", nameof(obj)); + if (!(obj is Information otherQuantity)) throw new ArgumentException("Expected type Information.", nameof(obj)); - return CompareTo(objInformation); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Information other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -977,7 +1041,7 @@ public int CompareTo(Information other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using decimal internally. /// /// /// The other quantity to compare to. @@ -1169,7 +1233,7 @@ private bool TryToUnit(InformationUnit unit, out Information? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs index 7d7da7a249..6733f605f6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Irradiance is the intensity of ultraviolet (UV) or visible light incident on a surface. /// [DataContract] - public readonly partial struct Irradiance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Irradiance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -698,16 +698,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Irrad return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Irradiance left, Irradiance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Irradiance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Irradiance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Irradiance objIrradiance)) throw new ArgumentException("Expected type Irradiance.", nameof(obj)); + if (!(obj is Irradiance otherQuantity)) throw new ArgumentException("Expected type Irradiance.", nameof(obj)); - return CompareTo(objIrradiance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Irradiance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -746,7 +810,7 @@ public int CompareTo(Irradiance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -903,7 +967,7 @@ private bool TryToUnit(IrradianceUnit unit, out Irradiance? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs index 6377902a98..f9d35c1a87 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Irradiation /// [DataContract] - public readonly partial struct Irradiation : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Irradiation : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -568,16 +568,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Irrad return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Irradiation left, Irradiation right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Irradiation otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Irradiation other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Irradiation objIrradiation)) throw new ArgumentException("Expected type Irradiation.", nameof(obj)); + if (!(obj is Irradiation otherQuantity)) throw new ArgumentException("Expected type Irradiation.", nameof(obj)); - return CompareTo(objIrradiation); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Irradiation other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -616,7 +680,7 @@ public int CompareTo(Irradiation other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -759,7 +823,7 @@ private bool TryToUnit(IrradiationUnit unit, out Irradiation? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs index 0b8bff3708..6ebedf07a9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// /// [DataContract] - public readonly partial struct Jerk : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Jerk : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -652,16 +652,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out JerkU return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Jerk left, Jerk right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Jerk otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Jerk other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Jerk objJerk)) throw new ArgumentException("Expected type Jerk.", nameof(obj)); + if (!(obj is Jerk otherQuantity)) throw new ArgumentException("Expected type Jerk.", nameof(obj)); - return CompareTo(objJerk); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Jerk other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -700,7 +764,7 @@ public int CompareTo(Jerk other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -851,7 +915,7 @@ private bool TryToUnit(JerkUnit unit, out Jerk? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index a461b32e15..619181a743 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// http://en.wikipedia.org/wiki/Viscosity /// [DataContract] - public readonly partial struct KinematicViscosity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct KinematicViscosity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -614,16 +614,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Kinem return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(KinematicViscosity left, KinematicViscosity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is KinematicViscosity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(KinematicViscosity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is KinematicViscosity objKinematicViscosity)) throw new ArgumentException("Expected type KinematicViscosity.", nameof(obj)); + if (!(obj is KinematicViscosity otherQuantity)) throw new ArgumentException("Expected type KinematicViscosity.", nameof(obj)); - return CompareTo(objKinematicViscosity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(KinematicViscosity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -662,7 +726,7 @@ public int CompareTo(KinematicViscosity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -809,7 +873,7 @@ private bool TryToUnit(KinematicViscosityUnit unit, out KinematicViscosity? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs b/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs index ba32a9e3a8..dc5dfe2d11 100644 --- a/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LapseRate.g.cs @@ -36,7 +36,7 @@ namespace UnitsNet /// [Obsolete("Use TemperatureGradient instead.")] [DataContract] - public readonly partial struct LapseRate : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct LapseRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -452,16 +452,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lapse return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator ==(LapseRate left, LapseRate 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(LapseRate left, LapseRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is LapseRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(LapseRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is LapseRate objLapseRate)) throw new ArgumentException("Expected type LapseRate.", nameof(obj)); + if (!(obj is LapseRate otherQuantity)) throw new ArgumentException("Expected type LapseRate.", nameof(obj)); - return CompareTo(objLapseRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(LapseRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -500,7 +564,7 @@ public int CompareTo(LapseRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -631,7 +695,7 @@ private bool TryToUnit(LapseRateUnit unit, out LapseRate? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index b5632103e4..5f4572beaa 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Many different units of length have been used around the world. The main units in modern use are U.S. customary units in the United States and the Metric system elsewhere. British Imperial units are still used for some purposes in the United Kingdom and some other countries. The metric system is sub-divided into SI and non-SI units. /// [DataContract] - public readonly partial struct Length : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Length : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1148,16 +1148,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lengt return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Length left, Length right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Length otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Length other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Length objLength)) throw new ArgumentException("Expected type Length.", nameof(obj)); + if (!(obj is Length otherQuantity)) throw new ArgumentException("Expected type Length.", nameof(obj)); - return CompareTo(objLength); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Length other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1196,7 +1260,7 @@ public int CompareTo(Length other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1397,7 +1461,7 @@ private bool TryToUnit(LengthUnit unit, out Length? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Level.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.g.cs index 66932378ee..147038eaf9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Level is the logarithm of the ratio of a quantity Q to a reference value of that quantity, Q₀, expressed in dimensionless units. /// [DataContract] - public readonly partial struct Level : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Level : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -478,16 +478,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Level return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Level left, Level right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Level otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Level other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Level objLevel)) throw new ArgumentException("Expected type Level.", nameof(obj)); + if (!(obj is Level otherQuantity)) throw new ArgumentException("Expected type Level.", nameof(obj)); - return CompareTo(objLevel); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Level other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -526,7 +590,7 @@ public int CompareTo(Level other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -659,7 +723,7 @@ private bool TryToUnit(LevelUnit unit, out Level? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs index cb0e1870a2..c3cb92b908 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// http://en.wikipedia.org/wiki/Linear_density /// [DataContract] - public readonly partial struct LinearDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct LinearDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -701,16 +701,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Linea return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(LinearDensity left, LinearDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is LinearDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(LinearDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is LinearDensity objLinearDensity)) throw new ArgumentException("Expected type LinearDensity.", nameof(obj)); + if (!(obj is LinearDensity otherQuantity)) throw new ArgumentException("Expected type LinearDensity.", nameof(obj)); - return CompareTo(objLinearDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(LinearDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -749,7 +813,7 @@ public int CompareTo(LinearDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -906,7 +970,7 @@ private bool TryToUnit(LinearDensityUnit unit, out LinearDensity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs index 331fea246d..3281c6b995 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// http://en.wikipedia.org/wiki/Linear_density /// [DataContract] - public readonly partial struct LinearPowerDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct LinearPowerDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -910,16 +910,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Linea return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(LinearPowerDensity left, LinearPowerDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is LinearPowerDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(LinearPowerDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is LinearPowerDensity objLinearPowerDensity)) throw new ArgumentException("Expected type LinearPowerDensity.", nameof(obj)); + if (!(obj is LinearPowerDensity otherQuantity)) throw new ArgumentException("Expected type LinearPowerDensity.", nameof(obj)); - return CompareTo(objLinearPowerDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(LinearPowerDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -958,7 +1022,7 @@ public int CompareTo(LinearPowerDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1137,7 +1201,7 @@ private bool TryToUnit(LinearPowerDensityUnit unit, out LinearPowerDensity? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs index ea20867ce4..4ff280d962 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Luminance /// [DataContract] - public readonly partial struct Luminance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Luminance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -625,16 +625,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Luminance left, Luminance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Luminance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Luminance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Luminance objLuminance)) throw new ArgumentException("Expected type Luminance.", nameof(obj)); + if (!(obj is Luminance otherQuantity)) throw new ArgumentException("Expected type Luminance.", nameof(obj)); - return CompareTo(objLuminance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Luminance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -673,7 +737,7 @@ public int CompareTo(Luminance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -822,7 +886,7 @@ private bool TryToUnit(LuminanceUnit unit, out Luminance? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs index 90c81184ed..db7c207aa5 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Luminosity /// [DataContract] - public readonly partial struct Luminosity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Luminosity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -701,16 +701,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Luminosity left, Luminosity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Luminosity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Luminosity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Luminosity objLuminosity)) throw new ArgumentException("Expected type Luminosity.", nameof(obj)); + if (!(obj is Luminosity otherQuantity)) throw new ArgumentException("Expected type Luminosity.", nameof(obj)); - return CompareTo(objLuminosity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Luminosity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -749,7 +813,7 @@ public int CompareTo(Luminosity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -906,7 +970,7 @@ private bool TryToUnit(LuminosityUnit unit, out Luminosity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs index 8086454ba0..d42e0d53f5 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Luminous_flux /// [DataContract] - public readonly partial struct LuminousFlux : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct LuminousFlux : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(LuminousFlux left, LuminousFlux right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is LuminousFlux otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(LuminousFlux other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is LuminousFlux objLuminousFlux)) throw new ArgumentException("Expected type LuminousFlux.", nameof(obj)); + if (!(obj is LuminousFlux otherQuantity)) throw new ArgumentException("Expected type LuminousFlux.", nameof(obj)); - return CompareTo(objLuminousFlux); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(LuminousFlux other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(LuminousFlux other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(LuminousFluxUnit unit, out LuminousFlux? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs index e69fa0f73c..54c0f2c8b5 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Luminous_intensity /// [DataContract] - public readonly partial struct LuminousIntensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct LuminousIntensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Lumin return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(LuminousIntensity left, LuminousIntensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is LuminousIntensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(LuminousIntensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is LuminousIntensity objLuminousIntensity)) throw new ArgumentException("Expected type LuminousIntensity.", nameof(obj)); + if (!(obj is LuminousIntensity otherQuantity)) throw new ArgumentException("Expected type LuminousIntensity.", nameof(obj)); - return CompareTo(objLuminousIntensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(LuminousIntensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(LuminousIntensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(LuminousIntensityUnit unit, out LuminousIntensity? conver _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs index 2b7e0fa07f..62bbdfe827 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Magnetic_field /// [DataContract] - public readonly partial struct MagneticField : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MagneticField : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -549,16 +549,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MagneticField left, MagneticField right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MagneticField otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MagneticField other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MagneticField objMagneticField)) throw new ArgumentException("Expected type MagneticField.", nameof(obj)); + if (!(obj is MagneticField otherQuantity)) throw new ArgumentException("Expected type MagneticField.", nameof(obj)); - return CompareTo(objMagneticField); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MagneticField other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -597,7 +661,7 @@ public int CompareTo(MagneticField other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -738,7 +802,7 @@ private bool TryToUnit(MagneticFieldUnit unit, out MagneticField? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs index 8922d9f830..25e9887863 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Magnetic_flux /// [DataContract] - public readonly partial struct MagneticFlux : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MagneticFlux : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MagneticFlux left, MagneticFlux right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MagneticFlux otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MagneticFlux other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MagneticFlux objMagneticFlux)) throw new ArgumentException("Expected type MagneticFlux.", nameof(obj)); + if (!(obj is MagneticFlux otherQuantity)) throw new ArgumentException("Expected type MagneticFlux.", nameof(obj)); - return CompareTo(objMagneticFlux); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MagneticFlux other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(MagneticFlux other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(MagneticFluxUnit unit, out MagneticFlux? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs index 6038a986c4..96f41fafe3 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Magnetization /// [DataContract] - public readonly partial struct Magnetization : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Magnetization : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Magne return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Magnetization left, Magnetization right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Magnetization otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Magnetization other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Magnetization objMagnetization)) throw new ArgumentException("Expected type Magnetization.", nameof(obj)); + if (!(obj is Magnetization otherQuantity)) throw new ArgumentException("Expected type Magnetization.", nameof(obj)); - return CompareTo(objMagnetization); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Magnetization other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(Magnetization other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(MagnetizationUnit unit, out Magnetization? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index 4d07c98946..cb9616986d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In physics, mass (from Greek μᾶζα "barley cake, lump [of dough]") is a property of a physical system or body, giving rise to the phenomena of the body's resistance to being accelerated by a force and the strength of its mutual gravitational attraction with other bodies. Instruments such as mass balances or scales use those phenomena to measure mass. The SI unit of mass is the kilogram (kg). /// [DataContract] - public readonly partial struct Mass : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Mass : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -942,16 +942,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Mass left, Mass right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Mass otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Mass other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Mass objMass)) throw new ArgumentException("Expected type Mass.", nameof(obj)); + if (!(obj is Mass otherQuantity)) throw new ArgumentException("Expected type Mass.", nameof(obj)); - return CompareTo(objMass); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Mass other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -990,7 +1054,7 @@ public int CompareTo(Mass other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1169,7 +1233,7 @@ private bool TryToUnit(MassUnit unit, out Mass? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs index c608136eb3..d9b852899b 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Mass_concentration_(chemistry) /// [DataContract] - public readonly partial struct MassConcentration : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MassConcentration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1370,16 +1370,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassC return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MassConcentration left, MassConcentration right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MassConcentration otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MassConcentration other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MassConcentration objMassConcentration)) throw new ArgumentException("Expected type MassConcentration.", nameof(obj)); + if (!(obj is MassConcentration otherQuantity)) throw new ArgumentException("Expected type MassConcentration.", nameof(obj)); - return CompareTo(objMassConcentration); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MassConcentration other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1418,7 +1482,7 @@ public int CompareTo(MassConcentration other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1645,7 +1709,7 @@ private bool TryToUnit(MassConcentrationUnit unit, out MassConcentration? conver _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index da50509547..069f8e0938 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Mass flow is the ratio of the mass change to the time during which the change occurred (value of mass changes per unit time). /// [DataContract] - public readonly partial struct MassFlow : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MassFlow : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1061,16 +1061,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MassFlow left, MassFlow right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MassFlow otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MassFlow other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MassFlow objMassFlow)) throw new ArgumentException("Expected type MassFlow.", nameof(obj)); + if (!(obj is MassFlow otherQuantity)) throw new ArgumentException("Expected type MassFlow.", nameof(obj)); - return CompareTo(objMassFlow); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MassFlow other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1109,7 +1173,7 @@ public int CompareTo(MassFlow other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1304,7 +1368,7 @@ private bool TryToUnit(MassFlowUnit unit, out MassFlow? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index cee7fb9244..7e680ee911 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Mass flux is the mass flow rate per unit area. /// [DataContract] - public readonly partial struct MassFlux : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MassFlux : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -660,16 +660,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MassFlux left, MassFlux right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MassFlux otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MassFlux other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MassFlux objMassFlux)) throw new ArgumentException("Expected type MassFlux.", nameof(obj)); + if (!(obj is MassFlux otherQuantity)) throw new ArgumentException("Expected type MassFlux.", nameof(obj)); - return CompareTo(objMassFlux); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MassFlux other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -708,7 +772,7 @@ public int CompareTo(MassFlux other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -861,7 +925,7 @@ private bool TryToUnit(MassFluxUnit unit, out MassFlux? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs index b86c67e918..6132ce4b9e 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Mass_fraction_(chemistry) /// [DataContract] - public readonly partial struct MassFraction : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MassFraction : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -891,16 +891,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MassFraction left, MassFraction right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MassFraction otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MassFraction other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MassFraction objMassFraction)) throw new ArgumentException("Expected type MassFraction.", nameof(obj)); + if (!(obj is MassFraction otherQuantity)) throw new ArgumentException("Expected type MassFraction.", nameof(obj)); - return CompareTo(objMassFraction); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MassFraction other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -939,7 +1003,7 @@ public int CompareTo(MassFraction other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1116,7 +1180,7 @@ private bool TryToUnit(MassFractionUnit unit, out MassFraction? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs index 4a882d33c4..af4c4fe002 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A property of body reflects how its mass is distributed with regard to an axis. /// [DataContract] - public readonly partial struct MassMomentOfInertia : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MassMomentOfInertia : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -964,16 +964,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassM return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MassMomentOfInertia left, MassMomentOfInertia right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MassMomentOfInertia otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MassMomentOfInertia other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MassMomentOfInertia objMassMomentOfInertia)) throw new ArgumentException("Expected type MassMomentOfInertia.", nameof(obj)); + if (!(obj is MassMomentOfInertia otherQuantity)) throw new ArgumentException("Expected type MassMomentOfInertia.", nameof(obj)); - return CompareTo(objMassMomentOfInertia); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MassMomentOfInertia other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1012,7 +1076,7 @@ public int CompareTo(MassMomentOfInertia other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1197,7 +1261,7 @@ private bool TryToUnit(MassMomentOfInertiaUnit unit, out MassMomentOfInertia? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs index 90da0c7f02..cc2cadc7de 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Molar energy is the amount of energy stored in 1 mole of a substance. /// [DataContract] - public readonly partial struct MolarEnergy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MolarEnergy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MolarEnergy left, MolarEnergy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MolarEnergy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MolarEnergy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MolarEnergy objMolarEnergy)) throw new ArgumentException("Expected type MolarEnergy.", nameof(obj)); + if (!(obj is MolarEnergy otherQuantity)) throw new ArgumentException("Expected type MolarEnergy.", nameof(obj)); - return CompareTo(objMolarEnergy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MolarEnergy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(MolarEnergy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(MolarEnergyUnit unit, out MolarEnergy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs index 2dacb7ff7f..b195f40aed 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Molar entropy is amount of energy required to increase temperature of 1 mole substance by 1 Kelvin. /// [DataContract] - public readonly partial struct MolarEntropy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MolarEntropy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MolarEntropy left, MolarEntropy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MolarEntropy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MolarEntropy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MolarEntropy objMolarEntropy)) throw new ArgumentException("Expected type MolarEntropy.", nameof(obj)); + if (!(obj is MolarEntropy otherQuantity)) throw new ArgumentException("Expected type MolarEntropy.", nameof(obj)); - return CompareTo(objMolarEntropy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MolarEntropy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(MolarEntropy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(MolarEntropyUnit unit, out MolarEntropy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index e8a3762dde..b3929046a1 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In chemistry, the molar mass M is a physical property defined as the mass of a given substance (chemical element or chemical compound) divided by the amount of substance. /// [DataContract] - public readonly partial struct MolarMass : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct MolarMass : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -672,16 +672,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(MolarMass left, MolarMass right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is MolarMass otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(MolarMass other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is MolarMass objMolarMass)) throw new ArgumentException("Expected type MolarMass.", nameof(obj)); + if (!(obj is MolarMass otherQuantity)) throw new ArgumentException("Expected type MolarMass.", nameof(obj)); - return CompareTo(objMolarMass); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(MolarMass other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -720,7 +784,7 @@ public int CompareTo(MolarMass other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -873,7 +937,7 @@ private bool TryToUnit(MolarMassUnit unit, out MolarMass? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index f9bb0590ca..c9abf7dee0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -32,13 +32,13 @@ namespace UnitsNet { /// /// - /// Molar concentration, also called molarity, amount concentration or substance concentration, is a measure of the concentration of a solute in a solution, or of any chemical species, in terms of amount of substance in a given volume. + /// Molar concentration, also called molarity, amount concentration or substance concentration, is a measure of the concentration of a solute in a solution, or of any chemical species, in terms of amount of substance in a given volume. /// /// /// https://en.wikipedia.org/wiki/Molar_concentration /// [DataContract] - public readonly partial struct Molarity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Molarity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -638,16 +638,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Molarity left, Molarity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Molarity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Molarity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Molarity objMolarity)) throw new ArgumentException("Expected type Molarity.", nameof(obj)); + if (!(obj is Molarity otherQuantity)) throw new ArgumentException("Expected type Molarity.", nameof(obj)); - return CompareTo(objMolarity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Molarity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -686,7 +750,7 @@ public int CompareTo(Molarity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -849,7 +913,7 @@ private bool TryToUnit(MolarityUnit unit, out Molarity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs index 886fdcf5aa..4349b772a9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Permeability_(electromagnetism) /// [DataContract] - public readonly partial struct Permeability : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Permeability : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Perme return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Permeability left, Permeability right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Permeability otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Permeability other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Permeability objPermeability)) throw new ArgumentException("Expected type Permeability.", nameof(obj)); + if (!(obj is Permeability otherQuantity)) throw new ArgumentException("Expected type Permeability.", nameof(obj)); - return CompareTo(objPermeability); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Permeability other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(Permeability other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(PermeabilityUnit unit, out Permeability? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs index fe14ad749e..4704d8a91d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Permittivity /// [DataContract] - public readonly partial struct Permittivity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Permittivity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Permi return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Permittivity left, Permittivity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Permittivity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Permittivity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Permittivity objPermittivity)) throw new ArgumentException("Expected type Permittivity.", nameof(obj)); + if (!(obj is Permittivity otherQuantity)) throw new ArgumentException("Expected type Permittivity.", nameof(obj)); - return CompareTo(objPermittivity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Permittivity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(Permittivity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(PermittivityUnit unit, out Permittivity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs index 37425206e6..8c2ba5a2d6 100644 --- a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Permeability_(Earth_sciences) /// [DataContract] - public readonly partial struct PorousMediumPermeability : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct PorousMediumPermeability : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -530,16 +530,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Porou return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(PorousMediumPermeability left, PorousMediumPermeability right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is PorousMediumPermeability otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(PorousMediumPermeability other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is PorousMediumPermeability objPorousMediumPermeability)) throw new ArgumentException("Expected type PorousMediumPermeability.", nameof(obj)); + if (!(obj is PorousMediumPermeability otherQuantity)) throw new ArgumentException("Expected type PorousMediumPermeability.", nameof(obj)); - return CompareTo(objPorousMediumPermeability); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(PorousMediumPermeability other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -578,7 +642,7 @@ public int CompareTo(PorousMediumPermeability other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -717,7 +781,7 @@ private bool TryToUnit(PorousMediumPermeabilityUnit unit, out PorousMediumPermea _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index c79a8c8c91..6c2a900761 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In physics, power is the rate of doing work. It is equivalent to an amount of energy consumed per unit time. /// [DataContract] - public readonly partial struct Power : IQuantity, IDecimalQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Power : IQuantity, IDecimalQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -929,16 +929,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Power left, Power right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Power otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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, decimal, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public bool Equals(Power other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Power objPower)) throw new ArgumentException("Expected type Power.", nameof(obj)); + if (!(obj is Power otherQuantity)) throw new ArgumentException("Expected type Power.", nameof(obj)); - return CompareTo(objPower); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Power other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -977,7 +1041,7 @@ public int CompareTo(Power other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using decimal internally. /// /// /// The other quantity to compare to. @@ -1169,7 +1233,7 @@ private bool TryToUnit(PowerUnit unit, out Power? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs index 070beb332d..35becfd899 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The amount of power in a volume. /// [DataContract] - public readonly partial struct PowerDensity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct PowerDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1268,16 +1268,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(PowerDensity left, PowerDensity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is PowerDensity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(PowerDensity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is PowerDensity objPowerDensity)) throw new ArgumentException("Expected type PowerDensity.", nameof(obj)); + if (!(obj is PowerDensity otherQuantity)) throw new ArgumentException("Expected type PowerDensity.", nameof(obj)); - return CompareTo(objPowerDensity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(PowerDensity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1316,7 +1380,7 @@ public int CompareTo(PowerDensity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1533,7 +1597,7 @@ private bool TryToUnit(PowerDensityUnit unit, out PowerDensity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs index 21c7d7b2c8..bae5d5e9b3 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The strength of a signal expressed in decibels (dB) relative to one watt. /// [DataContract] - public readonly partial struct PowerRatio : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct PowerRatio : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -478,16 +478,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(PowerRatio left, PowerRatio right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is PowerRatio otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(PowerRatio other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is PowerRatio objPowerRatio)) throw new ArgumentException("Expected type PowerRatio.", nameof(obj)); + if (!(obj is PowerRatio otherQuantity)) throw new ArgumentException("Expected type PowerRatio.", nameof(obj)); - return CompareTo(objPowerRatio); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(PowerRatio other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -526,7 +590,7 @@ public int CompareTo(PowerRatio other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -659,7 +723,7 @@ private bool TryToUnit(PowerRatioUnit unit, out PowerRatio? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index de40801b2f..878bd296e6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Pressure (symbol: P or p) is the ratio of force to the area over which that force is distributed. Pressure is force per unit area applied in a direction perpendicular to the surface of an object. Gauge pressure (also spelled gage pressure)[a] is the pressure relative to the local atmospheric or ambient pressure. Pressure is measured in any unit of force divided by any unit of area. The SI unit of pressure is the newton per square metre, which is called the pascal (Pa) after the seventeenth-century philosopher and scientist Blaise Pascal. A pressure of 1 Pa is small; it approximately equals the pressure exerted by a dollar bill resting flat on a table. Everyday pressures are often stated in kilopascals (1 kPa = 1000 Pa). /// [DataContract] - public readonly partial struct Pressure : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Pressure : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1356,16 +1356,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Pressure left, Pressure right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Pressure otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Pressure other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Pressure objPressure)) throw new ArgumentException("Expected type Pressure.", nameof(obj)); + if (!(obj is Pressure otherQuantity)) throw new ArgumentException("Expected type Pressure.", nameof(obj)); - return CompareTo(objPressure); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Pressure other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1404,7 +1468,7 @@ public int CompareTo(Pressure other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1627,7 +1691,7 @@ private bool TryToUnit(PressureUnit unit, out Pressure? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs index 5c34d5763d..e9c92a19db 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Pressure change rate is the ratio of the pressure change to the time during which the change occurred (value of pressure changes per unit time). /// [DataContract] - public readonly partial struct PressureChangeRate : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct PressureChangeRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -712,16 +712,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(PressureChangeRate left, PressureChangeRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is PressureChangeRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(PressureChangeRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is PressureChangeRate objPressureChangeRate)) throw new ArgumentException("Expected type PressureChangeRate.", nameof(obj)); + if (!(obj is PressureChangeRate otherQuantity)) throw new ArgumentException("Expected type PressureChangeRate.", nameof(obj)); - return CompareTo(objPressureChangeRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(PressureChangeRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -760,7 +824,7 @@ public int CompareTo(PressureChangeRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -917,7 +981,7 @@ private bool TryToUnit(PressureChangeRateUnit unit, out PressureChangeRate? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs index 4c4fc5bed4..5a12dc4fd9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In mathematics, a ratio is a relationship between two numbers of the same kind (e.g., objects, persons, students, spoonfuls, units of whatever identical dimension), usually expressed as "a to b" or a:b, sometimes expressed arithmetically as a dimensionless quotient of the two that explicitly indicates how many times the first number contains the second (not necessarily an integer). /// [DataContract] - public readonly partial struct Ratio : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Ratio : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -546,16 +546,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Ratio left, Ratio right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Ratio otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Ratio other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Ratio objRatio)) throw new ArgumentException("Expected type Ratio.", nameof(obj)); + if (!(obj is Ratio otherQuantity)) throw new ArgumentException("Expected type Ratio.", nameof(obj)); - return CompareTo(objRatio); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Ratio other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -594,7 +658,7 @@ public int CompareTo(Ratio other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -735,7 +799,7 @@ private bool TryToUnit(RatioUnit unit, out Ratio? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs index f295a579c7..ddffc1cf3d 100644 --- a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The change in ratio per unit of time. /// [DataContract] - public readonly partial struct RatioChangeRate : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct RatioChangeRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -470,16 +470,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Ratio return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(RatioChangeRate left, RatioChangeRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is RatioChangeRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(RatioChangeRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is RatioChangeRate objRatioChangeRate)) throw new ArgumentException("Expected type RatioChangeRate.", nameof(obj)); + if (!(obj is RatioChangeRate otherQuantity)) throw new ArgumentException("Expected type RatioChangeRate.", nameof(obj)); - return CompareTo(objRatioChangeRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(RatioChangeRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -518,7 +582,7 @@ public int CompareTo(RatioChangeRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -651,7 +715,7 @@ private bool TryToUnit(RatioChangeRateUnit unit, out RatioChangeRate? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs index ad7a4923c5..6c26f6d502 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The Volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour. /// [DataContract] - public readonly partial struct ReactiveEnergy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ReactiveEnergy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out React return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ReactiveEnergy left, ReactiveEnergy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ReactiveEnergy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ReactiveEnergy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ReactiveEnergy objReactiveEnergy)) throw new ArgumentException("Expected type ReactiveEnergy.", nameof(obj)); + if (!(obj is ReactiveEnergy otherQuantity)) throw new ArgumentException("Expected type ReactiveEnergy.", nameof(obj)); - return CompareTo(objReactiveEnergy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ReactiveEnergy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(ReactiveEnergy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(ReactiveEnergyUnit unit, out ReactiveEnergy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs index 8755488de6..c0d1b5cc71 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Volt-ampere reactive (var) is a unit by which reactive power is expressed in an AC electric power system. Reactive power exists in an AC circuit when the current and voltage are not in phase. /// [DataContract] - public readonly partial struct ReactivePower : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ReactivePower : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -508,16 +508,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out React return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ReactivePower left, ReactivePower right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ReactivePower otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ReactivePower other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ReactivePower objReactivePower)) throw new ArgumentException("Expected type ReactivePower.", nameof(obj)); + if (!(obj is ReactivePower otherQuantity)) throw new ArgumentException("Expected type ReactivePower.", nameof(obj)); - return CompareTo(objReactivePower); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ReactivePower other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -556,7 +620,7 @@ public int CompareTo(ReactivePower other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -693,7 +757,7 @@ private bool TryToUnit(ReactivePowerUnit unit, out ReactivePower? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs index 3f02a59653..12fe121d52 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Inverse-square_law /// [DataContract] - public readonly partial struct ReciprocalArea : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ReciprocalArea : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -644,16 +644,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ReciprocalArea left, ReciprocalArea right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ReciprocalArea otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ReciprocalArea other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ReciprocalArea objReciprocalArea)) throw new ArgumentException("Expected type ReciprocalArea.", nameof(obj)); + if (!(obj is ReciprocalArea otherQuantity)) throw new ArgumentException("Expected type ReciprocalArea.", nameof(obj)); - return CompareTo(objReciprocalArea); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ReciprocalArea other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -692,7 +756,7 @@ public int CompareTo(ReciprocalArea other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -843,7 +907,7 @@ private bool TryToUnit(ReciprocalAreaUnit unit, out ReciprocalArea? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index 6c6426d6e1..13096334be 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Reciprocal_length /// [DataContract] - public readonly partial struct ReciprocalLength : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ReciprocalLength : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -625,16 +625,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Recip return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ReciprocalLength left, ReciprocalLength right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ReciprocalLength otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ReciprocalLength other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ReciprocalLength objReciprocalLength)) throw new ArgumentException("Expected type ReciprocalLength.", nameof(obj)); + if (!(obj is ReciprocalLength otherQuantity)) throw new ArgumentException("Expected type ReciprocalLength.", nameof(obj)); - return CompareTo(objReciprocalLength); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ReciprocalLength other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -673,7 +737,7 @@ public int CompareTo(ReciprocalLength other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -822,7 +886,7 @@ private bool TryToUnit(ReciprocalLengthUnit unit, out ReciprocalLength? converte _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs index ca9ebe4f6c..90a3a06769 100644 --- a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Relative humidity is a ratio of the actual water vapor present in the air to the maximum water vapor in the air at the given temperature. /// [DataContract] - public readonly partial struct RelativeHumidity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct RelativeHumidity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -451,16 +451,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Relat return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(RelativeHumidity left, RelativeHumidity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is RelativeHumidity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(RelativeHumidity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is RelativeHumidity objRelativeHumidity)) throw new ArgumentException("Expected type RelativeHumidity.", nameof(obj)); + if (!(obj is RelativeHumidity otherQuantity)) throw new ArgumentException("Expected type RelativeHumidity.", nameof(obj)); - return CompareTo(objRelativeHumidity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(RelativeHumidity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -499,7 +563,7 @@ public int CompareTo(RelativeHumidity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -630,7 +694,7 @@ private bool TryToUnit(RelativeHumidityUnit unit, out RelativeHumidity? converte _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs index d637aa381a..5a62a4896b 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Angular acceleration is the rate of change of rotational speed. /// [DataContract] - public readonly partial struct RotationalAcceleration : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct RotationalAcceleration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -508,16 +508,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(RotationalAcceleration left, RotationalAcceleration right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is RotationalAcceleration otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(RotationalAcceleration other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is RotationalAcceleration objRotationalAcceleration)) throw new ArgumentException("Expected type RotationalAcceleration.", nameof(obj)); + if (!(obj is RotationalAcceleration otherQuantity)) throw new ArgumentException("Expected type RotationalAcceleration.", nameof(obj)); - return CompareTo(objRotationalAcceleration); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(RotationalAcceleration other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -556,7 +620,7 @@ public int CompareTo(RotationalAcceleration other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -693,7 +757,7 @@ private bool TryToUnit(RotationalAccelerationUnit unit, out RotationalAccelerati _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index 8bcdcd2c67..cba7ab82ba 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Rotational speed (sometimes called speed of revolution) is the number of complete rotations, revolutions, cycles, or turns per time unit. Rotational speed is a cyclic frequency, measured in radians per second or in hertz in the SI System by scientists, or in revolutions per minute (rpm or min-1) or revolutions per second in everyday life. The symbol for rotational speed is ω (the Greek lowercase letter "omega"). /// [DataContract] - public readonly partial struct RotationalSpeed : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct RotationalSpeed : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -691,16 +691,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(RotationalSpeed left, RotationalSpeed right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is RotationalSpeed otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(RotationalSpeed other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is RotationalSpeed objRotationalSpeed)) throw new ArgumentException("Expected type RotationalSpeed.", nameof(obj)); + if (!(obj is RotationalSpeed otherQuantity)) throw new ArgumentException("Expected type RotationalSpeed.", nameof(obj)); - return CompareTo(objRotationalSpeed); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(RotationalSpeed other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -739,7 +803,7 @@ public int CompareTo(RotationalSpeed other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -894,7 +958,7 @@ private bool TryToUnit(RotationalSpeedUnit unit, out RotationalSpeed? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs index 2885b7a89c..55c31efb3b 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Stiffness#Rotational_stiffness /// [DataContract] - public readonly partial struct RotationalStiffness : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct RotationalStiffness : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1059,16 +1059,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(RotationalStiffness left, RotationalStiffness right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is RotationalStiffness otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(RotationalStiffness other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is RotationalStiffness objRotationalStiffness)) throw new ArgumentException("Expected type RotationalStiffness.", nameof(obj)); + if (!(obj is RotationalStiffness otherQuantity)) throw new ArgumentException("Expected type RotationalStiffness.", nameof(obj)); - return CompareTo(objRotationalStiffness); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(RotationalStiffness other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1107,7 +1171,7 @@ public int CompareTo(RotationalStiffness other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1302,7 +1366,7 @@ private bool TryToUnit(RotationalStiffnessUnit unit, out RotationalStiffness? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs index 9f97e88234..3271a39e7f 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Stiffness#Rotational_stiffness /// [DataContract] - public readonly partial struct RotationalStiffnessPerLength : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct RotationalStiffnessPerLength : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -527,16 +527,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(RotationalStiffnessPerLength left, RotationalStiffnessPerLength right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is RotationalStiffnessPerLength otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(RotationalStiffnessPerLength other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is RotationalStiffnessPerLength objRotationalStiffnessPerLength)) throw new ArgumentException("Expected type RotationalStiffnessPerLength.", nameof(obj)); + if (!(obj is RotationalStiffnessPerLength otherQuantity)) throw new ArgumentException("Expected type RotationalStiffnessPerLength.", nameof(obj)); - return CompareTo(objRotationalStiffnessPerLength); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(RotationalStiffnessPerLength other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -575,7 +639,7 @@ public int CompareTo(RotationalStiffnessPerLength other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -714,7 +778,7 @@ private bool TryToUnit(RotationalStiffnessPerLengthUnit unit, out RotationalStif _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs index 270d576ad2..3f68ad2192 100644 --- a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A way of representing a number of items. /// [DataContract] - public readonly partial struct Scalar : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Scalar : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -451,16 +451,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Scala return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Scalar left, Scalar right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Scalar otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Scalar other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Scalar objScalar)) throw new ArgumentException("Expected type Scalar.", nameof(obj)); + if (!(obj is Scalar otherQuantity)) throw new ArgumentException("Expected type Scalar.", nameof(obj)); - return CompareTo(objScalar); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Scalar other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -499,7 +563,7 @@ public int CompareTo(Scalar other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -630,7 +694,7 @@ private bool TryToUnit(ScalarUnit unit, out Scalar? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs index 59997371ea..7f79e74d36 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Solid_angle /// [DataContract] - public readonly partial struct SolidAngle : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct SolidAngle : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Solid return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(SolidAngle left, SolidAngle right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is SolidAngle otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(SolidAngle other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is SolidAngle objSolidAngle)) throw new ArgumentException("Expected type SolidAngle.", nameof(obj)); + if (!(obj is SolidAngle otherQuantity)) throw new ArgumentException("Expected type SolidAngle.", nameof(obj)); - return CompareTo(objSolidAngle); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(SolidAngle other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(SolidAngle other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(SolidAngleUnit unit, out SolidAngle? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs index 7f4e83de44..b4490ff456 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Specific_energy /// [DataContract] - public readonly partial struct SpecificEnergy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct SpecificEnergy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -986,16 +986,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(SpecificEnergy left, SpecificEnergy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is SpecificEnergy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(SpecificEnergy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is SpecificEnergy objSpecificEnergy)) throw new ArgumentException("Expected type SpecificEnergy.", nameof(obj)); + if (!(obj is SpecificEnergy otherQuantity)) throw new ArgumentException("Expected type SpecificEnergy.", nameof(obj)); - return CompareTo(objSpecificEnergy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(SpecificEnergy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1034,7 +1098,7 @@ public int CompareTo(SpecificEnergy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1221,7 +1285,7 @@ private bool TryToUnit(SpecificEnergyUnit unit, out SpecificEnergy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs index 5cb253e90c..8ee4ec4878 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Specific entropy is an amount of energy required to raise temperature of a substance by 1 Kelvin per unit mass. /// [DataContract] - public readonly partial struct SpecificEntropy : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct SpecificEntropy : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -603,16 +603,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(SpecificEntropy left, SpecificEntropy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is SpecificEntropy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(SpecificEntropy other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is SpecificEntropy objSpecificEntropy)) throw new ArgumentException("Expected type SpecificEntropy.", nameof(obj)); + if (!(obj is SpecificEntropy otherQuantity)) throw new ArgumentException("Expected type SpecificEntropy.", nameof(obj)); - return CompareTo(objSpecificEntropy); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(SpecificEntropy other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -651,7 +715,7 @@ public int CompareTo(SpecificEntropy other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -798,7 +862,7 @@ private bool TryToUnit(SpecificEntropyUnit unit, out SpecificEntropy? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs index 4ed93c01cc..a09c0cb448 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Thrust-specific_fuel_consumption /// [DataContract] - public readonly partial struct SpecificFuelConsumption : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct SpecificFuelConsumption : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -511,16 +511,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(SpecificFuelConsumption left, SpecificFuelConsumption right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is SpecificFuelConsumption otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(SpecificFuelConsumption other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is SpecificFuelConsumption objSpecificFuelConsumption)) throw new ArgumentException("Expected type SpecificFuelConsumption.", nameof(obj)); + if (!(obj is SpecificFuelConsumption otherQuantity)) throw new ArgumentException("Expected type SpecificFuelConsumption.", nameof(obj)); - return CompareTo(objSpecificFuelConsumption); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(SpecificFuelConsumption other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -559,7 +623,7 @@ public int CompareTo(SpecificFuelConsumption other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -696,7 +760,7 @@ private bool TryToUnit(SpecificFuelConsumptionUnit unit, out SpecificFuelConsump _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs index e901f6a002..a26a6f0053 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In thermodynamics, the specific volume of a substance is the ratio of the substance's volume to its mass. It is the reciprocal of density and an intrinsic property of matter as well. /// [DataContract] - public readonly partial struct SpecificVolume : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct SpecificVolume : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -489,16 +489,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(SpecificVolume left, SpecificVolume right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is SpecificVolume otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(SpecificVolume other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is SpecificVolume objSpecificVolume)) throw new ArgumentException("Expected type SpecificVolume.", nameof(obj)); + if (!(obj is SpecificVolume otherQuantity)) throw new ArgumentException("Expected type SpecificVolume.", nameof(obj)); - return CompareTo(objSpecificVolume); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(SpecificVolume other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -537,7 +601,7 @@ public int CompareTo(SpecificVolume other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -672,7 +736,7 @@ private bool TryToUnit(SpecificVolumeUnit unit, out SpecificVolume? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs index c2f728eb9b..86dfa0850f 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// http://en.wikipedia.org/wiki/Specificweight /// [DataContract] - public readonly partial struct SpecificWeight : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct SpecificWeight : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -758,16 +758,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speci return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(SpecificWeight left, SpecificWeight right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is SpecificWeight otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(SpecificWeight other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is SpecificWeight objSpecificWeight)) throw new ArgumentException("Expected type SpecificWeight.", nameof(obj)); + if (!(obj is SpecificWeight otherQuantity)) throw new ArgumentException("Expected type SpecificWeight.", nameof(obj)); - return CompareTo(objSpecificWeight); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(SpecificWeight other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -806,7 +870,7 @@ public int CompareTo(SpecificWeight other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -969,7 +1033,7 @@ private bool TryToUnit(SpecificWeightUnit unit, out SpecificWeight? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs index 23f1c22189..c06f28de9e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In everyday use and in kinematics, the speed of an object is the magnitude of its velocity (the rate of change of its position); it is thus a scalar quantity.[1] The average speed of an object in an interval of time is the distance travelled by the object divided by the duration of the interval;[2] the instantaneous speed is the limit of the average speed as the duration of the time interval approaches zero. /// [DataContract] - public readonly partial struct Speed : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Speed : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1083,16 +1083,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speed return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Speed left, Speed right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Speed otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Speed other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Speed objSpeed)) throw new ArgumentException("Expected type Speed.", nameof(obj)); + if (!(obj is Speed otherQuantity)) throw new ArgumentException("Expected type Speed.", nameof(obj)); - return CompareTo(objSpeed); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Speed other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1131,7 +1195,7 @@ public int CompareTo(Speed other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1326,7 +1390,7 @@ private bool TryToUnit(SpeedUnit unit, out Speed? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs index 8fe6f311ea..a17f6b7d03 100644 --- a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The molar flow rate of a gas corrected to standardized conditions of temperature and pressure thus representing a fixed number of moles of gas regardless of composition and actual flow conditions. /// [DataContract] - public readonly partial struct StandardVolumeFlow : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct StandardVolumeFlow : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -603,16 +603,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Stand return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(StandardVolumeFlow left, StandardVolumeFlow right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is StandardVolumeFlow otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(StandardVolumeFlow other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is StandardVolumeFlow objStandardVolumeFlow)) throw new ArgumentException("Expected type StandardVolumeFlow.", nameof(obj)); + if (!(obj is StandardVolumeFlow otherQuantity)) throw new ArgumentException("Expected type StandardVolumeFlow.", nameof(obj)); - return CompareTo(objStandardVolumeFlow); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(StandardVolumeFlow other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -651,7 +715,7 @@ public int CompareTo(StandardVolumeFlow other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -798,7 +862,7 @@ private bool TryToUnit(StandardVolumeFlowUnit unit, out StandardVolumeFlow? conv _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs index 63807a9e1d..20175c551d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A temperature is a numerical measure of hot or cold. Its measurement is by detection of heat radiation or particle velocity or kinetic energy, or by the bulk behavior of a thermometric material. It may be calibrated in any of various temperature scales, Celsius, Fahrenheit, Kelvin, etc. The fundamental physical definition of temperature is provided by thermodynamics. /// [DataContract] - public readonly partial struct Temperature : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Temperature : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -576,16 +576,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Temperature left, Temperature right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Temperature otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Temperature other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Temperature objTemperature)) throw new ArgumentException("Expected type Temperature.", nameof(obj)); + if (!(obj is Temperature otherQuantity)) throw new ArgumentException("Expected type Temperature.", nameof(obj)); - return CompareTo(objTemperature); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Temperature other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -624,7 +688,7 @@ public int CompareTo(Temperature other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -773,7 +837,7 @@ private bool TryToUnit(TemperatureUnit unit, out Temperature? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs index ccdbef8d82..1f90689eeb 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Temperature change rate is the ratio of the temperature change to the time during which the change occurred (value of temperature changes per unit time). /// [DataContract] - public readonly partial struct TemperatureChangeRate : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct TemperatureChangeRate : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -622,16 +622,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(TemperatureChangeRate left, TemperatureChangeRate right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is TemperatureChangeRate otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(TemperatureChangeRate other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is TemperatureChangeRate objTemperatureChangeRate)) throw new ArgumentException("Expected type TemperatureChangeRate.", nameof(obj)); + if (!(obj is TemperatureChangeRate otherQuantity)) throw new ArgumentException("Expected type TemperatureChangeRate.", nameof(obj)); - return CompareTo(objTemperatureChangeRate); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(TemperatureChangeRate other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -670,7 +734,7 @@ public int CompareTo(TemperatureChangeRate other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -819,7 +883,7 @@ private bool TryToUnit(TemperatureChangeRateUnit unit, out TemperatureChangeRate _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs index c9d515069a..60086ffe05 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Difference between two temperatures. The conversions are different than for Temperature. /// [DataContract] - public readonly partial struct TemperatureDelta : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct TemperatureDelta : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -603,16 +603,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(TemperatureDelta left, TemperatureDelta right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is TemperatureDelta otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(TemperatureDelta other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is TemperatureDelta objTemperatureDelta)) throw new ArgumentException("Expected type TemperatureDelta.", nameof(obj)); + if (!(obj is TemperatureDelta otherQuantity)) throw new ArgumentException("Expected type TemperatureDelta.", nameof(obj)); - return CompareTo(objTemperatureDelta); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(TemperatureDelta other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -651,7 +715,7 @@ public int CompareTo(TemperatureDelta other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -798,7 +862,7 @@ private bool TryToUnit(TemperatureDeltaUnit unit, out TemperatureDelta? converte _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs index 476aa2f8f5..1fe916a88f 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// /// [DataContract] - public readonly partial struct TemperatureGradient : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct TemperatureGradient : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -508,16 +508,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(TemperatureGradient left, TemperatureGradient right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is TemperatureGradient otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(TemperatureGradient other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is TemperatureGradient objTemperatureGradient)) throw new ArgumentException("Expected type TemperatureGradient.", nameof(obj)); + if (!(obj is TemperatureGradient otherQuantity)) throw new ArgumentException("Expected type TemperatureGradient.", nameof(obj)); - return CompareTo(objTemperatureGradient); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(TemperatureGradient other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -556,7 +620,7 @@ public int CompareTo(TemperatureGradient other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -693,7 +757,7 @@ private bool TryToUnit(TemperatureGradientUnit unit, out TemperatureGradient? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs index 6c83353c45..0df1d8b6e3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Thermal_Conductivity /// [DataContract] - public readonly partial struct ThermalConductivity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ThermalConductivity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -473,16 +473,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Therm return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ThermalConductivity left, ThermalConductivity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ThermalConductivity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ThermalConductivity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ThermalConductivity objThermalConductivity)) throw new ArgumentException("Expected type ThermalConductivity.", nameof(obj)); + if (!(obj is ThermalConductivity otherQuantity)) throw new ArgumentException("Expected type ThermalConductivity.", nameof(obj)); - return CompareTo(objThermalConductivity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ThermalConductivity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -521,7 +585,7 @@ public int CompareTo(ThermalConductivity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -654,7 +718,7 @@ private bool TryToUnit(ThermalConductivityUnit unit, out ThermalConductivity? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs index 097a72be1e..3608e5da19 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Heat Transfer Coefficient or Thermal conductivity - indicates a materials ability to conduct heat. /// [DataContract] - public readonly partial struct ThermalResistance : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct ThermalResistance : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -546,16 +546,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Therm return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(ThermalResistance left, ThermalResistance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is ThermalResistance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(ThermalResistance other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ThermalResistance objThermalResistance)) throw new ArgumentException("Expected type ThermalResistance.", nameof(obj)); + if (!(obj is ThermalResistance otherQuantity)) throw new ArgumentException("Expected type ThermalResistance.", nameof(obj)); - return CompareTo(objThermalResistance); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(ThermalResistance other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -594,7 +658,7 @@ public int CompareTo(ThermalResistance other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -735,7 +799,7 @@ private bool TryToUnit(ThermalResistanceUnit unit, out ThermalResistance? conver _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs index 6caeee53be..64c4b1a46e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Torque, moment or moment of force (see the terminology below), is the tendency of a force to rotate an object about an axis,[1] fulcrum, or pivot. Just as a force is a push or a pull, a torque can be thought of as a twist to an object. Mathematically, torque is defined as the cross product of the lever-arm distance and force, which tends to produce rotation. Loosely speaking, torque is a measure of the turning force on an object such as a bolt or a flywheel. For example, pushing or pulling the handle of a wrench connected to a nut or bolt produces a torque (turning force) that loosens or tightens the nut or bolt. /// [DataContract] - public readonly partial struct Torque : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Torque : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -910,16 +910,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Torque left, Torque right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Torque otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Torque other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Torque objTorque)) throw new ArgumentException("Expected type Torque.", nameof(obj)); + if (!(obj is Torque otherQuantity)) throw new ArgumentException("Expected type Torque.", nameof(obj)); - return CompareTo(objTorque); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Torque other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -958,7 +1022,7 @@ public int CompareTo(Torque other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1137,7 +1201,7 @@ private bool TryToUnit(TorqueUnit unit, out Torque? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs index d70cf4f425..3d5fb80f21 100644 --- a/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TorquePerLength.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// The magnitude of torque per unit length. /// [DataContract] - public readonly partial struct TorquePerLength : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct TorquePerLength : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -834,16 +834,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Torqu return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(TorquePerLength left, TorquePerLength right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is TorquePerLength otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(TorquePerLength other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is TorquePerLength objTorquePerLength)) throw new ArgumentException("Expected type TorquePerLength.", nameof(obj)); + if (!(obj is TorquePerLength otherQuantity)) throw new ArgumentException("Expected type TorquePerLength.", nameof(obj)); - return CompareTo(objTorquePerLength); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(TorquePerLength other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -882,7 +946,7 @@ public int CompareTo(TorquePerLength other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1053,7 +1117,7 @@ private bool TryToUnit(TorquePerLengthUnit unit, out TorquePerLength? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs index fe876e38dc..3203e2e106 100644 --- a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Turbidity /// [DataContract] - public readonly partial struct Turbidity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Turbidity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -454,16 +454,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Turbi return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Turbidity left, Turbidity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Turbidity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Turbidity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Turbidity objTurbidity)) throw new ArgumentException("Expected type Turbidity.", nameof(obj)); + if (!(obj is Turbidity otherQuantity)) throw new ArgumentException("Expected type Turbidity.", nameof(obj)); - return CompareTo(objTurbidity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Turbidity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -502,7 +566,7 @@ public int CompareTo(Turbidity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -633,7 +697,7 @@ private bool TryToUnit(TurbidityUnit unit, out Turbidity? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs index 9dd24f9ba5..103c60e4ca 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Vitamin A: 1 IU is the biological equivalent of 0.3 µg retinol, or of 0.6 µg beta-carotene. /// [DataContract] - public readonly partial struct VitaminA : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct VitaminA : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -451,16 +451,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Vitam return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(VitaminA left, VitaminA right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is VitaminA otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(VitaminA other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is VitaminA objVitaminA)) throw new ArgumentException("Expected type VitaminA.", nameof(obj)); + if (!(obj is VitaminA otherQuantity)) throw new ArgumentException("Expected type VitaminA.", nameof(obj)); - return CompareTo(objVitaminA); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(VitaminA other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -499,7 +563,7 @@ public int CompareTo(VitaminA other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -630,7 +694,7 @@ private bool TryToUnit(VitaminAUnit unit, out VitaminA? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index 63f7be1c53..c8057b3827 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Volume is the quantity of three-dimensional space enclosed by some closed boundary, for example, the space that a substance (solid, liquid, gas, or plasma) or shape occupies or contains.[1] Volume is often quantified numerically using the SI derived unit, the cubic metre. The volume of a container is generally understood to be the capacity of the container, i. e. the amount of fluid (gas or liquid) that the container could hold, rather than the amount of space the container itself displaces. /// [DataContract] - public readonly partial struct Volume : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct Volume : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1467,16 +1467,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(Volume left, Volume right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Volume otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(Volume other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is Volume objVolume)) throw new ArgumentException("Expected type Volume.", nameof(obj)); + if (!(obj is Volume otherQuantity)) throw new ArgumentException("Expected type Volume.", nameof(obj)); - return CompareTo(objVolume); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(Volume other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1515,7 +1579,7 @@ public int CompareTo(Volume other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1748,7 +1812,7 @@ private bool TryToUnit(VolumeUnit unit, out Volume? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs index 089da3c52e..b336293255 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Concentration#Volume_concentration /// [DataContract] - public readonly partial struct VolumeConcentration : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct VolumeConcentration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -815,16 +815,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(VolumeConcentration left, VolumeConcentration right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is VolumeConcentration otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(VolumeConcentration other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is VolumeConcentration objVolumeConcentration)) throw new ArgumentException("Expected type VolumeConcentration.", nameof(obj)); + if (!(obj is VolumeConcentration otherQuantity)) throw new ArgumentException("Expected type VolumeConcentration.", nameof(obj)); - return CompareTo(objVolumeConcentration); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(VolumeConcentration other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -863,7 +927,7 @@ public int CompareTo(VolumeConcentration other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1032,7 +1096,7 @@ private bool TryToUnit(VolumeConcentrationUnit unit, out VolumeConcentration? co _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index 7c908f8629..42c389d36e 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// In physics and engineering, in particular fluid dynamics and hydrometry, the volumetric flow rate, (also known as volume flow rate, rate of fluid flow or volume velocity) is the volume of fluid which passes through a given surface per unit time. The SI unit is m³/s (cubic meters per second). In US Customary Units and British Imperial Units, volumetric flow rate is often expressed as ft³/s (cubic feet per second). It is usually represented by the symbol Q. /// [DataContract] - public readonly partial struct VolumeFlow : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct VolumeFlow : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -1637,16 +1637,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(VolumeFlow left, VolumeFlow right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is VolumeFlow otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(VolumeFlow other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is VolumeFlow objVolumeFlow)) throw new ArgumentException("Expected type VolumeFlow.", nameof(obj)); + if (!(obj is VolumeFlow otherQuantity)) throw new ArgumentException("Expected type VolumeFlow.", nameof(obj)); - return CompareTo(objVolumeFlow); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(VolumeFlow other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -1685,7 +1749,7 @@ public int CompareTo(VolumeFlow other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -1938,7 +2002,7 @@ private bool TryToUnit(VolumeFlowUnit unit, out VolumeFlow? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs index 765b992554..b0acba6eca 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// /// [DataContract] - public readonly partial struct VolumeFlowPerArea : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct VolumeFlowPerArea : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -470,16 +470,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(VolumeFlowPerArea left, VolumeFlowPerArea right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is VolumeFlowPerArea otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(VolumeFlowPerArea other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is VolumeFlowPerArea objVolumeFlowPerArea)) throw new ArgumentException("Expected type VolumeFlowPerArea.", nameof(obj)); + if (!(obj is VolumeFlowPerArea otherQuantity)) throw new ArgumentException("Expected type VolumeFlowPerArea.", nameof(obj)); - return CompareTo(objVolumeFlowPerArea); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(VolumeFlowPerArea other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -518,7 +582,7 @@ public int CompareTo(VolumeFlowPerArea other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -651,7 +715,7 @@ private bool TryToUnit(VolumeFlowPerAreaUnit unit, out VolumeFlowPerArea? conver _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs index 3feec62585..6e574a90b3 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// Volume, typically of fluid, that a container can hold within a unit of length. /// [DataContract] - public readonly partial struct VolumePerLength : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct VolumePerLength : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -565,16 +565,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(VolumePerLength left, VolumePerLength right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is VolumePerLength otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(VolumePerLength other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is VolumePerLength objVolumePerLength)) throw new ArgumentException("Expected type VolumePerLength.", nameof(obj)); + if (!(obj is VolumePerLength otherQuantity)) throw new ArgumentException("Expected type VolumePerLength.", nameof(obj)); - return CompareTo(objVolumePerLength); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(VolumePerLength other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -613,7 +677,7 @@ public int CompareTo(VolumePerLength other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -756,7 +820,7 @@ private bool TryToUnit(VolumePerLengthUnit unit, out VolumePerLength? converted) _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs index 1eb4353947..577f75c0e2 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs @@ -38,7 +38,7 @@ namespace UnitsNet /// https://en.wikipedia.org/wiki/Volumetric_heat_capacity /// [DataContract] - public readonly partial struct VolumetricHeatCapacity : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct VolumetricHeatCapacity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -606,16 +606,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(VolumetricHeatCapacity left, VolumetricHeatCapacity right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is VolumetricHeatCapacity otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(VolumetricHeatCapacity other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is VolumetricHeatCapacity objVolumetricHeatCapacity)) throw new ArgumentException("Expected type VolumetricHeatCapacity.", nameof(obj)); + if (!(obj is VolumetricHeatCapacity otherQuantity)) throw new ArgumentException("Expected type VolumetricHeatCapacity.", nameof(obj)); - return CompareTo(objVolumetricHeatCapacity); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(VolumetricHeatCapacity other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -654,7 +718,7 @@ public int CompareTo(VolumetricHeatCapacity other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -801,7 +865,7 @@ private bool TryToUnit(VolumetricHeatCapacityUnit unit, out VolumetricHeatCapaci _ => null! }; - return converted != null; + return converted is not null; } /// diff --git a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs index b3e92e35dc..e452f6d027 100644 --- a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs @@ -35,7 +35,7 @@ namespace UnitsNet /// A geometric property of an area that is used to determine the warping stress. /// [DataContract] - public readonly partial struct WarpingMomentOfInertia : IQuantity, IComparable, IComparable, IConvertible, IFormattable + public readonly partial struct WarpingMomentOfInertia : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable { /// /// The numeric value this quantity was constructed with. @@ -546,16 +546,80 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Warpi return left.Value > right.ToUnit(left.Unit).Value; } + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + 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("Consider using Equals(Angle, double, ComparisonType) to check equality across different units and to specify a floating-point number error tolerance.")] + public static bool operator !=(WarpingMomentOfInertia left, WarpingMomentOfInertia right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, 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.")] + public override bool Equals(object obj) + { + if (obj is null || !(obj is WarpingMomentOfInertia otherQuantity)) + return false; + + return Equals(otherQuantity); + } + /// + /// Indicates strict equality of two quantities, 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.")] + public bool Equals(WarpingMomentOfInertia other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(object obj) { if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is WarpingMomentOfInertia objWarpingMomentOfInertia)) throw new ArgumentException("Expected type WarpingMomentOfInertia.", nameof(obj)); + if (!(obj is WarpingMomentOfInertia otherQuantity)) throw new ArgumentException("Expected type WarpingMomentOfInertia.", nameof(obj)); - return CompareTo(objWarpingMomentOfInertia); + return CompareTo(otherQuantity); } - /// + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// public int CompareTo(WarpingMomentOfInertia other) { return _value.CompareTo(other.ToUnit(this.Unit).Value); @@ -594,7 +658,7 @@ public int CompareTo(WarpingMomentOfInertia other) /// /// /// Note that it is advised against specifying zero difference, due to the nature - /// of floating point operations and using System.Double internally. + /// of floating-point operations and using double internally. /// /// /// The other quantity to compare to. @@ -735,7 +799,7 @@ private bool TryToUnit(WarpingMomentOfInertiaUnit unit, out WarpingMomentOfInert _ => null! }; - return converted != null; + return converted is not null; } ///