Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb22805

Browse files
committed
merging the removal of the EnumUtils (i'm keeping it for now)
2 parents faa0c1e + 7264a1f commit eb22805

File tree

260 files changed

+668
-664
lines changed

Some content is hidden

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

260 files changed

+668
-664
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private void GenerateQuantityInfo()
167167
var createDimensionsExpression = _isDimensionless
168168
? "BaseDimensions.Dimensionless"
169169
: $"new BaseDimensions({baseDimensions.L}, {baseDimensions.M}, {baseDimensions.T}, {baseDimensions.I}, {baseDimensions.Θ}, {baseDimensions.N}, {baseDimensions.J})";
170-
170+
171171
Writer.WL($@"
172172
/// <summary>
173173
/// Provides detailed information about the <see cref=""{_quantity.Name}""/> quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions.
@@ -227,7 +227,7 @@ public sealed class {quantityInfoClassName}: QuantityInfo<{_quantity.Name}, {_un
227227
/// <returns>An <see cref=""IEnumerable{{T}}""/> of <see cref=""UnitDefinition{{{_unitEnumName}}}""/> representing the default unit mappings for {_quantity.Name}.</returns>
228228
public static IEnumerable<UnitDefinition<{_unitEnumName}>> GetDefaultMappings()
229229
{{");
230-
230+
231231
foreach (Unit unit in _quantity.Units)
232232
{
233233
BaseUnits? baseUnits = unit.BaseUnits;
@@ -402,7 +402,7 @@ private void GenerateProperties()
402402
403403
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
404404
Enum IQuantity.Unit => Unit;
405-
405+
406406
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
407407
UnitKey IQuantity.UnitKey => UnitKey.ForUnit(Unit);
408408

CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal class UnitTestBaseClassGenerator : GeneratorBase
5151
/// Example: "LengthUnit.Centimeter".
5252
/// </summary>
5353
private readonly string _otherOrBaseUnitFullName;
54-
54+
5555
/// <summary>
5656
/// Indicates whether the quantity is dimensionless.
5757
/// </summary>
@@ -417,7 +417,7 @@ public void As_UnitSystem_ReturnsValueInDimensionlessUnit()
417417
var quantity = new {_quantity.Name}(value: 1, unit: {_baseUnitFullName});
418418
419419
var convertedValue = quantity.As(UnitSystem.SI);
420-
420+
421421
Assert.Equal(quantity.Value, convertedValue);
422422
}}
423423
@@ -463,7 +463,7 @@ public void ToUnitSystem_ReturnsValueInDimensionlessUnit()
463463
public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
464464
{{
465465
UnitSystem nullUnitSystem = null!;
466-
Assert.Multiple(() =>
466+
Assert.Multiple(() =>
467467
{{
468468
var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
469469
Assert.Throws<ArgumentNullException>(() => quantity.ToUnit(nullUnitSystem));
@@ -539,23 +539,23 @@ public virtual void ToUnit_UnitSystem_SI_ReturnsQuantityInSIUnits()
539539
IQuantity<{_unitEnumName}> convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
540540
541541
Assert.Equal(expectedUnit, convertedQuantity.Unit);
542-
Assert.Equal(expectedValue, convertedQuantity.Value);
542+
Assert.Equal(expectedValue, convertedQuantity.Value);
543543
}}, () =>
544544
{{
545545
IQuantity quantityToConvert = quantity;
546546
547547
IQuantity convertedQuantity = quantityToConvert.ToUnit(UnitSystem.SI);
548548
549549
Assert.Equal(expectedUnit, convertedQuantity.Unit);
550-
Assert.Equal(expectedValue, convertedQuantity.Value);
550+
Assert.Equal(expectedValue, convertedQuantity.Value);
551551
}});
552552
}}
553553
554554
[Fact]
555555
public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
556556
{{
557557
UnitSystem nullUnitSystem = null!;
558-
Assert.Multiple(() =>
558+
Assert.Multiple(() =>
559559
{{
560560
var quantity = new {_quantity.Name}(value: 1, unit: {_quantity.Name}.BaseUnit);
561561
Assert.Throws<ArgumentNullException>(() => quantity.ToUnit(nullUnitSystem));
@@ -758,7 +758,7 @@ public void ParseUnit_WithCulture(string culture, string abbreviation, {_unitEnu
758758
foreach (KeyValuePair<string, List<Unit>> ambiguousPair in abbreviations)
759759
{
760760
Writer.WL($@"
761-
[InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}] ");
761+
[InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}]");
762762
}
763763
}
764764
Writer.WL($@"
@@ -850,7 +850,7 @@ public void TryParseUnit_WithCulture(string culture, string abbreviation, {_unit
850850
foreach (KeyValuePair<string, List<Unit>> ambiguousPair in abbreviations)
851851
{
852852
Writer.WL($@"
853-
[InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}] ");
853+
[InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}]");
854854
}
855855
}
856856
Writer.WL($@"
@@ -1194,7 +1194,7 @@ public void Equals_WithNegativeTolerance_ThrowsArgumentOutOfRangeException()
11941194
[Fact]
11951195
public void HasAtLeastOneAbbreviationSpecified()
11961196
{{
1197-
var units = Enum.GetValues(typeof({_unitEnumName})).Cast<{_unitEnumName}>();
1197+
var units = EnumUtils.GetEnumValues<{_unitEnumName}>();
11981198
foreach (var unit in units)
11991199
{{
12001200
var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit);

UnitsNet.Tests/CustomCode/PressureTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void ReferencePressure_WithInvalidPressureReference_ThrowsNotImplementedE
167167
[Fact]
168168
public void ReferencePressureReferences_ReturnsTheExpectedEnumValues()
169169
{
170-
IEnumerable<PressureReference> expectedValues = Enum.GetValues(typeof(PressureReference)).Cast<PressureReference>();
170+
IEnumerable<PressureReference> expectedValues = EnumUtils.GetEnumValues<PressureReference>();
171171

172172
PressureReference[] actualValues = ReferencePressure.References;
173173

UnitsNet.Tests/EnumUtils.cs

Lines changed: 6 additions & 2 deletions
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;
@@ -8,9 +8,13 @@ namespace UnitsNet.Tests
88
{
99
public static class EnumUtils
1010
{
11-
public static T[] GetEnumValues<T>()
11+
public static T[] GetEnumValues<T>() where T : struct, Enum
1212
{
13+
#if NET
14+
return Enum.GetValues<T>();
15+
#else
1316
return Enum.GetValues(typeof (T)).Cast<T>().ToArray();
17+
#endif
1418
}
1519
}
1620
}

UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.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.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.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.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.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.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs

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

UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs

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

UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.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)