You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#1017
Reverted removing IEquatable and changed the implementation to strict equality and improved the xmldocs a bit.
Reverts commit f3c7e25.
"🔥 Remove IEquatable<T> and equality operators/methods"
/// <summary>Returns true if both <see cref=""Value"" /> and <see cref=""Unit"" /> are exactly equal for both quantities.</summary>
756
+
/// <remarks>Consider using <see cref=""Equals({_quantity.Name}, double, ComparisonType)""/> for comparing floating point values with rounding error tolerances.</remarks>
757
+
public static bool operator ==({_quantity.Name} left, {_quantity.Name} right)
758
+
{{
759
+
return left.Equals(right);
760
+
}}
761
+
762
+
/// <summary>Returns true if either <see cref=""Value"" /> or <see cref=""Unit"" /> are not exactly equal for both quantities.</summary>
763
+
/// <remarks>Consider using <see cref=""Equals({_quantity.Name}, double, ComparisonType)""/> for comparing floating point values with rounding error tolerances.</remarks>
764
+
public static bool operator !=({_quantity.Name} left, {_quantity.Name} right)
765
+
{{
766
+
return !(left == right);
767
+
}}
768
+
769
+
/// <summary>Compares the current <see cref=""{_quantity.Name}""/> 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.</summary>
770
+
/// <param name=""obj"">An object to compare with this instance.</param>
/// <item><term> Less than zero</term><description> This instance precedes <paramref name=""obj"" /> in the sort order.</description></item>
778
+
/// <item><term> Zero</term><description> This instance occurs in the same position in the sort order as <paramref name=""obj"" />.</description></item>
779
+
/// <item><term> Greater than zero</term><description> This instance follows <paramref name=""obj"" /> in the sort order.</description></item>
780
+
/// </list>
781
+
/// </returns>
756
782
public int CompareTo(object obj)
757
783
{{
758
784
if (obj is null) throw new ArgumentNullException(nameof(obj));
@@ -761,12 +787,40 @@ public int CompareTo(object obj)
761
787
return CompareTo(obj{_quantity.Name});
762
788
}}
763
789
764
-
/// <inheritdoc />
790
+
/// <summary>Compares the current <see cref=""{_quantity.Name}""/> with another <see cref=""{_quantity.Name}""/> 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.</summary>
791
+
/// <param name=""other"">A quantity to compare with this instance.</param>
792
+
/// <returns>A value that indicates the relative order of the quantities being compared. The return value has these meanings:
/// <item><term> Less than zero</term><description> This instance precedes <paramref name=""other"" /> in the sort order.</description></item>
796
+
/// <item><term> Zero</term><description> This instance occurs in the same position in the sort order as <paramref name=""other"" />.</description></item>
797
+
/// <item><term> Greater than zero</term><description> This instance follows <paramref name=""other"" /> in the sort order.</description></item>
/// <summary>Returns true if either <see cref=""Value"" /> or <see cref=""Unit"" /> are not exactly equal for both quantities.</summary>
807
+
/// <remarks>Consider using <see cref=""Equals({_quantity.Name}, double, ComparisonType)""/> for comparing floating point values with rounding error tolerances.</remarks>
808
+
public override bool Equals(object obj)
809
+
{{
810
+
if(obj is null || !(obj is {_quantity.Name} obj{_quantity.Name}))
811
+
return false;
812
+
813
+
return Equals(obj{_quantity.Name});
814
+
}}
815
+
816
+
/// <inheritdoc />
817
+
/// <summary>Returns true if either <see cref=""Value"" /> or <see cref=""Unit"" /> are not exactly equal for both quantities.</summary>
818
+
/// <remarks>Consider using <see cref=""Equals({_quantity.Name}, double, ComparisonType)""/> for comparing floating point values with rounding error tolerances.</remarks>
819
+
public bool Equals({_quantity.Name} other)
820
+
{{
821
+
return new {{ Value, Unit }}.Equals(new {{ other.Value, other.Unit }});
822
+
}}
823
+
770
824
/// <summary>
771
825
/// <para>
772
826
/// Compare equality to another {_quantity.Name} within the given absolute or relative tolerance.
0 commit comments