Skip to content

Commit 9d5c86f

Browse files
committed
merged from upstream
2 parents 784ef10 + 8e1a459 commit 9d5c86f

File tree

529 files changed

+12896
-1881
lines changed

Some content is hidden

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

529 files changed

+12896
-1881
lines changed

Build/bump-version-UnitsNet-major.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
22
SET scriptdir=%~dp0
3-
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump major
43
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.NumberExtensions.ps1 -bump major
4+
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump major
55
if %errorlevel% neq 0 exit /b %errorlevel%

Build/bump-version-UnitsNet-minor.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
22
SET scriptdir=%~dp0
3-
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump minor
43
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.NumberExtensions.ps1 -bump minor
4+
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump minor
55
if %errorlevel% neq 0 exit /b %errorlevel%

Build/bump-version-UnitsNet-patch.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
22
SET scriptdir=%~dp0
3-
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump patch
43
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.NumberExtensions.ps1 -bump patch
4+
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump patch
55
if %errorlevel% neq 0 exit /b %errorlevel%
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
22
SET scriptdir=%~dp0
3-
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump suffix
43
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.NumberExtensions.ps1 -bump suffix
4+
call powershell -NoProfile %scriptdir%\set-version-UnitsNet.ps1 -bump suffix
55
if %errorlevel% neq 0 exit /b %errorlevel%

CodeGen/CodeGen.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<TargetFramework>netcoreapp2.1</TargetFramework>
66
<LangVersion>latest</LangVersion>
77
<Nullable>enable</Nullable>
8+
<!-- Allow compile with various nullability warnings until fixed. -->
9+
<WarningsNotAsErrors>8600,8601,8603,8604,8618,8619,8625</WarningsNotAsErrors>
810
</PropertyGroup>
911

1012
<ItemGroup>

CodeGen/Generators/UnitsNetGen/IQuantityTestClassGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed under MIT No Attribution, see LICENSE file at the root.
1+
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;

CodeGen/Generators/UnitsNetGen/NumberExtensionsGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static class NumberTo{_quantityName}Extensions
5252
return Writer.ToString();
5353
}
5454

55-
private string GetObsoleteAttributeOrNull(string obsoleteText) =>
55+
private static string? GetObsoleteAttributeOrNull(string obsoleteText) =>
5656
string.IsNullOrWhiteSpace(obsoleteText) ?
5757
null :
58-
$"[System.Obsolete({obsoleteText})]";
58+
$"[System.Obsolete(\"{obsoleteText}\")]";
5959
}
6060
}

