Skip to content

Commit 542122e

Browse files
jnyrupangularsen
authored andcommitted
Avoid extra evaluation of GetValueOrDefault (#429)
1 parent 011da2d commit 542122e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

UnitsNet/QuantityValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private QuantityValue(decimal val)
8989
public static explicit operator double(QuantityValue number)
9090
{
9191
// double -> decimal -> zero (since we can't implement the default struct ctor)
92-
return number._value.GetValueOrDefault((double) number._valueDecimal.GetValueOrDefault());
92+
return number._value ?? (double) number._valueDecimal.GetValueOrDefault();
9393
}
9494

9595
#endregion
@@ -99,7 +99,7 @@ public static explicit operator double(QuantityValue number)
9999
public static explicit operator decimal(QuantityValue number)
100100
{
101101
// decimal -> double -> zero (since we can't implement the default struct ctor)
102-
return number._valueDecimal.GetValueOrDefault((decimal) number._value.GetValueOrDefault());
102+
return number._valueDecimal ?? (decimal) number._value.GetValueOrDefault();
103103
}
104104

105105
#endregion

0 commit comments

Comments
 (0)