From f5104f8c2f0b27b93d621bcab214ba77a8a4031e Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Tue, 17 Sep 2024 10:37:25 -0600 Subject: [PATCH] don't throw on a different type equality check --- Source/Meadow.Units/Temperature.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/Meadow.Units/Temperature.cs b/Source/Meadow.Units/Temperature.cs index 8a3e70e..ee60d14 100644 --- a/Source/Meadow.Units/Temperature.cs +++ b/Source/Meadow.Units/Temperature.cs @@ -23,7 +23,7 @@ public struct Temperature : /// /// Absolute Zero temperature. /// - public static Temperature AbsoluteZero = new (0, UnitType.Kelvin); + public static Temperature AbsoluteZero = new(0, UnitType.Kelvin); /// /// Creates a new object. @@ -113,7 +113,12 @@ public double From(UnitType convertTo) /// /// The object to compare /// true if equal - [Pure] public override bool Equals(object obj) => CompareTo(obj) == 0; + [Pure] + public override bool Equals(object obj) + { + if (obj is not Temperature) { return false; } + return CompareTo(obj) == 0; + } /// /// Get hash of object @@ -253,7 +258,7 @@ public double From(UnitType convertTo) /// /// The other Temperature cast to object /// 0 if equal - [Pure] + [Pure] public int CompareTo(object obj) { if (obj is Temperature temperature) @@ -391,7 +396,7 @@ public int CompareTo(object obj) [Pure] public int CompareTo(double? other) { - return (other is null) ? -1 : (Value).CompareTo(other.Value); + return (other is null) ? -1 : Value.CompareTo(other.Value); } ///