CodeGen/Generators/UnitsNetGen/NumberExtensionsTestClassGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override string Generate()
2828
using Xunit;
2929
3030
namespace UnitsNet.Tests
31-
{{
31+
{{
3232
public class NumberTo{_quantityName}ExtensionsTests
3333
{{");
3434

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ namespace UnitsNet
6969
/// {_quantity.XmlDocRemarks}
7070
/// </remarks>");
7171

72+
Writer.W(@$"
73+
public partial struct {_quantity.Name} : IQuantity<{_unitEnumName}>, ");
74+
if (_quantity.BaseType == "decimal")
75+
{
76+
Writer.W("IDecimalQuantity, ");
77+
}
78+
79+
Writer.WL($"IEquatable<{_quantity.Name}>, IComparable, IComparable<{_quantity.Name}>, IConvertible, IFormattable");
7280
Writer.WL($@"
73-
public partial struct {_quantity.Name} : IQuantity<{_unitEnumName}>, IEquatable<{_quantity.Name}>, IComparable, IComparable<{_quantity.Name}>, IConvertible, IFormattable
7481
{{
7582
/// <summary>
7683
/// The numeric value this quantity was constructed with.
@@ -117,7 +124,7 @@ private void GenerateStaticConstructor()
117124
");
118125

119126
Writer.WL($@"
120-
Info = new QuantityInfo<{_unitEnumName}>(QuantityType.{_quantity.Name},
127+
Info = new QuantityInfo<{_unitEnumName}>(""{_quantity.Name}"",
121128
new UnitInfo<{_unitEnumName}>[] {{");
122129

123130
foreach (var unit in _quantity.Units)
@@ -147,10 +154,10 @@ private void GenerateStaticConstructor()
147154
}
148155
}
149156

150-
Writer.WL(@"
151-
},
152-
BaseUnit, Zero, BaseDimensions);
153-
}
157+
Writer.WL($@"
158+
}},
159+
BaseUnit, Zero, BaseDimensions, QuantityType.{_quantity.Name});
160+
}}
154161
");
155162
}
156163

@@ -228,16 +235,19 @@ private void GenerateStaticProperties()
228235
/// <summary>
229236
/// Represents the largest possible value of {_quantity.Name}
230237
/// </summary>
238+
[Obsolete(""MaxValue and MinValue will be removed. Choose your own value or use nullability for unbounded lower/upper range checks. See discussion in https://github.com/angularsen/UnitsNet/issues/848."")]
231239
public static {_quantity.Name} MaxValue {{ get; }} = new {_quantity.Name}({_valueType}.MaxValue, BaseUnit);
232240
233241
/// <summary>
234242
/// Represents the smallest possible value of {_quantity.Name}
235243
/// </summary>
244+
[Obsolete(""MaxValue and MinValue will be removed. Choose your own value or use nullability for unbounded lower/upper range checks. See discussion in https://github.com/angularsen/UnitsNet/issues/848."")]
236245
public static {_quantity.Name} MinValue {{ get; }} = new {_quantity.Name}({_valueType}.MinValue, BaseUnit);
237246
238247
/// <summary>
239248
/// The <see cref=""QuantityType"" /> of this quantity.
240249
/// </summary>
250+
[Obsolete(""QuantityType will be removed in the future. Use Info property instead."")]
241251
public static QuantityType QuantityType {{ get; }} = QuantityType.{_quantity.Name};
242252
243253
/// <summary>
@@ -270,6 +280,11 @@ private void GenerateProperties()
270280
Writer.WL(@"
271281
double IQuantity.Value => (double) _value;
272282
");
283+
if (_quantity.BaseType == "decimal")
284+
Writer.WL(@"
285+
/// <inheritdoc cref=""IDecimalQuantity.Value""/>
286+
decimal IDecimalQuantity.Value => _value;
287+
");
273288

274289
Writer.WL($@"
275290
Enum IQuantity.Unit => Unit;
@@ -794,7 +809,7 @@ public bool Equals({_quantity.Name} other, double tolerance, ComparisonType comp
794809
/// <returns>A hash code for the current {_quantity.Name}.</returns>
795810
public override int GetHashCode()
796811
{{
797-
return new {{ QuantityType, Value, Unit }}.GetHashCode();
812+
return new {{ Info.Name, Value, Unit }}.GetHashCode();
798813
}}
799814
800815
#endregion
@@ -1106,6 +1121,8 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
11061121
return Unit;
11071122
else if(conversionType == typeof(QuantityType))
11081123
return {_quantity.Name}.QuantityType;
1124+
else if(conversionType == typeof(QuantityInfo))
1125+
return {_quantity.Name}.Info;
11091126
else if(conversionType == typeof(BaseDimensions))
11101127
return {_quantity.Name}.BaseDimensions;
11111128
else
@@ -1142,6 +1159,6 @@ ulong IConvertible.ToUInt64(IFormatProvider provider)
11421159
/// </summary>
11431160
private static string GetObsoleteAttributeOrNull(string obsoleteText) => string.IsNullOrWhiteSpace(obsoleteText)
11441161
? null
1145-
: $"[System.Obsolete({obsoleteText})]";
1162+
: $"[System.Obsolete(\"{obsoleteText}\")]";
11461163
}
11471164
}

CodeGen/Generators/UnitsNetGen/QuantityTypeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CodeGen.JsonTypes;
1+
using CodeGen.JsonTypes;
22

33
namespace CodeGen.Generators.UnitsNetGen
44
{

0 commit comments

Comments
 (0)