Skip to content

Commit a5bb56f

Browse files
committed
🛡️Restrict number extension methods to INumber<T>
1 parent 439c143 commit a5bb56f

File tree

133 files changed

+9490
-3010
lines changed

Some content is hidden

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

133 files changed

+9490
-3010
lines changed

CodeGen/Generators/UnitsNetGen/NumberExtensionsGenerator.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public string Generate()
2525
$@"
2626
using System;
2727
28+
#if NET7_0_OR_GREATER
29+
using System.Numerics;
30+
#endif
31+
2832
#nullable enable
2933
3034
namespace UnitsNet.NumberExtensions.NumberTo{_quantityName}
@@ -45,8 +49,12 @@ public static class NumberTo{_quantityName}Extensions
4549

4650
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit.ObsoleteText));
4751

48-
Writer.WL(2, $@"public static {_quantityName} {unit.PluralName}<T>(this T value) =>
49-
{_quantityName}.From{unit.PluralName}(Convert.ToDouble(value));
52+
Writer.WL(2, $@"public static {_quantityName} {unit.PluralName}<T>(this T value)
53+
where T : notnull
54+
#if NET7_0_OR_GREATER
55+
, INumber<T>
56+
#endif
57+
=> {_quantityName}.From{unit.PluralName}(Convert.ToDouble(value));
5058
");
5159
}
5260

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void GenerateStaticProperties()
257257

258258
Writer.WL($@"
259259
#endregion
260-
");
260+
");
261261
}
262262

263263
private void GenerateProperties()

Common/UnitDefinitions/Molarity.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Name": "Molarity",
33
"BaseUnit": "MolePerCubicMeter",
4-
"XmlDocSummary": "Molar concentration, also called molarity, amount concentration or substance concentration, is a measure of the concentration of a solute in a solution, or of any chemical species, in terms of amount of substance in a given volume. ",
4+
"XmlDocSummary": "Molar concentration, also called molarity, amount concentration or substance concentration, is a measure of the concentration of a solute in a solution, or of any chemical species, in terms of amount of substance in a given volume.",
55
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Molar_concentration",
66
"BaseDimensions": {
77
"L": -3,

UnitsNet.NanoFramework/GeneratedCode/Quantities/Molarity.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/UnitsNet.NumberExtensions.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<RootNamespace>UnitsNet.NumberExtensions.Tests</RootNamespace>
66
<LangVersion>latest</LangVersion>
77
<Nullable>enable</Nullable>

UnitsNet.NumberExtensions/GeneratedCode/NumberToAbsorbedDoseOfIonizingRadiationExtensions.g.cs

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

UnitsNet.NumberExtensions/GeneratedCode/NumberToAccelerationExtensions.g.cs

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

0 commit comments

Comments
 (0)