Skip to content

Commit 1c5e8fe

Browse files
authored
ToUnit for IValueQuantity<T> should return IValueQuantity<T> (#1224)
1 parent 206e4fa commit 1c5e8fe

File tree

128 files changed

+1552
-65
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

+1552
-65
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,18 @@ IQuantity IQuantity.ToUnit(Enum unit)
10931093
/// <inheritdoc />
10941094
IQuantity<{_unitEnumName}> IQuantity<{_unitEnumName}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
10951095
1096+
/// <inheritdoc />
1097+
IValueQuantity<{_quantity.ValueType}> IValueQuantity<{_quantity.ValueType}>.ToUnit(Enum unit)
1098+
{{
1099+
if (unit is not {_unitEnumName} typedUnit)
1100+
throw new ArgumentException($""The given unit is of type {{unit.GetType()}}. Only {{typeof({_unitEnumName})}} is supported."", nameof(unit));
1101+
1102+
return ToUnit(typedUnit);
1103+
}}
1104+
1105+
/// <inheritdoc />
1106+
IValueQuantity<{_quantity.ValueType}> IValueQuantity<{_quantity.ValueType}>.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem);
1107+
10961108
#endregion
10971109
");
10981110
}

UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCharge.g.cs

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

UnitsNet.NanoFramework/GeneratedCode/Units/ElectricChargeUnit.g.cs

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

UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricChargeExtensionsTest.g.cs

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

UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricChargeExtensions.g.cs

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

0 commit comments

Comments
 (0)