Skip to content

Commit 87e5d7c

Browse files
authored
Exposing the operator IDivisionOperators<TSelf, TSelf, double> (#1613)
Exposing the operator `IDivisionOperators<TSelf, TSelf, double>` for all non-affine quantities (which already implement it). Unfortunately it's not possible for the operator to be part of the `IAritmeticQuantity` interface, as the compiler cannot verify that there isn't a collision with the `IDivisionOperators<TSelf, double, TSelf>`.
1 parent 8f8c0e6 commit 87e5d7c

File tree

128 files changed

+149
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+149
-146
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,36 +120,38 @@ private void GenerateInterfaceExtensions()
120120
IArithmeticQuantity<{_quantity.Name}, {_unitEnumName}>,");
121121
}
122122

123+
Writer.WL(@"
124+
#if NET7_0_OR_GREATER");
125+
if (!_quantity.IsAffine)
126+
{
127+
Writer.WL($@"
128+
IDivisionOperators<{_quantity.Name}, {_quantity.Name}, double>,");
129+
}
130+
123131
if (_quantity.Relations.Any(r => r.Operator is "*" or "/"))
124132
{
125-
Writer.WL(@$"
126-
#if NET7_0_OR_GREATER");
127-
foreach (var relation in _quantity.Relations)
133+
foreach (QuantityRelation relation in _quantity.Relations)
128134
{
129-
if (relation.LeftQuantity == _quantity)
135+
if (relation.LeftQuantity != _quantity) continue;
136+
switch (relation.Operator)
130137
{
131-
switch (relation.Operator)
132-
{
133-
case "*":
134-
Writer.W(@"
138+
case "*":
139+
Writer.W(@"
135140
IMultiplyOperators");
136-
break;
137-
case "/":
138-
Writer.W(@"
141+
break;
142+
case "/":
143+
Writer.W(@"
139144
IDivisionOperators");
140-
break;
141-
default:
142-
continue;
143-
}
144-
Writer.WL($"<{relation.LeftQuantity.Name}, {relation.RightQuantity.Name}, {relation.ResultQuantity.Name}>,");
145+
break;
146+
default:
147+
continue;
145148
}
146-
}
147149

148-
Writer.WL(@$"
149-
#endif");
150+
Writer.WL($"<{relation.LeftQuantity.Name}, {relation.RightQuantity.Name}, {relation.ResultQuantity.Name}>,");
151+
}
150152
}
153+
151154
Writer.WL(@$"
152-
#if NET7_0_OR_GREATER
153155
IComparisonOperators<{_quantity.Name}, {_quantity.Name}, bool>,
154156
IParsable<{_quantity.Name}>,
155157
#endif

UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Area.g.cs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/BitRate.g.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)