Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't throw on a different type equality check #67

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Source/Meadow.Units/Temperature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct Temperature :
/// <summary>
/// Absolute Zero temperature.
/// </summary>
public static Temperature AbsoluteZero = new (0, UnitType.Kelvin);
public static Temperature AbsoluteZero = new(0, UnitType.Kelvin);

/// <summary>
/// Creates a new <see cref="Temperature"/> object.
Expand Down Expand Up @@ -113,7 +113,12 @@ public double From(UnitType convertTo)
/// </summary>
/// <param name="obj">The object to compare</param>
/// <returns>true if equal</returns>
[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;
}

/// <summary>
/// Get hash of object
Expand Down Expand Up @@ -253,7 +258,7 @@ public double From(UnitType convertTo)
/// </summary>
/// <param name="obj">The other Temperature cast to object</param>
/// <returns>0 if equal</returns>
[Pure]
[Pure]
public int CompareTo(object obj)
{
if (obj is Temperature temperature)
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
Loading