Skip to content

Commit 2b9d456

Browse files
committed
Make casting decimal types neater
1 parent 5c9abed commit 2b9d456

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ internal class QuantityGenerator : GeneratorBase
1717
private readonly string _valueType;
1818
private readonly Unit _baseUnit;
1919

20-
private readonly string[] _decimalTypes = { "BitRate", "Information", "Power" };
21-
2220
public QuantityGenerator(Quantity quantity)
2321
{
2422
_quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
@@ -794,8 +792,8 @@ private void GenerateRelationalOperators()
794792
rightPart = "value";
795793
}
796794

797-
var leftCast = _decimalTypes.Contains(relation.LeftQuantity.Name) ? "(double)" : "";
798-
var rightCast = _decimalTypes.Contains(relation.RightQuantity.Name) ? "(double)" : "";
795+
var leftCast = relation.LeftQuantity.ValueType is "decimal" ? "(double)" : string.Empty;
796+
var rightCast = relation.RightQuantity.ValueType is "decimal" ? "(double)" : string.Empty;
799797

800798
var expression = $"{leftCast}{leftPart} {relation.Operator} {rightCast}{rightPart}";
801799

0 commit comments

Comments
 (0)