Skip to content

Commit b560b48

Browse files
committed
Merge remote-tracking branch 'origin/master' into AndreasLeeb/genericMath
2 parents 9fe4029 + d53ea95 commit b560b48

File tree

363 files changed

+991
-2893
lines changed

Some content is hidden

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

363 files changed

+991
-2893
lines changed

Build/build-functions.psm1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Start-Build([boolean] $IncludeNanoFramework = $false) {
3737
$appVeyorLoggerNetCoreDll = "C:\Program Files\AppVeyor\BuildAgent\dotnetcore\Appveyor.MSBuildLogger.dll"
3838
$appVeyorLoggerArg = if (Test-Path "$appVeyorLoggerNetCoreDll") { "/logger:$appVeyorLoggerNetCoreDll" } else { "" }
3939

40-
dotnet build --configuration Release "$root\UnitsNet.sln" $fileLoggerArg $appVeyorLoggerArg
40+
dotnet build --configuration Release /p:ContinuousIntegrationBuild=true "$root\UnitsNet.sln" $fileLoggerArg $appVeyorLoggerArg
4141
if ($lastexitcode -ne 0) { exit 1 }
4242

4343
if (-not $IncludeNanoFramework)
@@ -53,7 +53,7 @@ function Start-Build([boolean] $IncludeNanoFramework = $false) {
5353
# msbuild does not auto-restore nugets for this project type
5454
& "$nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln"
5555
# now build
56-
& "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" $fileLoggerArg $appVeyorLoggerArg
56+
& "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" /p:ContinuousIntegrationBuild=true $fileLoggerArg $appVeyorLoggerArg
5757
if ($lastexitcode -ne 0) { exit 1 }
5858
}
5959

@@ -83,6 +83,7 @@ function Start-Tests {
8383

8484
# Create coverage report for this test project
8585
& dotnet dotcover test `
86+
--no-build `
8687
--dotCoverFilters="+:module=UnitsNet*;-:module=*Tests" `
8788
--dotCoverOutput="$coverageReportFile" `
8889
--dcReportType=DetailedXML
@@ -106,7 +107,12 @@ function Start-PackNugets([boolean] $IncludeNanoFramework = $false) {
106107

107108
write-host -foreground blue "Pack nugets...`n---"
108109
foreach ($projectPath in $projectPaths) {
109-
dotnet pack --configuration Release -o $nugetOutDir "$root\$projectPath"
110+
dotnet pack --configuration Release `
111+
--no-build `
112+
--output $nugetOutDir `
113+
/p:ContinuousIntegrationBuild=true `
114+
"$root\$projectPath"
115+
110116
if ($lastexitcode -ne 0) { exit 1 }
111117
}
112118

Build/push-nugets.bat

Lines changed: 0 additions & 4 deletions
This file was deleted.

Build/push-nugets.ps1

Lines changed: 0 additions & 7 deletions
This file was deleted.

CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public string Generate()
2525
<package xmlns=""http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"">
2626
<metadata>
2727
<id>UnitsNet.nanoFramework.{_quantity.Name}</id>
28-
<version>5.0.0-rc005</version>
28+
<version>5.0.0-rc007</version>
2929
<title>Units.NET {_quantity.Name} - nanoFramework</title>
3030
<authors>Andreas Gullberg Larsen,nanoFramework project contributors</authors>
3131
<owners>UnitsNet</owners>

CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace CodeGen.Generators.NanoFrameworkGen
1+
namespace CodeGen.Generators.NanoFrameworkGen
62
{
73
class PropertyGenerator : GeneratorBase
84
{

CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using CodeGen.Helpers;
53
using CodeGen.JsonTypes;
64

@@ -37,6 +35,7 @@ namespace UnitsNet
3735
/// <remarks>
3836
/// {_quantity.XmlDocRemarks}
3937
/// </remarks>");
38+
Writer.WLIfText(1, GetObsoleteAttributeOrNull(_quantity));
4039

4140
Writer.WL($@"
4241
public struct {_quantity.Name}
@@ -125,10 +124,9 @@ private void GenerateConversionProperties()
125124
Writer.WL(@"
126125
#region Conversion Properties
127126
");
128-
foreach (var unit in _quantity.Units)
127+
foreach (Unit unit in _quantity.Units)
129128
{
130-
if (unit.SkipConversionGeneration)
131-
continue;
129+
if (unit.SkipConversionGeneration) continue;
132130

133131
Writer.WL($@"
134132
/// <summary>
@@ -151,10 +149,9 @@ private void GenerateStaticFactoryMethods()
151149
Writer.WL(@"
152150
#region Static Factory Methods
153151
");
154-
foreach (var unit in _quantity.Units)
152+
foreach (Unit unit in _quantity.Units)
155153
{
156-
if (unit.SkipConversionGeneration)
157-
continue;
154+
if (unit.SkipConversionGeneration) continue;
158155

159156
var valueParamName = unit.PluralName.ToLowerInvariant();
160157
Writer.WL($@"
@@ -214,7 +211,7 @@ private void GenerateConversionMethods()
214211
{{
215212
return Unit switch
216213
{{");
217-
foreach (var unit in _quantity.Units)
214+
foreach (Unit unit in _quantity.Units)
218215
{
219216
var func = unit.FromUnitToBaseFunc.Replace("{x}", "_value");
220217
Writer.WL($@"
@@ -235,7 +232,7 @@ private void GenerateConversionMethods()
235232
236233
return unit switch
237234
{{");
238-
foreach (var unit in _quantity.Units)
235+
foreach (Unit unit in _quantity.Units)
239236
{
240237
var func = unit.FromBaseToUnitFunc.Replace("{x}", "baseUnitValue");
241238
Writer.WL($@"
@@ -251,16 +248,16 @@ private void GenerateConversionMethods()
251248
}
252249

253250
/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
254-
internal static string? GetObsoleteAttributeOrNull(Quantity quantity) => GetObsoleteAttributeOrNull(quantity.ObsoleteText);
251+
private static string? GetObsoleteAttributeOrNull(Quantity quantity) => GetObsoleteAttributeOrNull(quantity.ObsoleteText);
255252

256253
/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
257-
internal static string? GetObsoleteAttributeOrNull(Unit unit) => GetObsoleteAttributeOrNull(unit.ObsoleteText);
254+
private static string? GetObsoleteAttributeOrNull(Unit unit) => GetObsoleteAttributeOrNull(unit.ObsoleteText);
258255

259256
/// <summary>
260257
/// Returns the Obsolete attribute if ObsoleteText has been defined on the JSON input - otherwise returns empty string
261258
/// It is up to the consumer to wrap any padding/new lines in order to keep to correct indentation formats
262259
/// </summary>
263-
private static string? GetObsoleteAttributeOrNull(string obsoleteText) => string.IsNullOrWhiteSpace(obsoleteText)
260+
private static string? GetObsoleteAttributeOrNull(string? obsoleteText) => string.IsNullOrWhiteSpace(obsoleteText)
264261
? null
265262
: $"[Obsolete(\"{obsoleteText}\")]";
266263

CodeGen/Generators/NanoFrameworkGen/UnitTypeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace UnitsNet.Units
2929
3030
public enum {_unitEnumName}
3131
{{");
32-
foreach (var unit in _quantity.Units)
32+
foreach (Unit unit in _quantity.Units)
3333
{
3434
if (unit.XmlDocSummary.HasText())
3535
{
@@ -59,7 +59,7 @@ public enum {_unitEnumName}
5959
return Writer.ToString();
6060
}
6161

62-
private string? GetObsoleteAttributeOrNull(string obsoleteText) =>
62+
private static string? GetObsoleteAttributeOrNull(string? obsoleteText) =>
6363
string.IsNullOrWhiteSpace(obsoleteText) ?
6464
null :
6565
$"[System.Obsolete(\"{obsoleteText}\")]";

CodeGen/Generators/NanoFrameworkGenerator.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void Generate(string rootDir, Quantity[] quantities, QuantityNameT
6767
new Regex(@"<version>(?<version>[\d.]+)(?<suffix>-[a-z\d]+)?<\/version>", RegexOptions.IgnoreCase),
6868
"projectVersion");
6969

70-
foreach (var quantity in quantities)
70+
foreach (Quantity quantity in quantities)
7171
{
7272
var projectPath = Path.Combine(outputDir, quantity.Name);
7373
Directory.CreateDirectory(projectPath);
@@ -95,7 +95,6 @@ public static void Generate(string rootDir, Quantity[] quantities, QuantityNameT
9595
{
9696
var replacements = new Dictionary<string, string>
9797
{
98-
//{ "(\\)sdecimal(\\s)", "$1float$2" }
9998
{ "(\\d)m", "$1d" },
10099
{ "(\\d)M", "$1d" },
101100
{ " decimal ", " double " },
@@ -119,22 +118,22 @@ public static void Generate(string rootDir, Quantity[] quantities, QuantityNameT
119118
}
120119

121120
/// <summary>
122-
/// Updates existing nanoFramework projects and nuspecs with the latest versions.
121+
/// Updates existing nanoFramework projects and nuspec files with the latest versions.
123122
/// </summary>
124123
/// <param name="rootDir">The root directory</param>
125-
/// <param name="quantities">The quantities to update nuspecs</param>
124+
/// <param name="quantities">The quantities to update nuspec files</param>
126125
public static bool UpdateNanoFrameworkDependencies(
127126
string rootDir,
128127
Quantity[] quantities)
129128
{
130129
// working path
131-
string path = Path.Combine(rootDir, "UnitsNet.NanoFramework\\GeneratedCode");
130+
var path = Path.Combine(rootDir, "UnitsNet.NanoFramework\\GeneratedCode");
132131

133132
Log.Information("");
134133
Log.Information("Restoring .NET nanoFramework projects");
135134

136135
// run nuget CLI
137-
var nugetCLI = new Process
136+
using var nugetRestore = new Process
138137
{
139138
StartInfo = new ProcessStartInfo
140139
{
@@ -147,7 +146,7 @@ public static bool UpdateNanoFrameworkDependencies(
147146
};
148147

149148
// start nuget CLI and wait for exit
150-
if (!nugetCLI.Start())
149+
if (!nugetRestore.Start())
151150
{
152151
Log.Information("");
153152
Log.Information("Failed to start nuget CLI to restore .NET nanoFramework projects");
@@ -156,25 +155,25 @@ public static bool UpdateNanoFrameworkDependencies(
156155
else
157156
{
158157
// wait for exit, within 2 minutes
159-
if (!nugetCLI.WaitForExit((int)TimeSpan.FromMinutes(2).TotalMilliseconds))
158+
if (!nugetRestore.WaitForExit((int)TimeSpan.FromMinutes(2).TotalMilliseconds))
160159
{
161160
Log.Information("");
162161
Log.Information("Failed to complete execution of nuget CLI to restore .NET nanoFramework projects");
163162
Log.Information("");
164163
}
165164
else
166165
{
167-
if (nugetCLI.ExitCode == 0)
166+
if (nugetRestore.ExitCode == 0)
168167
{
169168
Log.Information("Done!");
170169
Log.Information("");
171170
}
172171
else
173172
{
174173
Log.Information("");
175-
Log.Information($"nuget CLI executed with {nugetCLI.ExitCode} exit code");
174+
Log.Information("nuget CLI executed with {ExitCode} exit code", nugetRestore.ExitCode);
176175

177-
Log.Information(nugetCLI.StandardError.ReadToEnd());
176+
Log.Information("{StandardError}", nugetRestore.StandardError.ReadToEnd());
178177

179178
return false;
180179
}
@@ -185,7 +184,7 @@ public static bool UpdateNanoFrameworkDependencies(
185184
Log.Information("Updating .NET nanoFramework references using nuget CLI");
186185

187186
// run nuget CLI to perform update
188-
nugetCLI = new Process
187+
using var nugetUpdate = new Process
189188
{
190189
StartInfo = new ProcessStartInfo
191190
{
@@ -198,7 +197,7 @@ public static bool UpdateNanoFrameworkDependencies(
198197
};
199198

200199
// start nuget CLI and wait for exit
201-
if (!nugetCLI.Start())
200+
if (!nugetUpdate.Start())
202201
{
203202
Log.Information("");
204203
Log.Information("Failed to start nuget CLI to update .NET nanoFramework projects");
@@ -207,23 +206,23 @@ public static bool UpdateNanoFrameworkDependencies(
207206
else
208207
{
209208
// wait for exit, within 2 minutes
210-
if (!nugetCLI.WaitForExit((int)TimeSpan.FromMinutes(2).TotalMilliseconds))
209+
if (!nugetUpdate.WaitForExit((int)TimeSpan.FromMinutes(2).TotalMilliseconds))
211210
{
212211
Log.Information("");
213212
Log.Information("Failed to complete execution of nuget CLI to update .NET nanoFramework projects");
214213
Log.Information("");
215214
}
216215
else
217216
{
218-
if (nugetCLI.ExitCode == 0)
217+
if (nugetUpdate.ExitCode == 0)
219218
{
220219
Log.Information("Done!");
221220
Log.Information("");
222221

223222
Log.Information("Updating .NET nanoFramework nuspec files");
224223
Log.Information("");
225224

226-
foreach (var quantity in quantities)
225+
foreach (Quantity quantity in quantities)
227226
{
228227
var projectPath = Path.Combine(path, quantity.Name);
229228

@@ -254,9 +253,9 @@ public static bool UpdateNanoFrameworkDependencies(
254253
else
255254
{
256255
Log.Information("");
257-
Log.Information($"nuget CLI executed with {nugetCLI.ExitCode} exit code");
256+
Log.Information("nuget CLI executed with {ExitCode} exit code", nugetUpdate.ExitCode);
258257

259-
Log.Information(nugetCLI.StandardError.ReadToEnd());
258+
Log.Information("{StandardError}", nugetUpdate.StandardError.ReadToEnd());
260259

261260
return false;
262261
}
@@ -272,7 +271,7 @@ public static bool UpdateNanoFrameworkDependencies(
272271
private static NanoFrameworkVersions ParseCurrentNanoFrameworkVersions(string rootDir)
273272
{
274273
// Angle has both mscorlib and System.Math dependency
275-
string generatedCodePath = Path.Combine(rootDir, "UnitsNet.NanoFramework", "GeneratedCode");
274+
var generatedCodePath = Path.Combine(rootDir, "UnitsNet.NanoFramework", "GeneratedCode");
276275
var angleProjectFile = Path.Combine(generatedCodePath, "Angle", "Angle.nfproj");
277276
var projectFileContent = File.ReadAllText(angleProjectFile);
278277

@@ -305,7 +304,7 @@ private static string ParseVersion(
305304
string descriptiveName,
306305
bool throwOnFailure = true)
307306
{
308-
var match = versionRegex.Match(projectFileContent);
307+
Match match = versionRegex.Match(projectFileContent);
309308

310309
if (!match.Success && throwOnFailure)
311310
{
@@ -321,8 +320,7 @@ private static void GeneratePackageConfig(
321320
string mscorlibNuGetVersion,
322321
string mathNuGetVersion)
323322
{
324-
string filePath = Path.Combine(projectPath, "packages.config");
325-
323+
var filePath = Path.Combine(projectPath, "packages.config");
326324
var content = GeneratePackageConfigFile(quantityName, mscorlibNuGetVersion, mathNuGetVersion);
327325

328326
File.WriteAllText(filePath, content);
@@ -334,7 +332,7 @@ private static void GenerateNuspec(
334332
string mscorlibNuGetVersion,
335333
string mathNuGetVersion)
336334
{
337-
string filePath = Path.Combine(projectPath, $"UnitsNet.NanoFramework.{quantity.Name}.nuspec");
335+
var filePath = Path.Combine(projectPath, $"UnitsNet.NanoFramework.{quantity.Name}.nuspec");
338336

339337
var content = new NuspecGenerator(
340338
quantity,

CodeGen/Generators/QuantityJsonFilesParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static void OrderUnitsByName(Quantity quantity)
6565

6666
private static void FixConversionFunctionsForDecimalValueTypes(Quantity quantity)
6767
{
68-
foreach (var u in quantity.Units)
68+
foreach (Unit u in quantity.Units)
6969
// Use decimal for internal calculations if base type is not double, such as for long or int.
7070
{
7171
if (string.Equals(quantity.ValueType, "decimal", StringComparison.OrdinalIgnoreCase))
@@ -80,8 +80,8 @@ private static void FixConversionFunctionsForDecimalValueTypes(Quantity quantity
8080
private static void AddPrefixUnits(Quantity quantity)
8181
{
8282
var unitsToAdd = new List<Unit>();
83-
foreach (var unit in quantity.Units)
84-
foreach (var prefix in unit.Prefixes)
83+
foreach (Unit unit in quantity.Units)
84+
foreach (Prefix prefix in unit.Prefixes)
8585
{
8686
try
8787
{
@@ -118,7 +118,7 @@ private static Localization[] GetLocalizationForPrefixUnit(IEnumerable<Localizat
118118
{
119119
return localizations.Select(loc =>
120120
{
121-
if (loc.TryGetAbbreviationsForPrefix(prefixInfo.Prefix, out string[] unitAbbreviationsForPrefix))
121+
if (loc.TryGetAbbreviationsForPrefix(prefixInfo.Prefix, out string[]? unitAbbreviationsForPrefix))
122122
{
123123
return new Localization
124124
{

CodeGen/Generators/UnitsNetGen/NumberExtensionsGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static class NumberTo{_quantityName}Extensions
5555
return Writer.ToString();
5656
}
5757

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

CodeGen/Generators/UnitsNetGen/NumberExtensionsTestClassGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class NumberTo{_quantityName}ExtensionsTests
5050
return Writer.ToString();
5151
}
5252

53-
private static string? GetObsoleteAttributeOrNull(string obsoleteText) =>
53+
private static string? GetObsoleteAttributeOrNull(string? obsoleteText) =>
5454
string.IsNullOrWhiteSpace(obsoleteText) ?
5555
null :
5656
$"[Obsolete(\"{obsoleteText}\")]";

0 commit comments

Comments
 (0)