Skip to content

Commit

Permalink
Make casting decimal types neater
Browse files Browse the repository at this point in the history
  • Loading branch information
Muximize committed Jan 9, 2024
1 parent ef44d00 commit d6cb7d1
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ internal class QuantityGenerator : GeneratorBase
private readonly string _valueType;
private readonly Unit _baseUnit;

private readonly string[] _decimalTypes = { "BitRate", "Information", "Power" };

public QuantityGenerator(Quantity quantity)
{
_quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
Expand Down Expand Up @@ -794,8 +792,8 @@ private void GenerateRelationalOperators()
rightPart = "value";
}

var leftCast = _decimalTypes.Contains(relation.LeftQuantity.Name) ? "(double)" : "";
var rightCast = _decimalTypes.Contains(relation.RightQuantity.Name) ? "(double)" : "";
var leftCast = relation.LeftQuantity.ValueType is "decimal" ? "(double)" : string.Empty;
var rightCast = relation.RightQuantity.ValueType is "decimal" ? "(double)" : string.Empty;

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

Expand Down

0 comments on commit d6cb7d1

Please sign in to comment.