diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
index 63cab0add0..a3be4f0208 100644
--- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
+++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
@@ -565,7 +565,7 @@ public static bool TryParse([NotNullWhen(true)]string? str, IFormatProvider? pro
/// Error parsing string.
public static {_unitEnumName} ParseUnit(string str, IFormatProvider? provider)
{{
- return UnitsNetSetup.Default.UnitParser.Parse<{_unitEnumName}>(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}}
///
@@ -586,7 +586,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out {_unitEnumNa
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out {_unitEnumName} unit)
{{
- return UnitsNetSetup.Default.UnitParser.TryParse<{_unitEnumName}>(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}}
#endregion
diff --git a/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs b/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs
index 26e6d9722b..4ca3b7a855 100644
--- a/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs
+++ b/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs
@@ -47,25 +47,4 @@ public string WithSpecificQuantityAndCustomMapping()
cache.MapUnitToDefaultAbbreviation(MassUnit.Gram, "zz");
return cache.GetDefaultAbbreviation(MassUnit.Gram);
}
-
- [Benchmark]
- public string DefaultWithoutLookup()
- {
- var cache = UnitAbbreviationsCache.CreateDefault();
- return cache.GetAbbreviations(Mass.Info.BaseUnitInfo)[0];
- }
-
- [Benchmark]
- public string EmptyWithoutLookup()
- {
- var cache = new UnitAbbreviationsCache();
- return cache.GetAbbreviations(Mass.Info.BaseUnitInfo)[0];
- }
-
- [Benchmark]
- public string WithSpecificQuantityWithoutLookup()
- {
- var cache = new UnitAbbreviationsCache([Mass.Info]);
- return cache.GetAbbreviations(Mass.Info.BaseUnitInfo)[0];
- }
}
diff --git a/UnitsNet.Tests/CustomQuantities/HowMuch.cs b/UnitsNet.Tests/CustomQuantities/HowMuch.cs
index 233c97b1f1..233c2490ef 100644
--- a/UnitsNet.Tests/CustomQuantities/HowMuch.cs
+++ b/UnitsNet.Tests/CustomQuantities/HowMuch.cs
@@ -27,7 +27,7 @@ public HowMuch(double value, HowMuchUnit unit)
public BaseDimensions Dimensions => BaseDimensions.Dimensionless;
- public QuantityInfo QuantityInfo => new(
+ public static QuantityInfo Info = new(
nameof(HowMuch),
typeof(HowMuchUnit),
new UnitInfo[]
@@ -40,6 +40,11 @@ public HowMuch(double value, HowMuchUnit unit)
Zero,
BaseDimensions.Dimensionless);
+ QuantityInfo IQuantity.QuantityInfo
+ {
+ get { return Info; }
+ }
+
public double As(Enum unit) => Convert.ToDouble(unit);
public double As(UnitSystem unitSystem) => throw new NotImplementedException();
diff --git a/UnitsNet.Tests/QuantityParserTests.cs b/UnitsNet.Tests/QuantityParserTests.cs
index b56fa10d90..e63f29fdb7 100644
--- a/UnitsNet.Tests/QuantityParserTests.cs
+++ b/UnitsNet.Tests/QuantityParserTests.cs
@@ -13,13 +13,13 @@ public class QuantityParserTests
[Fact]
public void Parse_WithSingleCaseInsensitiveMatch_ParsesWithMatchedUnit()
{
- var unitAbbreviationsCache = new UnitAbbreviationsCache();
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "foo");
var quantityParser = new QuantityParser(unitAbbreviationsCache);
HowMuch q = quantityParser.Parse("1 FOO",
null,
- (value, unit) => new HowMuch((double) value, unit));
+ (value, unit) => new HowMuch(value, unit));
Assert.Equal(HowMuchUnit.Some, q.Unit);
Assert.Equal(1, q.Value);
@@ -28,14 +28,14 @@ public void Parse_WithSingleCaseInsensitiveMatch_ParsesWithMatchedUnit()
[Fact]
public void Parse_WithOneCaseInsensitiveMatchAndOneExactMatch_ParsesWithTheExactMatchUnit()
{
- var unitAbbreviationsCache = new UnitAbbreviationsCache();
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "foo");
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.ATon, "FOO");
var quantityParser = new QuantityParser(unitAbbreviationsCache);
HowMuch q = quantityParser.Parse("1 FOO",
null,
- (value, unit) => new HowMuch((double) value, unit));
+ (value, unit) => new HowMuch(value, unit));
Assert.Equal(HowMuchUnit.ATon, q.Unit);
Assert.Equal(1, q.Value);
@@ -44,14 +44,14 @@ public void Parse_WithOneCaseInsensitiveMatchAndOneExactMatch_ParsesWithTheExact
[Fact]
public void Parse_WithMultipleCaseInsensitiveMatchesButNoExactMatches_ThrowsAmbiguousUnitParseException()
{
- var unitAbbreviationsCache = new UnitAbbreviationsCache();
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "foo");
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.ATon, "FOO");
var quantityParser = new QuantityParser(unitAbbreviationsCache);
void Act()
{
- quantityParser.Parse("1 Foo", null, (value, unit) => new HowMuch((double) value, unit));
+ quantityParser.Parse("1 Foo", null, (value, unit) => new HowMuch(value, unit));
}
var ex = Assert.Throws(Act);
@@ -61,13 +61,13 @@ void Act()
[Fact]
public void Parse_MappedCustomUnit()
{
- var unitAbbreviationsCache = new UnitAbbreviationsCache();
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh");
var quantityParser = new QuantityParser(unitAbbreviationsCache);
HowMuch q = quantityParser.Parse("1 fooh",
null,
- (value, unit) => new HowMuch((double) value, unit));
+ (value, unit) => new HowMuch(value, unit));
Assert.Equal(HowMuchUnit.Some, q.Unit);
Assert.Equal(1, q.Value);
@@ -76,13 +76,13 @@ public void Parse_MappedCustomUnit()
[Fact]
public void TryParse_MappedCustomUnit()
{
- var unitAbbreviationsCache = new UnitAbbreviationsCache();
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh");
var quantityParser = new QuantityParser(unitAbbreviationsCache);
bool success = quantityParser.TryParse("1 fooh",
null,
- (value, unit) => new HowMuch((double) value, unit),
+ (value, unit) => new HowMuch(value, unit),
out HowMuch q);
Assert.True(success);
diff --git a/UnitsNet.Tests/QuantityTests.cs b/UnitsNet.Tests/QuantityTests.cs
index 22154965fb..e50a25ba23 100644
--- a/UnitsNet.Tests/QuantityTests.cs
+++ b/UnitsNet.Tests/QuantityTests.cs
@@ -174,21 +174,23 @@ public void FromUnitAbbreviation_MatchingCulture_ReturnsQuantity()
}
[Fact]
- public void TryFromUnitAbbreviation_MatchingCulture_ReturnsQuantity()
+ public void FromUnitAbbreviation_MatchingFallbackCulture_ReturnsQuantity()
{
- Assert.False(Quantity.TryFromUnitAbbreviation(Russian, 5, "cm", out IQuantity? q));
+ // The localized abbreviation is "см"
+ IQuantity quantity = Quantity.FromUnitAbbreviation(Russian, 5, "cm");
+ Assert.Equal(5, quantity.Value);
+ Assert.Equal(LengthUnit.Centimeter, quantity.Unit);
}
[Fact]
- public void FromUnitAbbreviation_MismatchingCulture_ThrowsUnitNotFoundException()
+ public void TryFromUnitAbbreviation_MatchingFallbackCulture_ReturnsQuantity()
{
- Assert.Throws(() => Quantity.FromUnitAbbreviation(Russian, 5, "cm")); // Expected "см"
- }
-
- [Fact]
- public void TryFromUnitAbbreviation_MismatchingCulture_ThrowsUnitNotFoundException()
- {
- Assert.Throws(() => Quantity.FromUnitAbbreviation(Russian, 5, "cm")); // Expected "см"
+ // The localized abbreviation is "см"
+ var success = Quantity.TryFromUnitAbbreviation(Russian, 5, "cm", out IQuantity? quantity);
+ Assert.True(success);
+ Assert.NotNull(quantity);
+ Assert.Equal(5, quantity.Value);
+ Assert.Equal(LengthUnit.Centimeter, quantity.Unit);
}
[Fact]
diff --git a/UnitsNet.Tests/UnitAbbreviationsCacheTests.cs b/UnitsNet.Tests/UnitAbbreviationsCacheTests.cs
index 2d565419c4..aa0bae8fad 100644
--- a/UnitsNet.Tests/UnitAbbreviationsCacheTests.cs
+++ b/UnitsNet.Tests/UnitAbbreviationsCacheTests.cs
@@ -17,9 +17,40 @@ public class UnitAbbreviationsCacheTests
{
private static readonly CultureInfo AmericanCulture = CultureInfo.GetCultureInfo("en-US");
private static readonly CultureInfo NorwegianCulture = CultureInfo.GetCultureInfo("nb-NO");
+
+ [Fact]
+ public void EmptyConstructor_ReturnsAnAbbreviationCacheWithDefaultQuantityInfoLookup()
+ {
+ var unitAbbreviationCache = new UnitAbbreviationsCache();
+
+ Assert.Equal(UnitsNetSetup.Default.QuantityInfoLookup, unitAbbreviationCache.Quantities);
+ Assert.Equal("g", unitAbbreviationCache.GetUnitAbbreviations(MassUnit.Gram, AmericanCulture)[0]);
+ Assert.Throws(() => unitAbbreviationCache.GetUnitAbbreviations(HowMuchUnit.Some));
+ }
[Fact]
- public void UnitAbbreviationsCacheDefaultReturnsUnitsNetSetupDefaultUnitAbbreviations()
+ public void Constructor_WithQuantities_ReturnsAnAbbreviationCacheWithNewQuantityInfoLookup()
+ {
+ var unitAbbreviationCache = new UnitAbbreviationsCache([Mass.Info, HowMuch.Info]);
+
+ Assert.NotEqual(UnitsNetSetup.Default.QuantityInfoLookup, unitAbbreviationCache.Quantities);
+ Assert.Equal("g", unitAbbreviationCache.GetUnitAbbreviations(MassUnit.Gram, AmericanCulture)[0]);
+ Assert.Empty(unitAbbreviationCache.GetUnitAbbreviations(HowMuchUnit.Some, AmericanCulture));
+ Assert.Throws(() => unitAbbreviationCache.GetUnitAbbreviations(LengthUnit.Meter));
+ }
+
+ [Fact]
+ public void CreateDefault_ReturnsAnAbbreviationCacheWithDefaultQuantityInfoLookup()
+ {
+ var unitAbbreviationCache = UnitAbbreviationsCache.CreateDefault();
+
+ Assert.Equal(UnitsNetSetup.Default.QuantityInfoLookup, unitAbbreviationCache.Quantities);
+ Assert.Equal("g", unitAbbreviationCache.GetUnitAbbreviations(MassUnit.Gram, AmericanCulture)[0]);
+ Assert.Throws(() => unitAbbreviationCache.GetUnitAbbreviations(HowMuchUnit.Some));
+ }
+
+ [Fact]
+ public void UnitAbbreviationsCache_Default_ReturnsInstanceFromUnitsNetSetup()
{
Assert.Equal(UnitsNetSetup.Default.UnitAbbreviations, UnitAbbreviationsCache.Default);
}
@@ -28,13 +59,13 @@ public void UnitAbbreviationsCacheDefaultReturnsUnitsNetSetupDefaultUnitAbbrevia
public void GetUnitAbbreviationsThrowsUnitNotFoundExceptionIfNoneExist()
{
Assert.Multiple(checks: [
- () => Assert.Throws(() => new UnitAbbreviationsCache().GetUnitAbbreviations(MassUnit.Gram)),
- () => Assert.Throws(() => new UnitAbbreviationsCache().GetUnitAbbreviations(typeof(MassUnit), (int)MassUnit.Gram))
+ () => Assert.Throws(() => new UnitAbbreviationsCache().GetUnitAbbreviations(HowMuchUnit.AShitTon)),
+ () => Assert.Throws(() => new UnitAbbreviationsCache().GetUnitAbbreviations(typeof(HowMuchUnit), (int)HowMuchUnit.AShitTon))
]);
}
[Fact]
- public void GetUnitAbbreviationsReturnsTheExpectedAbbreviationWhenConstructedWithTheSpecificQuantityInfo()
+ public void GetUnitAbbreviationReturnsTheExpectedAbbreviationWhenConstructedWithTheSpecificQuantityInfo()
{
Assert.Multiple(checks:
[
@@ -43,6 +74,13 @@ public void GetUnitAbbreviationsReturnsTheExpectedAbbreviationWhenConstructedWit
]);
}
+ [Fact]
+ public void GetUnitAbbreviationsReturnsTheExpectedAbbreviationWhenConstructedWithTheSpecificQuantityInfo()
+ {
+ var unitAbbreviationCache = new UnitAbbreviationsCache([Mass.Info]);
+ Assert.Equal("g", unitAbbreviationCache.GetUnitAbbreviations(MassUnit.Gram, AmericanCulture)[0]);
+ }
+
[Fact]
public void GetDefaultAbbreviationReturnsTheExpectedAbbreviationWhenConstructedWithTheSpecificQuantityInfo()
{
@@ -61,7 +99,7 @@ public void GetDefaultAbbreviationFallsBackToUsEnglishCulture()
// Zulu (South Africa)
var zuluCulture = CultureInfo.GetCultureInfo("zu-ZA");
- var abbreviationsCache = new UnitAbbreviationsCache();
+ var abbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
abbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.AShitTon, AmericanCulture, "US english abbreviation for Unit1");
// Act
@@ -71,19 +109,56 @@ public void GetDefaultAbbreviationFallsBackToUsEnglishCulture()
Assert.Equal("US english abbreviation for Unit1", abbreviation);
}
+ [Fact]
+ public void GetDefaultAbbreviationFallsBackToInvariantCulture()
+ {
+ // CurrentCulture affects number formatting, such as comma or dot as decimal separator.
+ // CurrentCulture also affects localization of unit abbreviations.
+ // Zulu (South Africa)
+ var zuluCulture = CultureInfo.GetCultureInfo("zu-ZA");
+
+ var abbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
+ abbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.AShitTon, CultureInfo.InvariantCulture, "Invariant abbreviation for Unit1");
+
+ // Act
+ string abbreviation = abbreviationsCache.GetDefaultAbbreviation(HowMuchUnit.AShitTon, zuluCulture);
+
+ // Assert
+ Assert.Equal("Invariant abbreviation for Unit1", abbreviation);
+ }
+
[Fact]
public void GetDefaultAbbreviationThrowsUnitNotFoundExceptionIfNoneExist()
{
Assert.Multiple(checks: [
- () => Assert.Throws(() => new UnitAbbreviationsCache().GetDefaultAbbreviation(MassUnit.Gram)),
- () => Assert.Throws(() => new UnitAbbreviationsCache().GetDefaultAbbreviation(typeof(MassUnit), (int)MassUnit.Gram))
+ () => Assert.Throws(() => new UnitAbbreviationsCache().GetDefaultAbbreviation(HowMuchUnit.AShitTon)),
+ () => Assert.Throws(() => new UnitAbbreviationsCache().GetDefaultAbbreviation(typeof(HowMuchUnit), (int)HowMuchUnit.AShitTon))
]);
}
[Fact]
- public void GetAbbreviationsThrowsArgumentNullExceptionWhenGivenANullUnitInfo()
+ public void GetDefaultAbbreviation_ForUnitWithoutAbbreviations_ThrowsInvalidOperationException()
+ {
+ Assert.Throws(() => new UnitAbbreviationsCache([HowMuch.Info]).GetDefaultAbbreviation(HowMuchUnit.AShitTon));
+ }
+
+ [Fact]
+ public void GetAllUnitAbbreviationsForQuantity_WithQuantityWithoutAbbreviations_ReturnsEmpty()
{
- Assert.Throws(() => new UnitAbbreviationsCache().GetAbbreviations(null!));
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
+ Assert.Empty(unitAbbreviationsCache.GetAllUnitAbbreviationsForQuantity(typeof(HowMuchUnit)));
+ }
+
+ [Fact]
+ public void GetAllUnitAbbreviationsForQuantity_WithInvalidUnitType_ThrowsArgumentException()
+ {
+ Assert.Throws(() => UnitAbbreviationsCache.Default.GetAllUnitAbbreviationsForQuantity(typeof(DateTime)));
+ }
+
+ [Fact]
+ public void GetAllUnitAbbreviationsForQuantity_WithUnknownUnitType_ThrowsUnitNotFoundException()
+ {
+ Assert.Throws(() => UnitAbbreviationsCache.Default.GetAllUnitAbbreviationsForQuantity(typeof(HowMuchUnit)));
}
[Fact]
@@ -113,15 +188,6 @@ public void MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviati
Assert.Equal("m²", cache.GetDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture));
}
- [Fact]
- public void MapUnitToDefaultAbbreviation_GivenUnitAndCulture_SetsDefaultAbbreviationForUnitAndCulture()
- {
- var cache = new UnitAbbreviationsCache();
- cache.MapUnitToDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture, "m^2");
-
- Assert.Equal("m^2", cache.GetDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture));
- }
-
[Fact]
public void MapUnitToDefaultAbbreviation_GivenUnitAndNoCulture_SetsDefaultAbbreviationForUnitForCurrentCulture()
{
@@ -135,15 +201,21 @@ public void MapUnitToDefaultAbbreviation_GivenUnitAndNoCulture_SetsDefaultAbbrev
}
[Fact]
- public void MapUnitToDefaultAbbreviation_GivenUnitTypeAndValue_SetsDefaultAbbreviationForUnitForCurrentCulture()
+ public void MapUnitToDefaultAbbreviation_GivenUnitAndCulture_SetsDefaultAbbreviationForUnitAndCulture()
{
- using var cultureScope = new CultureScope(NorwegianCulture);
- var cache = new UnitAbbreviationsCache([Mass.Info]);
+ var cache = new UnitAbbreviationsCache([Area.Info]);
+ cache.MapUnitToDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture, "m^2");
- cache.MapUnitToDefaultAbbreviation(typeof(MassUnit), (int)MassUnit.Gram, null, "zz");
+ Assert.Equal("m^2", cache.GetDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture));
+ }
- Assert.Equal("zz", cache.GetDefaultAbbreviation(MassUnit.Gram));
- Assert.Equal("g", cache.GetDefaultAbbreviation(MassUnit.Gram, AmericanCulture));
+ [Fact]
+ public void MapUnitToDefaultAbbreviation_GivenUnitTypeValueAndCulture_SetsDefaultAbbreviationForUnitAndCulture()
+ {
+ var cache = new UnitAbbreviationsCache([Area.Info]);
+ cache.MapUnitToDefaultAbbreviation(typeof(AreaUnit), (int)AreaUnit.SquareMeter, AmericanCulture, "m^2");
+
+ Assert.Equal("m^2", cache.GetDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture));
}
[Fact]
@@ -172,7 +244,7 @@ public void MapUnitToAbbreviation_GivenUnitTypeAndValue_AddsTheAbbreviationForUn
[Fact]
public void MapUnitToAbbreviation_DoesNotInsertDuplicates()
{
- var cache = new UnitAbbreviationsCache();
+ var cache = new UnitAbbreviationsCache([HowMuch.Info]);
cache.MapUnitToAbbreviation(HowMuchUnit.Some, "sm");
cache.MapUnitToAbbreviation(HowMuchUnit.Some, "sm");
@@ -186,7 +258,7 @@ public void MapUnitToAbbreviation_DoesNotInsertDuplicates()
[Fact]
public void MapUnitToDefaultAbbreviation_Twice_SetsNewDefaultAndKeepsOrderOfExistingAbbreviations()
{
- var cache = new UnitAbbreviationsCache();
+ var cache = new UnitAbbreviationsCache([HowMuch.Info]);
cache.MapUnitToAbbreviation(HowMuchUnit.Some, "sm");
cache.MapUnitToDefaultAbbreviation(HowMuchUnit.Some, "1st default");
@@ -204,8 +276,44 @@ public void MapUnitToDefaultAbbreviation_Twice_SetsNewDefaultAndKeepsOrderOfExis
[Fact]
public void MapAndLookup_WithSpecificEnumType()
{
- UnitsNetSetup.Default.UnitAbbreviations.MapUnitToDefaultAbbreviation(HowMuchUnit.Some, "sm");
- Assert.Equal("sm", UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(HowMuchUnit.Some));
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
+ unitAbbreviationsCache.MapUnitToDefaultAbbreviation(HowMuchUnit.Some, "sm");
+ Assert.Equal("sm", unitAbbreviationsCache.GetDefaultAbbreviation(HowMuchUnit.Some));
+ }
+
+ ///
+ [Fact]
+ public void MapAndLookup_WithEnumType()
+ {
+ Enum valueAsEnumType = HowMuchUnit.Some;
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
+ unitAbbreviationsCache.MapUnitToDefaultAbbreviation(valueAsEnumType, "sm");
+ Assert.Equal("sm", unitAbbreviationsCache.GetDefaultAbbreviation(valueAsEnumType));
+ }
+
+ ///
+ [Fact]
+ public void MapAndLookup_MapWithSpecificEnumType_LookupWithEnumType()
+ {
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
+ unitAbbreviationsCache.MapUnitToDefaultAbbreviation(HowMuchUnit.Some, "sm");
+ Assert.Equal("sm", unitAbbreviationsCache.GetDefaultAbbreviation((Enum)HowMuchUnit.Some));
+ }
+
+ [Fact]
+ public void MapUnitToAbbreviation_WithUnknownUnit_ThrowsUnitNotFoundException()
+ {
+ var unitAbbreviationCache = new UnitAbbreviationsCache([Mass.Info]);
+ Assert.Throws(() => unitAbbreviationCache.MapUnitToAbbreviation(HowMuchUnit.Some, "nothing"));
+ Assert.Throws(() => unitAbbreviationCache.MapUnitToAbbreviation(LengthUnit.Centimeter, "nothing"));
+ }
+
+ [Fact]
+ public void MapUnitToDefaultAbbreviation_WithUnknownUnit_ThrowsUnitNotFoundException()
+ {
+ var unitAbbreviationCache = new UnitAbbreviationsCache([Mass.Info]);
+ Assert.Throws(() => unitAbbreviationCache.MapUnitToDefaultAbbreviation(HowMuchUnit.Some, "nothing"));
+ Assert.Throws(() => unitAbbreviationCache.MapUnitToDefaultAbbreviation(LengthUnit.AstronomicalUnit, "nothing"));
}
}
}
diff --git a/UnitsNet.Tests/UnitParserTests.cs b/UnitsNet.Tests/UnitParserTests.cs
index 17b2007e40..63131e4483 100644
--- a/UnitsNet.Tests/UnitParserTests.cs
+++ b/UnitsNet.Tests/UnitParserTests.cs
@@ -11,12 +11,40 @@ namespace UnitsNet.Tests
{
public class UnitParserTests
{
+ [Fact]
+ public void Constructor_WithQuantitiesCreatesNewAbbreviationsCacheAndNewQuantityInfoLookup()
+ {
+ var unitParser = new UnitParser([Mass.Info]);
+ Assert.NotNull(unitParser.Abbreviations);
+ Assert.NotEqual(UnitAbbreviationsCache.Default, unitParser.Abbreviations);
+ Assert.NotEqual(UnitsNetSetup.Default.QuantityInfoLookup, unitParser.Quantities);
+ }
+
+ [Fact]
+ public void Constructor_WithQuantityInfoLookupCreatesNewAbbreviationsCache()
+ {
+ var quantities = new QuantityInfoLookup([Mass.Info]);
+ var unitParser = new UnitParser(quantities);
+ Assert.NotNull(unitParser.Abbreviations);
+ Assert.NotEqual(UnitAbbreviationsCache.Default, unitParser.Abbreviations);
+ Assert.Equal(quantities, unitParser.Quantities);
+ }
+
+ [Fact]
+ public void CreateDefault_CreatesNewAbbreviationsCacheWithDefaultQuantities()
+ {
+ var unitParser = UnitParser.CreateDefault();
+ Assert.NotNull(unitParser.Abbreviations);
+ Assert.NotEqual(UnitAbbreviationsCache.Default, unitParser.Abbreviations);
+ Assert.Equal(UnitsNetSetup.Default.QuantityInfoLookup, unitParser.Quantities);
+ }
+
[Theory]
[InlineData("m^^2", AreaUnit.SquareMeter)]
[InlineData("cm^^2", AreaUnit.SquareCentimeter)]
public void Parse_ReturnsUnitMappedByCustomAbbreviation(string customAbbreviation, AreaUnit expected)
{
- var abbrevCache = new UnitAbbreviationsCache();
+ var abbrevCache = new UnitAbbreviationsCache([Area.Info]);
abbrevCache.MapUnitToAbbreviation(expected, customAbbreviation);
var parser = new UnitParser(abbrevCache);
@@ -59,6 +87,8 @@ public void Parse_GivenAbbreviationsThatAreAmbiguousWhenLowerCase_ReturnsCorrect
[Fact]
public void Parse_NullAbbreviation_Throws_ArgumentNullException()
{
+ Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse(null!));
+ Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse(null!, Length.Info.UnitInfos));
Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse(null!, typeof(LengthUnit)));
}
@@ -129,13 +159,16 @@ public void Parse_AmbiguousUnitsThrowsException()
[InlineData("kg", "ru-RU", MassUnit.Kilogram)] // should work with the "FallbackCulture"
public void ParseMassUnit_GivenCulture(string str, string cultureName, Enum expectedUnit)
{
- Assert.Equal(expectedUnit, UnitsNetSetup.Default.UnitParser.Parse(str, CultureInfo.GetCultureInfo(cultureName)));
+ var formatProvider = CultureInfo.GetCultureInfo(cultureName);
+ UnitParser unitParser = UnitsNetSetup.Default.UnitParser;
+
+ Assert.Equal(expectedUnit, unitParser.Parse(str, formatProvider));
}
-
+
[Fact]
public void Parse_MappedCustomUnit()
{
- var unitAbbreviationsCache = new UnitAbbreviationsCache();
+ var unitAbbreviationsCache = new UnitAbbreviationsCache([HowMuch.Info]);
unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh");
var unitParser = new UnitParser(unitAbbreviationsCache);
@@ -150,7 +183,7 @@ public void Parse_LengthUnit_MM_ThrowsExceptionDescribingTheAmbiguity()
var ex = Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse("MM"));
Assert.Equal("""Cannot parse "MM" since it matches multiple units: Megameter ("Mm"), Millimeter ("mm").""", ex.Message);
}
-
+
[Fact]
public void TryParse_WithNullAbbreviation_ReturnsFalse()
{
@@ -163,13 +196,20 @@ public void TryParse_WithNullAbbreviation_ReturnsFalse()
{
var success = unitParser.TryParse(null, typeof(LengthUnit), out Enum? _);
Assert.False(success);
+ }, () =>
+ {
+ var success = unitParser.TryParse(null, [], null, out UnitInfo? _);
+ Assert.False(success);
});
}
- [Fact]
- public void TryParse_UnknownAbbreviation_ReturnsFalse()
+ [Theory]
+ [InlineData("")]
+ [InlineData("z^2")]
+ [InlineData("nonexistingunit")]
+ public void TryParse_UnknownAbbreviation_ReturnsFalse(string unknownAreaAbbreviation)
{
- Assert.False(UnitsNetSetup.Default.UnitParser.TryParse("nonexistingunit", out AreaUnit _));
+ Assert.False(UnitsNetSetup.Default.UnitParser.TryParse(unknownAreaAbbreviation, out AreaUnit _));
}
[Fact]
@@ -177,6 +217,7 @@ public void TryParse_WithAmbiguousUnits_ReturnsFalse()
{
UnitParser unitParser = UnitsNetSetup.Default.UnitParser;
Assert.False(unitParser.TryParse("pt", CultureInfo.InvariantCulture, out LengthUnit _));
+ Assert.False(unitParser.TryParse("pt", Length.Info.UnitInfos, CultureInfo.InvariantCulture, out UnitInfo? _));
}
[Theory]
@@ -197,5 +238,60 @@ public void TryParseMassUnit_GivenCulture(string str, string cultureName, Enum e
Assert.True(success);
Assert.Equal(expectedUnit, unitParsed);
}
+
+ [Fact]
+ public void TryGetUnitFromAbbreviation_WithLocalizedUnit_MatchingCulture_ReturnsTrue()
+ {
+ var formatProvider = CultureInfo.GetCultureInfo("ru-RU");
+ UnitParser unitParser = UnitsNetSetup.Default.UnitParser;
+
+ var success = unitParser.TryGetUnitFromAbbreviation("кг", formatProvider, out UnitInfo? unitInfo);
+
+ Assert.True(success);
+ Assert.NotNull(unitInfo);
+ Assert.Equal(MassUnit.Kilogram, unitInfo.Value);
+ }
+
+ [Fact]
+ public void TryGetUnitFromAbbreviation_MatchingFallbackCulture_ReturnsTrue()
+ {
+ var formatProvider = CultureInfo.GetCultureInfo("ru-RU");
+ UnitParser unitParser = UnitsNetSetup.Default.UnitParser;
+
+ var success = unitParser.TryGetUnitFromAbbreviation("kg", formatProvider, out UnitInfo? unitInfo);
+
+ Assert.True(success);
+ Assert.NotNull(unitInfo);
+ Assert.Equal(MassUnit.Kilogram, unitInfo.Value);
+ }
+
+ [Fact]
+ public void TryGetUnitFromAbbreviation_WithNullString_ReturnsFalse()
+ {
+ var success = UnitsNetSetup.Default.UnitParser.TryGetUnitFromAbbreviation(null, CultureInfo.InvariantCulture, out UnitInfo? _);
+
+ Assert.False(success);
+ }
+
+ [Fact]
+ public void GetUnitFromAbbreviation_GivenAbbreviationsThatAreAmbiguousWhenLowerCase_ReturnsCorrectUnit()
+ {
+ Assert.Equal(PressureUnit.Megabar, UnitParser.Default.GetUnitFromAbbreviation("Mbar", CultureInfo.InvariantCulture).Value);
+ Assert.Equal(PressureUnit.Millibar, UnitParser.Default.GetUnitFromAbbreviation("mbar", CultureInfo.InvariantCulture).Value);
+ }
+
+ [Fact]
+ public void GetUnitFromAbbreviation_NullAbbreviation_Throws_ArgumentNullException()
+ {
+ Assert.Throws(() => UnitsNetSetup.Default.UnitParser.GetUnitFromAbbreviation(null!, CultureInfo.InvariantCulture));
+ }
+
+ [Theory]
+ [InlineData("z^2")]
+ [InlineData("nonexistingunit")]
+ public void GetUnitFromAbbreviation_UnknownAbbreviationThrowsUnitNotFoundException(string unknownAbbreviation)
+ {
+ Assert.Throws(() => UnitsNetSetup.Default.UnitParser.GetUnitFromAbbreviation(unknownAbbreviation, CultureInfo.InvariantCulture));
+ }
}
}
diff --git a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs
index 264caa0d93..9f083fd6ef 100644
--- a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs
+++ b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using System.Reflection;
using System.Resources;
using UnitsNet.Units;
using AbbreviationMapKey = System.ValueTuple;
@@ -15,32 +16,35 @@ namespace UnitsNet
{
///
/// Cache of the mapping between unit enum values and unit abbreviation strings for one or more cultures.
- /// A static instance .. is used internally
- /// for ToString() and Parse() of quantities and units.
+ /// A static instance is created in the , which is used for ToString() and Parse() of quantities and units.
///
public sealed class UnitAbbreviationsCache
{
///
- /// Fallback culture used by and
+ /// Fallback culture used by and
/// if no abbreviations are found with a given culture.
///
///
- /// User wants to call or with Russian
- /// culture, but no translation is defined, so we return the US English definition as a last resort. If it's not
+ /// User wants to call or with Russian
+ /// culture, but no translation is defined, so we return the US English (en-US) definition as a last resort. If it's not
/// defined there either, an exception is thrown.
///
internal static readonly CultureInfo FallbackCulture = CultureInfo.InvariantCulture;
///
- /// The default singleton instance with the default configured unit abbreviations, used for ToString() and parsing of quantities and units.
+ /// The static instance used internally for ToString() and Parse() of quantities and units.
///
- ///
- /// Convenience shortcut for ...
- /// You can add custom unit abbreviations at runtime, and this will affect all usages globally in the application.
- ///
public static UnitAbbreviationsCache Default => UnitsNetSetup.Default.UnitAbbreviations;
- private QuantityInfoLookup QuantityInfoLookup { get; }
+ ///
+ /// Gets the lookup table for quantity information used by this cache.
+ ///
+ ///
+ /// This property provides access to the instance that contains
+ /// information about quantities and their associated units. It is used internally to map units
+ /// to their abbreviations and vice versa.
+ ///
+ internal QuantityInfoLookup Quantities { get; }
///
/// Culture name to abbreviations. To add a custom default abbreviation, add to the beginning of the list.
@@ -48,10 +52,11 @@ public sealed class UnitAbbreviationsCache
private ConcurrentDictionary> AbbreviationsMap { get; } = new();
///
- /// Create an empty instance of the cache, with no default abbreviations loaded.
+ /// Create an instance of the cache and load all the built-in quantities defined in the library.
///
+ /// Instance for mapping any of the built-in units.
public UnitAbbreviationsCache()
- : this(new QuantityInfoLookup([]))
+ :this(UnitsNetSetup.Default.QuantityInfoLookup)
{
}
@@ -63,116 +68,146 @@ public UnitAbbreviationsCache(IEnumerable quantities)
:this(new QuantityInfoLookup(quantities))
{
}
-
+
///
/// Creates an instance of the cache using the specified set of quantities.
///
///
/// Access type is internal until this class is matured and ready for external use.
///
- internal UnitAbbreviationsCache(QuantityInfoLookup quantityInfoLookup)
+ internal UnitAbbreviationsCache(QuantityInfoLookup quantities)
{
- QuantityInfoLookup = quantityInfoLookup;
+ Quantities = quantities;
}
-
+
///
/// Create an instance of the cache and load all the built-in quantities defined in the library.
///
/// Instance for mapping any of the built-in units.
- public static UnitAbbreviationsCache CreateDefault() => new(new QuantityInfoLookup(Quantity.Infos));
-
+ public static UnitAbbreviationsCache CreateDefault()
+ {
+ return new UnitAbbreviationsCache();
+ }
+
+ #region MapUnitToAbbreviation overloads
+
///
/// Adds one or more unit abbreviation for the given unit enum value.
/// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
- /// in order to or on them later.
+ /// in order to or on them later.
///
/// The unit enum value.
/// Unit abbreviations to add.
/// The type of unit enum.
- public void MapUnitToAbbreviation(TUnitType unit, params string[] abbreviations) where TUnitType : struct, Enum
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// .
+ ///
+ public void MapUnitToAbbreviation(TUnitType unit, params IEnumerable abbreviations)
+ where TUnitType : struct, Enum
{
- PerformAbbreviationMapping(UnitKey.ForUnit(unit), CultureInfo.CurrentCulture, false, abbreviations);
+ MapUnitToAbbreviation(UnitKey.ForUnit(unit), abbreviations);
}
- ///
- /// Adds a unit abbreviation for the given unit enum value and sets it as the default.
- /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
- /// in order to or on them later.
- ///
- /// The unit enum value.
- /// Unit abbreviations to add as default.
- /// The type of unit enum.
- public void MapUnitToDefaultAbbreviation(TUnitType unit, string abbreviation) where TUnitType : struct, Enum
+ /// >
+ /// The unit enum type.
+ /// The unit enum value.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// Unit abbreviations to add.
+ public void MapUnitToAbbreviation(Type unitType, int unitValue, IFormatProvider? formatProvider, params IEnumerable abbreviations)
{
- PerformAbbreviationMapping(UnitKey.ForUnit(unit), CultureInfo.CurrentCulture, true, abbreviation);
+ MapUnitToAbbreviation(new UnitKey(unitType, unitValue), formatProvider, abbreviations);
}
- ///
- /// Adds one or more unit abbreviation for the given unit enum value.
- /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
- /// in order to or on them later.
- ///
+ /// >
+ /// The unit key value.
+ /// Unit abbreviations to add.
+ public void MapUnitToAbbreviation(UnitKey unitKey, params IEnumerable abbreviations)
+ {
+ MapUnitToAbbreviation(unitKey, CultureInfo.CurrentCulture, abbreviations);
+ }
+
+ /// >
/// The unit enum value.
/// The format provider to use for lookup. Defaults to if null.
/// Unit abbreviations to add.
/// The type of unit enum.
- public void MapUnitToAbbreviation(TUnitType unit, IFormatProvider? formatProvider, params string[] abbreviations) where TUnitType : struct, Enum
+ public void MapUnitToAbbreviation(TUnitType unit, IFormatProvider? formatProvider, params IEnumerable abbreviations)
+ where TUnitType : struct, Enum
{
- PerformAbbreviationMapping(UnitKey.ForUnit(unit), formatProvider, false, abbreviations);
+ MapUnitToAbbreviation(UnitKey.ForUnit(unit), formatProvider, abbreviations);
+ }
+
+ /// >
+ /// The unit key value.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// Unit abbreviations to add.
+ public void MapUnitToAbbreviation(UnitKey unitKey, IFormatProvider? formatProvider, params IEnumerable abbreviations)
+ {
+ PerformAbbreviationMapping(unitKey, formatProvider, false, abbreviations);
}
+ #endregion
+
+ #region MapUnitToDefaultAbbreviation overloads
+
///
/// Adds a unit abbreviation for the given unit enum value and sets it as the default.
- /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
- /// in order to or on them later.
+ /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
+ /// in order to or on them later.
///
/// The unit enum value.
- /// The format provider to use for lookup. Defaults to if null.
- /// Unit abbreviation to add as default.
+ /// Unit abbreviations to add as default.
/// The type of unit enum.
- public void MapUnitToDefaultAbbreviation(TUnitType unit, IFormatProvider? formatProvider, string abbreviation) where TUnitType : struct, Enum
+ public void MapUnitToDefaultAbbreviation(TUnitType unit, string abbreviation)
+ where TUnitType : struct, Enum
{
- PerformAbbreviationMapping(UnitKey.ForUnit(unit), formatProvider, true, abbreviation);
+ MapUnitToDefaultAbbreviation(UnitKey.ForUnit(unit), abbreviation);
}
- ///
- /// Adds one or more unit abbreviation for the given unit enum value.
- /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
- /// in order to or on them later.
- ///
- /// The unit enum type.
- /// The unit enum value.
+ /// >
+ /// The unit key value.
+ /// Unit abbreviations to add as default.
+ public void MapUnitToDefaultAbbreviation(UnitKey unitKey, string abbreviation)
+ {
+ MapUnitToDefaultAbbreviation(unitKey, CultureInfo.CurrentCulture, abbreviation);
+ }
+
+ /// >
+ /// The unit enum value.
/// The format provider to use for lookup. Defaults to if null.
- /// Unit abbreviations to add.
- public void MapUnitToAbbreviation(Type unitType, int unitValue, IFormatProvider? formatProvider, params string[] abbreviations)
+ /// Unit abbreviation to add as default.
+ /// The type of unit enum.
+ public void MapUnitToDefaultAbbreviation(TUnitType unit, IFormatProvider? formatProvider, string abbreviation)
+ where TUnitType : struct, Enum
{
- PerformAbbreviationMapping(new UnitKey(unitType, unitValue), formatProvider, false, abbreviations);
+ MapUnitToDefaultAbbreviation(UnitKey.ForUnit(unit), formatProvider, abbreviation);
}
- ///
- /// Adds a unit abbreviation for the given unit enum value and sets it as the default.
- /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums
- /// in order to or on them later.
- ///
+ /// >
/// The unit enum type.
/// The unit enum value.
/// The format provider to use for lookup. Defaults to if null.
/// Unit abbreviation to add as default.
public void MapUnitToDefaultAbbreviation(Type unitType, int unitValue, IFormatProvider? formatProvider, string abbreviation)
{
- PerformAbbreviationMapping(new UnitKey(unitType, unitValue), formatProvider, true, abbreviation);
+ MapUnitToDefaultAbbreviation(new UnitKey(unitType, unitValue), formatProvider, abbreviation);
}
- private void PerformAbbreviationMapping(UnitKey unitValue, IFormatProvider? formatProvider, bool setAsDefault, params string[] abbreviations)
+ /// >
+ /// The unit key value.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// Unit abbreviation to add as default.
+ public void MapUnitToDefaultAbbreviation(UnitKey unitKey, IFormatProvider? formatProvider, string abbreviation)
{
- if(!QuantityInfoLookup.TryGetUnitInfo(unitValue, out UnitInfo? unitInfo))
- {
- // TODO we should throw QuantityNotFoundException here (all QuantityInfos should be provided through the constructor)
- unitInfo = new UnitInfo((Enum)unitValue, unitValue.ToString(), BaseUnits.Undefined);
- QuantityInfoLookup.AddUnitInfo(unitInfo);
- }
+ PerformAbbreviationMapping(unitKey, formatProvider, true, abbreviation);
+ }
+
+ #endregion
- AddAbbreviation(unitInfo, formatProvider, setAsDefault, abbreviations);
+ private void PerformAbbreviationMapping(UnitKey unitKey, IFormatProvider? formatProvider, bool setAsDefault, params IEnumerable abbreviations)
+ {
+ AddAbbreviation(Quantities.GetUnitInfo(unitKey), formatProvider, setAsDefault, abbreviations);
}
///
@@ -183,7 +218,16 @@ private void PerformAbbreviationMapping(UnitKey unitValue, IFormatProvider? form
/// The unit enum value.
/// The format provider to use for lookup. Defaults to if null.
/// The type of unit enum.
- public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider? formatProvider = null) where TUnitType : struct, Enum
+ /// The default unit abbreviation string.
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// .
+ ///
+ ///
+ /// Thrown when no abbreviations are mapped for the specified unit.
+ ///
+ public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider? formatProvider = null)
+ where TUnitType : struct, Enum
{
return GetDefaultAbbreviation(UnitKey.ForUnit(unit), formatProvider);
}
@@ -196,18 +240,28 @@ public string GetDefaultAbbreviation(TUnitType unit, IFormatProvider?
/// The unit enum type.
/// The unit enum value.
/// The format provider to use for lookup. Defaults to if null.
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// and .
+ ///
+ ///
+ /// Thrown when no abbreviations are mapped for the specified unit.
+ ///
public string GetDefaultAbbreviation(Type unitType, int unitValue, IFormatProvider? formatProvider = null)
{
return GetDefaultAbbreviation(new UnitKey(unitType, unitValue), formatProvider);
}
-
- ///
+
+ ///
/// The key representing the unit type and value.
- ///
- /// The format provider to use for lookup. Defaults to
- /// if null.
- ///
- /// The default unit abbreviation string.
+ /// The format provider to use for lookup. Defaults to if null.
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// .
+ ///
+ ///
+ /// Thrown when no abbreviations are mapped for the specified unit.
+ ///
public string GetDefaultAbbreviation(UnitKey unitKey, IFormatProvider? formatProvider = null)
{
IReadOnlyList abbreviations = GetUnitAbbreviations(unitKey, formatProvider);
@@ -226,9 +280,14 @@ public string GetDefaultAbbreviation(UnitKey unitKey, IFormatProvider? formatPro
/// Enum value for unit.
/// The format provider to use for lookup. Defaults to if null.
/// Unit abbreviations associated with unit.
- public string[] GetUnitAbbreviations(TUnitType unit, IFormatProvider? formatProvider = null) where TUnitType : struct, Enum
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// .
+ ///
+ public IReadOnlyList GetUnitAbbreviations(TUnitType unit, IFormatProvider? formatProvider = null)
+ where TUnitType : struct, Enum
{
- return GetUnitAbbreviations(UnitKey.ForUnit(unit), formatProvider).ToArray(); // TODO can we change this to return an IReadonlyCollection (as the GetAbbreviations)?
+ return GetUnitAbbreviations(UnitKey.ForUnit(unit), formatProvider);
}
///
@@ -238,137 +297,136 @@ public string[] GetUnitAbbreviations(TUnitType unit, IFormatProvider?
/// Enum value for unit.
/// The format provider to use for lookup. Defaults to if null.
/// Unit abbreviations associated with unit.
- public string[] GetUnitAbbreviations(Type unitType, int unitValue, IFormatProvider? formatProvider = null)
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// and .
+ ///
+ public IReadOnlyList GetUnitAbbreviations(Type unitType, int unitValue, IFormatProvider? formatProvider = null)
{
- return GetUnitAbbreviations(new UnitKey(unitType, unitValue), formatProvider).ToArray(); // TODO can we change this to return an IReadOnlyList (as the GetAbbreviations)?
+ return GetUnitAbbreviations(new UnitKey(unitType, unitValue), formatProvider);
}
///
/// Retrieves the unit abbreviations for a specified unit key and optional format provider.
///
/// The key representing the unit type and value.
- /// An optional format provider to use for culture-specific formatting.
+ /// The format provider to use for lookup. Defaults to if null.
/// A read-only collection of unit abbreviation strings.
+ ///
+ /// Thrown when no unit information is found for the specified
+ /// .
+ ///
public IReadOnlyList GetUnitAbbreviations(UnitKey unitKey, IFormatProvider? formatProvider = null)
{
- return GetAbbreviations(QuantityInfoLookup.GetUnitInfo(unitKey), formatProvider);
- }
-
- ///
- /// Get all abbreviations for unit.
- ///
- /// The unit-enum type as a hash-friendly type.
- /// The format provider to use for lookup. Defaults to if null.
- /// The unit abbreviations associated with unit.
- /// True if found, otherwise false.
- private bool TryGetUnitAbbreviations(UnitKey unitKey, IFormatProvider? formatProvider, out IReadOnlyList abbreviations)
- {
- if(QuantityInfoLookup.TryGetUnitInfo(unitKey, out UnitInfo? unitInfo))
+ if (formatProvider is not CultureInfo culture)
{
- abbreviations = GetAbbreviations(unitInfo, formatProvider);
- return true;
+ culture = CultureInfo.CurrentCulture;
}
- abbreviations = [];
- return false;
+ return GetAbbreviationsWithFallbackCulture(Quantities.GetUnitInfo(unitKey), culture);
}
///
- /// Get all abbreviations for all units of a quantity.
+ /// Retrieves all abbreviations for all units of a specified quantity.
///
- /// Enum type for unit.
+ ///
+ /// The enum type representing the unit. This must be a valid unit type.
+ ///
/// The format provider to use for lookup. Defaults to if null.
- /// Unit abbreviations associated with unit.
+ ///
+ /// A read-only list of unit abbreviations associated with the specified unit type.
+ ///
+ ///
+ /// Thrown when the provided is not an enum type.
+ ///
+ ///
+ /// Thrown when no quantity is found for the specified unit type.
+ ///
public IReadOnlyList GetAllUnitAbbreviationsForQuantity(Type unitEnumType, IFormatProvider? formatProvider = null)
{
- var allAbbreviations = new List();
- if (!QuantityInfoLookup.TryGetQuantityByUnitType(unitEnumType, out QuantityInfo? quantityInfo))
+ if (!Quantities.TryGetQuantityByUnitType(unitEnumType, out QuantityInfo? quantityInfo))
{
- // TODO I think we should either return empty or throw QuantityNotFoundException here
- var enumValues = Enum.GetValues(unitEnumType).Cast();
- var all = GetStringUnitPairs(enumValues, formatProvider);
- return all.Select(pair => pair.Item2).ToList();
+ if (!unitEnumType.IsEnum)
+ {
+ throw new ArgumentException($"Type {unitEnumType.FullName} is not a supported unit type.");
+ }
+
+ throw new UnitNotFoundException($"No quantity was found with the specified unit type: '{unitEnumType}'.") { Data = { ["unitType"] = unitEnumType.Name } };
}
- foreach(UnitInfo unitInfo in quantityInfo.UnitInfos)
+ if (formatProvider is not CultureInfo culture)
{
- if(TryGetUnitAbbreviations(unitInfo.UnitKey, formatProvider, out IReadOnlyList abbreviations))
- {
- allAbbreviations.AddRange(abbreviations);
- }
+ culture = CultureInfo.CurrentCulture;
}
- return allAbbreviations;
- }
-
- internal List<(Enum Unit, string Abbreviation)> GetStringUnitPairs(IEnumerable enumValues, IFormatProvider? formatProvider = null)
- {
- var unitAbbreviationsPairs = new List<(Enum, string)>();
- formatProvider ??= CultureInfo.CurrentCulture;
-
- foreach(var enumValue in enumValues)
+ var allAbbreviations = new List();
+ foreach(UnitInfo unitInfo in quantityInfo.UnitInfos)
{
- if(TryGetUnitAbbreviations(enumValue, formatProvider, out var abbreviations))
- {
- foreach(var abbrev in abbreviations)
- {
- unitAbbreviationsPairs.Add((enumValue, abbrev));
- }
- }
+ allAbbreviations.AddRange(GetAbbreviationsWithFallbackCulture(unitInfo, culture));
}
- return unitAbbreviationsPairs;
+ return allAbbreviations;
}
///
/// Get all abbreviations for the given unit and culture.
///
/// The unit.
- /// The culture to get localized abbreviations for. Defaults to .
+ /// The culture to get localized abbreviations for.
/// The list of abbreviations mapped for this unit. The first in the list is the primary abbreviation used by ToString().
/// was null.
- public IReadOnlyList GetAbbreviations(UnitInfo unitInfo, IFormatProvider? formatProvider = null)
+ internal IReadOnlyList GetAbbreviationsWithFallbackCulture(UnitInfo unitInfo, CultureInfo culture)
{
- if (unitInfo == null) throw new ArgumentNullException(nameof(unitInfo));
- if (formatProvider is not CultureInfo)
- formatProvider = CultureInfo.CurrentCulture;
-
- var culture = (CultureInfo)formatProvider;
- var cultureName = GetCultureNameOrEnglish(culture);
-
- AbbreviationMapKey key = GetAbbreviationMapKey(unitInfo, cultureName);
+ IReadOnlyList abbreviations = GetAbbreviationsForCulture(unitInfo, culture);
- IReadOnlyList abbreviations = AbbreviationsMap.GetOrAdd(key,
- valueFactory: _ => ReadAbbreviationsFromResourceFile(unitInfo.QuantityName, unitInfo.PluralName, culture));
-
- return abbreviations.Count == 0 && !culture.Equals(FallbackCulture)
- ? GetAbbreviations(unitInfo, FallbackCulture)
+ return abbreviations.Count == 0 && HasFallbackCulture(culture)
+ ? GetAbbreviationsForCulture(unitInfo, FallbackCulture)
: abbreviations;
}
+ internal static bool HasFallbackCulture(CultureInfo culture)
+ {
+ // accounting for the fact that we're using the same abbreviations for both "en-US" and the "Invariant" culture (Name == string.Empty)
+ return culture.Name != string.Empty && culture.Name != FallbackCulture.Name;
+ }
+
+ internal IReadOnlyList GetAbbreviationsForCulture(UnitInfo unitInfo, CultureInfo culture)
+ {
+ AbbreviationMapKey abbreviationMapKey = GetAbbreviationMapKey(unitInfo, culture);
+#if NET
+ return AbbreviationsMap.GetOrAdd(abbreviationMapKey, ReadAbbreviationsForCulture, (unitInfo, culture));
+ static IReadOnlyList ReadAbbreviationsForCulture(AbbreviationMapKey key, (UnitInfo unitInfo, CultureInfo culture) unitForCulture)
+ {
+ return ReadAbbreviationsFromResourceFile(unitForCulture.unitInfo, unitForCulture.culture);
+ }
+#else
+ // intentionally not using the factory overload here, as it causes an extra allocation for the Func
+ return AbbreviationsMap.TryGetValue(abbreviationMapKey, out IReadOnlyList abbreviations)
+ ? abbreviations
+ : AbbreviationsMap.GetOrAdd(abbreviationMapKey, _ => ReadAbbreviationsFromResourceFile(unitInfo, culture));
+#endif
+ }
+
///
/// Add unit abbreviation for the given , such as "kg" for .
///
/// The unit to add for.
- /// The culture this abbreviation is for, defaults to .
+ /// The format provider to use for lookup. Defaults to if null.
/// Whether to set as the primary/default unit abbreviation used by ToString().
/// One or more abbreviations to add.
- private void AddAbbreviation(UnitInfo unitInfo, IFormatProvider? formatProvider, bool setAsDefault,
- params string[] newAbbreviations)
+ private void AddAbbreviation(UnitInfo unitInfo, IFormatProvider? formatProvider, bool setAsDefault, params IEnumerable newAbbreviations)
{
if (formatProvider is not CultureInfo culture)
{
culture = CultureInfo.CurrentCulture;
}
- var cultureName = GetCultureNameOrEnglish(culture);
-
- AbbreviationMapKey key = GetAbbreviationMapKey(unitInfo, cultureName);
+ AbbreviationMapKey key = GetAbbreviationMapKey(unitInfo, culture);
AbbreviationsMap.AddOrUpdate(key,
addValueFactory: _ =>
{
- List bundledAbbreviations = ReadAbbreviationsFromResourceFile(unitInfo.QuantityName, unitInfo.PluralName, culture).ToList();
+ List bundledAbbreviations = ReadAbbreviationsFromResourceFile(unitInfo, culture);
return AddAbbreviationsToList(setAsDefault, bundledAbbreviations, newAbbreviations);
},
updateValueFactory: (_, existingReadOnlyList) => AddAbbreviationsToList(setAsDefault, existingReadOnlyList.ToList(), newAbbreviations));
@@ -394,63 +452,32 @@ private static IReadOnlyList AddAbbreviationsToList(bool setAsDefault, L
return list.AsReadOnly();
}
- private static AbbreviationMapKey GetAbbreviationMapKey(UnitInfo unitInfo, string cultureName)
+ private static AbbreviationMapKey GetAbbreviationMapKey(UnitInfo unitInfo, CultureInfo culture)
{
- return new AbbreviationMapKey(unitInfo.UnitKey, cultureName);
+ // In order to support running in "invariant mode" (DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1) the FallbackCulture is set to the InvariantCulture.
+ // However, if we want to avoid having two entries in the cache ("", "en-US"), we need to map the invariant culture name to the primary localization language.
+ return new AbbreviationMapKey(unitInfo.UnitKey, culture.Name == string.Empty ? "en-US" : culture.Name);
}
-
- private static string GetCultureNameOrEnglish(CultureInfo culture)
- {
- // Fallback culture is invariant to support DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1,
- // but we need to map that to the primary localization, English.
- return culture.Equals(CultureInfo.InvariantCulture)
- ? "en-US"
- : culture.Name;
- }
-
- private IReadOnlyList ReadAbbreviationsFromResourceFile(string? quantityName, string unitPluralName, CultureInfo culture)
+
+ private static List ReadAbbreviationsFromResourceFile(UnitInfo unitInfo, CultureInfo culture)
{
var abbreviationsList = new List();
-
- if (quantityName is null) return abbreviationsList.AsReadOnly();
-
+ // we currently don't have any way of providing external resource dictionaries
+ Assembly unitAssembly = unitInfo.UnitKey.UnitType.Assembly;
+ if (unitAssembly != typeof(UnitAbbreviationsCache).Assembly)
+ {
+ return abbreviationsList;
+ }
+
+ var quantityName = unitInfo.QuantityName;
string resourceName = $"UnitsNet.GeneratedCode.Resources.{quantityName}";
- var resourceManager = new ResourceManager(resourceName, GetType().Assembly);
+ var resourceManager = new ResourceManager(resourceName, unitAssembly);
- var abbreviationsString = resourceManager.GetString(unitPluralName, culture);
+ var abbreviationsString = resourceManager.GetString(unitInfo.PluralName, culture);
if(abbreviationsString is not null)
abbreviationsList.AddRange(abbreviationsString.Split(','));
- return abbreviationsList.AsReadOnly();
- }
-
- ///
- /// Retrieves a list of unit information objects that match the specified unit abbreviation.
- ///
- /// An optional format provider to use for culture-specific formatting.
- /// The unit abbreviation to search for.
- /// A list of objects that match the specified unit abbreviation.
- ///
- /// This method performs a case-sensitive match to reduce ambiguity. For example, "cm" could match both
- /// LengthUnit.Centimeter (cm) and
- /// MolarityUnit.CentimolePerLiter (cM).
- ///
- internal List GetUnitsForAbbreviation(IFormatProvider? formatProvider, string unitAbbreviation)
- {
- // TODO this is certain to have terrible performance (especially on the first run)
- // TODO we should consider adding a (lazy) dictionary for these
- // Use case-sensitive match to reduce ambiguity.
- // Don't use UnitParser.TryParse() here, since it allows case-insensitive match per quantity as long as there are no ambiguous abbreviations for
- // units of that quantity, but here we try all quantities and this results in too high of a chance for ambiguous matches,
- // such as "cm" matching both LengthUnit.Centimeter (cm) and MolarityUnit.CentimolePerLiter (cM).
- return QuantityInfoLookup.Infos
- .SelectMany(quantityInfo => quantityInfo.UnitInfos)
- .Select(unitInfo => GetAbbreviations(unitInfo, formatProvider).Contains(unitAbbreviation, StringComparer.Ordinal)
- ? unitInfo
- : null)
- .Where(unitValue => unitValue != null)
- .Select(unitValue => unitValue!)
- .ToList();
+ return abbreviationsList;
}
}
}
diff --git a/UnitsNet/CustomCode/UnitParser.cs b/UnitsNet/CustomCode/UnitParser.cs
index e31612211d..4b1e49da2d 100644
--- a/UnitsNet/CustomCode/UnitParser.cs
+++ b/UnitsNet/CustomCode/UnitParser.cs
@@ -6,309 +6,581 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
+using System.Text;
using UnitsNet.Units;
// ReSharper disable once CheckNamespace
-namespace UnitsNet
+namespace UnitsNet;
+
+///
+/// Parses units given a unit abbreviations cache.
+/// A static instance is created in the , which is used internally to parse
+/// quantities and units using the
+/// default abbreviations cache for all units and abbreviations defined in the library.
+///
+public sealed class UnitParser
{
///
- /// Parses units given a unit abbreviations cache.
- /// The static instance is used internally to parse quantities and units using the
+ /// Initializes a new instance of the class using the specified collection of quantity
+ /// information.
+ ///
+ ///
+ /// A read-only collection of quantity information used to initialize the unit abbreviations cache.
+ ///
+ public UnitParser(IEnumerable quantities)
+ : this(new UnitAbbreviationsCache(quantities))
+ {
+ }
+
+ internal UnitParser(QuantityInfoLookup quantitiesLookup)
+ : this(new UnitAbbreviationsCache(quantitiesLookup))
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class using the specified unit abbreviations cache.
+ ///
+ ///
+ /// The cache containing unit abbreviations. If null, the default cache will be used.
+ ///
+ public UnitParser(UnitAbbreviationsCache unitAbbreviationsCache)
+ {
+ Abbreviations = unitAbbreviationsCache ?? throw new ArgumentNullException(nameof(unitAbbreviationsCache));
+ }
+
+ ///
+ /// Gets the instance used by this .
+ /// This cache contains mappings of unit abbreviations to their corresponding units, enabling efficient
+ /// parsing and retrieval of unit information.
+ ///
+ public UnitAbbreviationsCache Abbreviations { get; }
+
+ ///
+ /// Gets the collection of quantities available in this instance.
+ ///
+ ///
+ /// This property provides access to the that contains
+ /// information about all quantities and their associated units.
+ ///
+ internal QuantityInfoLookup Quantities
+ {
+ get => Abbreviations.Quantities;
+ }
+
+ ///
+ /// The default static instance used internally to parse quantities and units using the
/// default abbreviations cache for all units and abbreviations defined in the library.
///
- public sealed class UnitParser
+ public static UnitParser Default => UnitsNetSetup.Default.UnitParser;
+
+ ///
+ /// Creates a default instance of the class with all the built-in unit abbreviations defined
+ /// in the library.
+ ///
+ /// A instance with the default abbreviations cache.
+ public static UnitParser CreateDefault()
{
- private readonly UnitAbbreviationsCache _unitAbbreviationsCache;
-
- ///
- /// The default singleton instance for parsing units from the default configured unit abbreviations.
- ///
- ///
- /// Convenience shortcut for ...
- ///
- public static UnitParser Default => UnitsNetSetup.Default.UnitParser;
-
- ///
- /// Create a parser using the given unit abbreviations cache.
- ///
- /// The unit abbreviations to parse with.
- /// No unit abbreviations cache was given.
- public UnitParser(UnitAbbreviationsCache unitAbbreviationsCache)
- {
- _unitAbbreviationsCache = unitAbbreviationsCache ?? throw new ArgumentNullException(nameof(unitAbbreviationsCache));
- }
+ return new UnitParser(UnitAbbreviationsCache.CreateDefault());
+ }
+
+ ///
+ /// Parses a unit abbreviation for a given unit enumeration type.
+ /// Example: Parse<LengthUnit>("km") => LengthUnit.Kilometer
+ ///
+ ///
+ /// The format provider to use for lookup. Defaults to if null.
+ ///
+ ///
+ public TUnitType Parse(string unitAbbreviation, IFormatProvider? formatProvider = null)
+ where TUnitType : struct, Enum
+ {
+ if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation));
+
+ QuantityInfo quantityInfo = Quantities.GetQuantityByUnitType(typeof(TUnitType));
+ return Parse(unitAbbreviation, quantityInfo.UnitInfos, formatProvider).UnitKey.ToUnit();
+ }
+
+ ///
+ /// Parse a unit abbreviation, such as "kg" or "m", to the unit enum value of the enum type
+ /// .
+ ///
+ ///
+ /// Unit abbreviation, such as "kg" or "m" for and
+ /// respectively.
+ ///
+ /// Unit enum type, such as and .
+ /// The format provider to use for lookup. Defaults to if null.
+ /// Unit enum value, such as .
+ /// No units match the abbreviation.
+ /// More than one unit matches the abbreviation.
+ public Enum Parse(string unitAbbreviation, Type unitType, IFormatProvider? formatProvider = null)
+ {
+ if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation));
- ///
- /// Parses a unit abbreviation for a given unit enumeration type.
- /// Example: Parse<LengthUnit>("km") => LengthUnit.Kilometer
- ///
- ///
- /// The format provider to use for lookup. Defaults to if null.
- ///
- ///
- public TUnitType Parse(string unitAbbreviation, IFormatProvider? formatProvider = null)
- where TUnitType : struct, Enum
+ QuantityInfo quantityInfo = Quantities.GetQuantityByUnitType(unitType);
+ return Parse(unitAbbreviation, quantityInfo.UnitInfos, formatProvider).Value;
+ }
+
+ ///
+ /// Parses the specified unit abbreviation, such as "kg" or "m", to find the corresponding unit information.
+ ///
+ /// The type of the unit information.
+ /// The abbreviation of the unit to parse.
+ /// A collection of unit information to search through.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// The unit information that matches the specified abbreviation.
+ /// Thrown when is null.
+ /// Thrown when no matching unit is found.
+ /// Thrown when multiple matching units are found.
+ internal TUnitInfo Parse(string unitAbbreviation, IReadOnlyList units, IFormatProvider? formatProvider = null)
+ where TUnitInfo : UnitInfo
+ {
+ if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation));
+
+ if (formatProvider is not CultureInfo culture)
{
- return (TUnitType)Parse(unitAbbreviation, typeof(TUnitType), formatProvider);
+ culture = CultureInfo.CurrentCulture;
}
-
- ///
- /// Parse a unit abbreviation, such as "kg" or "m", to the unit enum value of the enum type
- /// .
- ///
- ///
- /// Unit abbreviation, such as "kg" or "m" for and
- /// respectively.
- ///
- /// Unit enum type, such as and .
- /// The format provider to use for lookup. Defaults to if null.
- /// Unit enum value, such as .
- /// No units match the abbreviation.
- /// More than one unit matches the abbreviation.
- public Enum Parse(string unitAbbreviation, Type unitType, IFormatProvider? formatProvider = null)
+
+ unitAbbreviation = unitAbbreviation.Trim();
+ while (true)
{
- if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation));
- unitAbbreviation = unitAbbreviation.Trim();
- Enum[] enumValues = Enum.GetValues(unitType).Cast().ToArray();
- while (true)
+ List<(TUnitInfo UnitInfo, string Abbreviation)> matches = FindMatchingUnits(unitAbbreviation, units, culture);
+ switch (matches.Count)
{
- (Enum Unit, string Abbreviation)[] matches = FindMatchingUnits(unitAbbreviation, enumValues, formatProvider);
- switch(matches.Length)
- {
- case 1:
- return matches[0].Unit;
- case 0:
- // Retry with fallback culture, if different.
- if (Equals(formatProvider, UnitAbbreviationsCache.FallbackCulture))
- {
- throw new UnitNotFoundException($"Unit not found with abbreviation [{unitAbbreviation}] for unit type [{unitType}].");
- }
-
- formatProvider = UnitAbbreviationsCache.FallbackCulture;
+ case 1:
+ return matches[0].UnitInfo;
+ case 0:
+ // Retry with fallback culture, if different.
+ if (UnitAbbreviationsCache.HasFallbackCulture(culture))
+ {
+ culture = UnitAbbreviationsCache.FallbackCulture;
continue;
- default:
- var unitsCsv = string.Join(", ", matches.Select(x => $"{Enum.GetName(unitType, x.Unit)} (\"{x.Abbreviation}\")").OrderBy(x => x));
- throw new AmbiguousUnitParseException($"Cannot parse \"{unitAbbreviation}\" since it matches multiple units: {unitsCsv}.");
- }
+ }
+
+ throw new UnitNotFoundException($"Unit not found with abbreviation [{unitAbbreviation}] for unit type [{typeof(TUnitInfo)}].");
+ default:
+ var unitsCsv = string.Join(", ", matches.Select(x => $"{x.UnitInfo.Name} (\"{x.Abbreviation}\")").OrderBy(x => x));
+ throw new AmbiguousUnitParseException($"Cannot parse \"{unitAbbreviation}\" since it matches multiple units: {unitsCsv}.");
}
}
+ }
+
- internal static string NormalizeUnitString(string unitAbbreviation)
+ internal static string NormalizeUnitString(string unitAbbreviation)
+ {
+ var abbreviationLength = unitAbbreviation.Length;
+ if (abbreviationLength == 0)
{
- // remove all whitespace in the string
- unitAbbreviation = new string(unitAbbreviation.Where(c => !char.IsWhiteSpace(c)).ToArray());
-
- unitAbbreviation = unitAbbreviation.Replace("^-9", "⁻⁹");
- unitAbbreviation = unitAbbreviation.Replace("^-8", "⁻⁸");
- unitAbbreviation = unitAbbreviation.Replace("^-7", "⁻⁷");
- unitAbbreviation = unitAbbreviation.Replace("^-6", "⁻⁶");
- unitAbbreviation = unitAbbreviation.Replace("^-5", "⁻⁵");
- unitAbbreviation = unitAbbreviation.Replace("^-4", "⁻⁴");
- unitAbbreviation = unitAbbreviation.Replace("^-3", "⁻³");
- unitAbbreviation = unitAbbreviation.Replace("^-2", "⁻²");
- unitAbbreviation = unitAbbreviation.Replace("^-1", "⁻¹");
- unitAbbreviation = unitAbbreviation.Replace("^1", "");
- unitAbbreviation = unitAbbreviation.Replace("^2", "²");
- unitAbbreviation = unitAbbreviation.Replace("^3", "³");
- unitAbbreviation = unitAbbreviation.Replace("^4", "⁴");
- unitAbbreviation = unitAbbreviation.Replace("^5", "⁵");
- unitAbbreviation = unitAbbreviation.Replace("^6", "⁶");
- unitAbbreviation = unitAbbreviation.Replace("^7", "⁷");
- unitAbbreviation = unitAbbreviation.Replace("^8", "⁸");
- unitAbbreviation = unitAbbreviation.Replace("^9", "⁹");
- unitAbbreviation = unitAbbreviation.Replace("*", "·");
- // "\u03bc" = Lower case Greek letter 'Mu'
- // "\u00b5" = Micro sign
- unitAbbreviation = unitAbbreviation.Replace("\u03bc", "\u00b5");
-
return unitAbbreviation;
}
- ///
- /// Try to parse a unit abbreviation.
- ///
- /// The string value.
- /// The unit enum value as out result.
- /// Type of unit enum.
- /// True if successful.
- public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, out TUnitType unit)
- where TUnitType : struct, Enum
+ // Remove all whitespace using StringBuilder
+ var sb = new StringBuilder(abbreviationLength);
+ for (var i = 0; i < unitAbbreviation.Length; i++)
{
- return TryParse(unitAbbreviation, null, out unit);
+ var character = unitAbbreviation[i];
+ if (!char.IsWhiteSpace(character))
+ {
+ sb.Append(character);
+ }
}
- ///
- /// Try to parse a unit abbreviation.
- ///
- /// The string value.
- /// The format provider to use for lookup. Defaults to if null.
- /// The unit enum value as out result.
- /// Type of unit enum.
- /// True if successful.
- public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, IFormatProvider? formatProvider, out TUnitType unit)
- where TUnitType : struct, Enum
+ // Perform replacements using StringBuilder
+ sb.Replace("^-9", "⁻⁹")
+ .Replace("^-8", "⁻⁸")
+ .Replace("^-7", "⁻⁷")
+ .Replace("^-6", "⁻⁶")
+ .Replace("^-5", "⁻⁵")
+ .Replace("^-4", "⁻⁴")
+ .Replace("^-3", "⁻³")
+ .Replace("^-2", "⁻²")
+ .Replace("^-1", "⁻¹")
+ .Replace("^1", "")
+ .Replace("^2", "²")
+ .Replace("^3", "³")
+ .Replace("^4", "⁴")
+ .Replace("^5", "⁵")
+ .Replace("^6", "⁶")
+ .Replace("^7", "⁷")
+ .Replace("^8", "⁸")
+ .Replace("^9", "⁹")
+ .Replace("*", "·")
+ .Replace("\u03bc", "\u00b5"); // Greek letter 'Mu' to Micro sign
+
+ return sb.ToString();
+ }
+
+ ///
+ /// Try to parse a unit abbreviation.
+ ///
+ /// The string value.
+ /// The unit enum value as out result.
+ /// Type of unit enum.
+ /// True if successful.
+ public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, out TUnitType unit)
+ where TUnitType : struct, Enum
+ {
+ return TryParse(unitAbbreviation, null, out unit);
+ }
+
+ ///
+ /// Try to parse a unit abbreviation.
+ ///
+ /// The string value.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// The unit enum value as out result.
+ /// Type of unit enum.
+ /// True if successful.
+ public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, IFormatProvider? formatProvider, out TUnitType unit)
+ where TUnitType : struct, Enum
+ {
+ if (!TryParse(unitAbbreviation, typeof(TUnitType), formatProvider, out Enum? unitObj))
{
unit = default;
+ return false;
+ }
+
+ unit = (TUnitType)unitObj;
+ return true;
+ }
+
+ ///
+ /// Try to parse a unit abbreviation.
+ ///
+ /// The string value.
+ /// Type of unit enum.
+ /// The unit enum value as out result.
+ /// True if successful.
+ public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, Type unitType, [NotNullWhen(true)] out Enum? unit)
+ {
+ return TryParse(unitAbbreviation, unitType, null, out unit);
+ }
- if (!TryParse(unitAbbreviation, typeof(TUnitType), formatProvider, out var unitObj))
- return false;
+ ///
+ /// Try to parse a unit abbreviation.
+ ///
+ /// The string value.
+ /// Type of unit enum.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// The unit enum value as out result.
+ /// True if successful.
+ public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType, IFormatProvider? formatProvider, [NotNullWhen(true)] out Enum? unit)
+ {
+ if (unitAbbreviation == null)
+ {
+ unit = null;
+ return false;
+ }
- unit = (TUnitType)unitObj;
+ if (Quantities.TryGetQuantityByUnitType(unitType, out QuantityInfo? quantityInfo) &&
+ TryParse(unitAbbreviation, quantityInfo.UnitInfos, formatProvider, out UnitInfo? unitInfo))
+ {
+ unit = unitInfo.Value;
return true;
}
- ///
- /// Try to parse a unit abbreviation.
- ///
- /// The string value.
- /// Type of unit enum.
- /// The unit enum value as out result.
- /// True if successful.
- public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType, [NotNullWhen(true)] out Enum? unit)
+ unit = null;
+ return false;
+ }
+
+ ///
+ /// Attempts to parse the specified unit abbreviation, such as "kg" or "m", into a unit of the specified type.
+ ///
+ /// The type of the unit enumeration.
+ /// The unit abbreviation to parse.
+ /// The quantity information that provides context for the unit.
+ /// The format provider to use for lookup. Defaults to if null.
+ ///
+ /// When this method returns, contains the parsed unit if the parsing succeeded, or null if the parsing failed.
+ ///
+ ///
+ /// true if the unit abbreviation was successfully parsed; otherwise, false.
+ ///
+ internal bool TryParse([NotNullWhen(true)] string? unitAbbreviation, QuantityInfo quantityInfo, IFormatProvider? formatProvider,
+ out TUnit unit)
+ where TUnit : struct, Enum
+ {
+ if (TryParse(unitAbbreviation, quantityInfo.UnitInfos, formatProvider, out UnitInfo? unitInfo))
{
- return TryParse(unitAbbreviation, unitType, null, out unit);
+ unit = unitInfo.Value;
+ return true;
}
- ///
- /// Try to parse a unit abbreviation.
- ///
- /// The string value.
- /// Type of unit enum.
- /// The format provider to use for lookup. Defaults to if null.
- /// The unit enum value as out result.
- /// True if successful.
- public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType, IFormatProvider? formatProvider, [NotNullWhen(true)] out Enum? unit)
+ unit = default;
+ return false;
+ }
+
+ ///
+ /// Attempts to match the provided unit abbreviation against the defined abbreviations for the units and returns the
+ /// matching unit information.
+ ///
+ /// The type of the unit information.
+ /// The unit abbreviation to match.
+ /// The collection of units to match against.
+ /// The format provider to use for lookup. Defaults to if null.
+ ///
+ /// When this method returns, contains the matching unit information if the match was successful; otherwise, the
+ /// default value for the type of the unit parameter.
+ ///
+ ///
+ /// true if the unit abbreviation was successfully matched; otherwise, false.
+ ///
+ internal bool TryParse([NotNullWhen(true)] string? unitAbbreviation, IReadOnlyList units, IFormatProvider? formatProvider,
+ [NotNullWhen(true)] out TUnitInfo? unit)
+ where TUnitInfo : UnitInfo
+ {
+ unit = null;
+ if (unitAbbreviation == null)
{
- unit = null;
- if (unitAbbreviation == null)
- {
- return false;
- }
+ return false;
+ }
+
+ unitAbbreviation = unitAbbreviation.Trim();
+
+ if (formatProvider is not CultureInfo culture)
+ {
+ culture = CultureInfo.CurrentCulture;
+ }
+
+ List<(TUnitInfo UnitInfo, string Abbreviation)> matches = FindMatchingUnits(unitAbbreviation, units, culture);
+
+ if (matches.Count == 1)
+ {
+ unit = matches[0].UnitInfo;
+ return true;
+ }
+
+ if (matches.Count != 0 || !UnitAbbreviationsCache.HasFallbackCulture(culture))
+ {
+ return false; // either there are duplicates or nothing was matched and we're already using the fallback culture
+ }
- unitAbbreviation = unitAbbreviation.Trim();
- Enum[] enumValues = Enum.GetValues(unitType).Cast().ToArray();
- (Enum Unit, string Abbreviation)[] matches = FindMatchingUnits(unitAbbreviation, enumValues, formatProvider);
+ // retry the lookup using the fallback culture
+ matches = FindMatchingUnits(unitAbbreviation, units, UnitAbbreviationsCache.FallbackCulture);
+ if (matches.Count != 1)
+ {
+ return false;
+ }
+
+ unit = matches[0].UnitInfo;
+ return true;
+ }
- if (matches.Length == 1)
- {
- unit = matches[0].Unit;
- return true;
- }
+ private List<(TUnitInfo UnitInfo, string Abbreviation)> FindMatchingUnits(string unitAbbreviation, IReadOnlyList units,
+ CultureInfo culture)
+ where TUnitInfo : UnitInfo
+ {
+ List<(TUnitInfo UnitInfo, string Abbreviation)> caseInsensitiveMatches = FindMatchingUnitsForCulture(units, unitAbbreviation, culture, StringComparison.OrdinalIgnoreCase);
- if (matches.Length != 0 || Equals(formatProvider, UnitAbbreviationsCache.FallbackCulture))
+ if (caseInsensitiveMatches.Count == 0)
+ {
+ var normalizeUnitString = NormalizeUnitString(unitAbbreviation);
+ if (unitAbbreviation == normalizeUnitString)
{
- return false; // either there are duplicates or nothing was matched and we're already using the fallback culture
+ return caseInsensitiveMatches;
}
- // retry the lookup using the fallback culture
- matches = FindMatchingUnits(unitAbbreviation, enumValues, UnitAbbreviationsCache.FallbackCulture);
- if (matches.Length != 1)
+ unitAbbreviation = normalizeUnitString;
+ caseInsensitiveMatches = FindMatchingUnitsForCulture(units, unitAbbreviation, culture, StringComparison.OrdinalIgnoreCase);
+ if (caseInsensitiveMatches.Count == 0)
{
- return false;
+ return caseInsensitiveMatches;
}
+ }
- unit = matches[0].Unit;
- return true;
+ var nbAbbreviationsFound = caseInsensitiveMatches.Count;
+ if (nbAbbreviationsFound == 1)
+ {
+ return caseInsensitiveMatches;
}
- private (Enum Unit, string Abbreviation)[] FindMatchingUnits(string unitAbbreviation, IEnumerable enumValues, IFormatProvider? formatProvider)
+ // Narrow the search if too many hits, for example Megabar "Mbar" and Millibar "mbar" need to be distinguished
+ var caseSensitiveMatches = new List<(TUnitInfo UnitInfo, string Abbreviation)>(nbAbbreviationsFound);
+ for (var i = 0; i < nbAbbreviationsFound; i++)
{
- // TODO see about optimizing this method: both Parse and TryParse only care about having one match (in case of a failure we could return the number of matches)
- List<(Enum Unit, string Abbreviation)> stringUnitPairs = _unitAbbreviationsCache.GetStringUnitPairs(enumValues, formatProvider);
- (Enum Unit, string Abbreviation)[] matches =
- stringUnitPairs.Where(pair => pair.Abbreviation.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray();
+ (TUnitInfo UnitInfo, string Abbreviation) match = caseInsensitiveMatches[i];
+ if (unitAbbreviation == match.Abbreviation)
+ {
+ caseSensitiveMatches.Add(match);
+ }
+ }
- // No match? Retry after normalizing the unit abbreviation.
- if (matches.Length == 0)
+ return caseSensitiveMatches.Count == 0 ? caseInsensitiveMatches : caseSensitiveMatches;
+ }
+
+ private List<(TUnitInfo UnitInfo, string Abbreviation)> FindMatchingUnitsForCulture(IReadOnlyList unitInfos, string unitAbbreviation,
+ CultureInfo culture, StringComparison comparison)
+ where TUnitInfo: UnitInfo
+ {
+ var unitAbbreviationsPairs = new List<(TUnitInfo, string)>();
+ var nbUnits = unitInfos.Count;
+ for (var i = 0; i < nbUnits; i++)
+ {
+ TUnitInfo unitInfo = unitInfos[i];
+ IReadOnlyList abbreviations = Abbreviations.GetAbbreviationsForCulture(unitInfo, culture);
+ var nbAbbreviations = abbreviations.Count;
+ for (var p = 0; p < nbAbbreviations; p++)
{
- var normalizeUnitString = NormalizeUnitString(unitAbbreviation);
- if (unitAbbreviation != normalizeUnitString)
+ var abbreviation = abbreviations[p];
+ if (unitAbbreviation.Equals(abbreviation, comparison))
{
- unitAbbreviation = normalizeUnitString;
- matches = stringUnitPairs.Where(pair => pair.Abbreviation.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray();
+ unitAbbreviationsPairs.Add((unitInfo, abbreviation));
}
}
+ }
- if (matches.Length == 1)
- {
- return matches;
- }
+ return unitAbbreviationsPairs;
+ }
- // Narrow the search if too many hits, for example Megabar "Mbar" and Millibar "mbar" need to be distinguished
- (Enum Unit, string Abbreviation)[] caseSensitiveMatches = stringUnitPairs.Where(pair => pair.Abbreviation.Equals(unitAbbreviation)).ToArray();
- return caseSensitiveMatches.Length == 0 ? matches : caseSensitiveMatches;
+ ///
+ /// Retrieves the unit information corresponding to the specified unit abbreviation.
+ ///
+ /// The unit abbreviation to parse. Cannot be null or empty.
+ /// The format provider to use for lookup. Defaults to if null.
+ /// The instance representing the parsed unit.
+ ///
+ /// Thrown when is null.
+ ///
+ ///
+ /// Thrown when the unit abbreviation is not recognized as a valid unit for the specified culture.
+ ///
+ ///
+ /// Thrown when multiple units match the given unit abbreviation, making the result ambiguous.
+ ///
+ ///
+ /// This method performs a series of searches to find the unit:
+ ///
+ /// - Case-sensitive search using the current culture.
+ /// - Case-sensitive search using the fallback culture, if applicable.
+ /// - Case-insensitive search.
+ ///
+ /// Note that this method is not optimized for performance, as it enumerates all units and their abbreviations
+ /// during each invocation.
+ ///
+ public UnitInfo GetUnitFromAbbreviation(string unitAbbreviation, IFormatProvider? formatProvider)
+ {
+ if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation));
+
+ List<(UnitInfo UnitInfo, string Abbreviation)> matches = FindAllMatchingUnits(unitAbbreviation, formatProvider);
+ switch (matches.Count)
+ {
+ case 1:
+ return matches[0].UnitInfo;
+ case 0:
+ throw new UnitNotFoundException($"Unit not found with abbreviation [{unitAbbreviation}].");
+ default:
+ var unitsCsv = string.Join(", ", matches.Select(x => $"{x.UnitInfo.Name} (\"{x.Abbreviation}\")").OrderBy(x => x));
+ throw new AmbiguousUnitParseException($"Cannot parse \"{unitAbbreviation}\" since it matches multiple units: {unitsCsv}.");
}
+ }
- ///
- /// Retrieves the unit information from the given unit abbreviation.
- ///
- ///
- /// This method is currently not optimized for performance and will enumerate all units and their unit abbreviations
- /// each time.
- /// Unit abbreviation matching in the
- /// overload is case-insensitive.
- ///
- /// This will fail if more than one unit across all quantities share the same unit abbreviation.
- ///
- /// The unit abbreviation to parse.
- /// The format provider to use for culture-specific formatting. Can be null.
- /// The unit information corresponding to the given unit abbreviation.
- ///
- /// Thrown when the unit abbreviation is not recognized as a valid unit for the specified culture.
- ///
- ///
- /// Thrown when multiple units are found matching the given unit abbreviation.
- ///
- internal UnitInfo GetUnitFromAbbreviation(string unitAbbreviation, IFormatProvider? formatProvider)
+ ///
+ /// Attempts to parse the specified unit abbreviation into an object.
+ ///
+ /// The unit abbreviation to parse.
+ /// The format provider to use for lookup. Defaults to if null.
+ ///
+ /// When this method returns, contains the parsed object if the parsing succeeded,
+ /// or null if the parsing failed. This parameter is passed uninitialized.
+ ///
+ ///
+ /// true if the unit abbreviation was successfully parsed; otherwise, false.
+ ///
+ ///
+ /// This method performs a series of searches to find the unit:
+ ///
+ /// - Case-sensitive search using the current culture.
+ /// - Case-sensitive search using the fallback culture, if applicable.
+ /// - Case-insensitive search.
+ ///
+ /// Note that this method is not optimized for performance, as it enumerates all units and their abbreviations
+ /// during each invocation.
+ ///
+ public bool TryGetUnitFromAbbreviation([NotNullWhen(true)]string? unitAbbreviation, IFormatProvider? formatProvider, [NotNullWhen(true)] out UnitInfo? unit)
+ {
+ if (unitAbbreviation == null)
{
- List units = _unitAbbreviationsCache.GetUnitsForAbbreviation(formatProvider, unitAbbreviation);
- return units.Count switch
- {
- 0 => throw new UnitNotFoundException(
- $"The unit abbreviation '{unitAbbreviation}' is not recognized as a valid unit for the specified culture."),
- 1 => units[0],
- _ => throw new AmbiguousUnitParseException(
- $"Cannot parse \"{unitAbbreviation}\" since it matches multiple units: {string.Join(", ", units.Select(x => x.Name).OrderBy(x => x))}.")
- };
+ unit = null;
+ return false;
}
+
+ List<(UnitInfo UnitInfo, string Abbreviation)> matches = FindAllMatchingUnits(unitAbbreviation, formatProvider);
+ if (matches.Count == 1)
+ {
+ unit = matches[0].UnitInfo;
+ return true;
+ }
+
+ unit = null;
+ return false;
+ }
- ///
- /// Attempts to parse the specified unit abbreviation into an object.
- ///
- ///
- /// This method is currently not optimized for performance and will enumerate all units and their unit abbreviations
- /// each time.
- /// Unit abbreviation matching in the
- /// overload is case-insensitive.
- ///
- /// This will fail if more than one unit across all quantities share the same unit abbreviation.
- ///
- /// The unit abbreviation to parse.
- /// The format provider to use for parsing, or null to use the current culture.
- ///
- /// When this method returns, contains the parsed object if the parsing succeeded,
- /// or null if the parsing failed. This parameter is passed uninitialized.
- ///
- ///
- /// true if the unit abbreviation was successfully parsed; otherwise, false.
- ///
- internal bool TryGetUnitFromAbbreviation([NotNullWhen(true)]string? unitAbbreviation, IFormatProvider? formatProvider, [NotNullWhen(true)] out UnitInfo? unit)
+ private List<(UnitInfo UnitInfo, string Abbreviation)> FindAllMatchingUnits(string unitAbbreviation, IFormatProvider? formatProvider)
+ {
+ if (formatProvider is not CultureInfo culture)
+ {
+ culture = CultureInfo.CurrentCulture;
+ }
+
+ unitAbbreviation = unitAbbreviation.Trim();
+ StringComparison comparison = StringComparison.Ordinal;
+ while (true)
{
- if (unitAbbreviation == null)
+ List<(UnitInfo UnitInfo, string Abbreviation)> matches = FindAllMatchingUnitsForCulture(unitAbbreviation, culture, comparison);
+ if (matches.Count != 0)
+ {
+ return matches;
+ }
+
+ // Retry with fallback culture, if different.
+ if (UnitAbbreviationsCache.HasFallbackCulture(culture))
+ {
+ culture = UnitAbbreviationsCache.FallbackCulture;
+ continue;
+ }
+
+ var normalizedUnitString = NormalizeUnitString(unitAbbreviation);
+ if (normalizedUnitString != unitAbbreviation)
{
- unit = null;
- return false;
+ unitAbbreviation = normalizedUnitString;
+ continue;
}
- List units = _unitAbbreviationsCache.GetUnitsForAbbreviation(formatProvider, unitAbbreviation);
- if (units.Count == 1)
+ if (comparison == StringComparison.Ordinal)
{
- unit = units[0];
- return true;
+ comparison = StringComparison.OrdinalIgnoreCase;
+ continue;
}
- unit = null;
- return false;
+ return matches;
}
}
+
+ private List<(UnitInfo UnitInfo, string Abbreviation)> FindAllMatchingUnitsForCulture(string unitAbbreviation, CultureInfo culture,
+ StringComparison comparison)
+ {
+ var unitAbbreviationsPairs = new List<(UnitInfo, string)>();
+ foreach (QuantityInfo quantityInfo in Quantities.Infos)
+ {
+ IReadOnlyList unitInfos = quantityInfo.UnitInfos;
+ var nbUnits = unitInfos.Count;
+ for (var i = 0; i < nbUnits; i++)
+ {
+ UnitInfo unitInfo = unitInfos[i];
+ IReadOnlyList abbreviations = Abbreviations.GetAbbreviationsForCulture(unitInfo, culture);
+ var nbAbbreviations = abbreviations.Count;
+ for (var p = 0; p < nbAbbreviations; p++)
+ {
+ var abbreviation = abbreviations[p];
+ if (unitAbbreviation.Equals(abbreviation, comparison))
+ {
+ unitAbbreviationsPairs.Add((unitInfo, abbreviation));
+ }
+ }
+ }
+ }
+
+ return unitAbbreviationsPairs;
+ }
}
diff --git a/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs b/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs
index 6526699053..a3da931238 100644
--- a/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs
@@ -601,7 +601,7 @@ public static AbsorbedDoseOfIonizingRadiationUnit ParseUnit(string str)
/// Error parsing string.
public static AbsorbedDoseOfIonizingRadiationUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -622,7 +622,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AbsorbedDose
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AbsorbedDoseOfIonizingRadiationUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs
index c998ba68e4..9e06043f1c 100644
--- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs
@@ -573,7 +573,7 @@ public static AccelerationUnit ParseUnit(string str)
/// Error parsing string.
public static AccelerationUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -594,7 +594,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out Acceleration
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AccelerationUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs
index 70442d991c..507902a183 100644
--- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs
@@ -622,7 +622,7 @@ public static AmountOfSubstanceUnit ParseUnit(string str)
/// Error parsing string.
public static AmountOfSubstanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -643,7 +643,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AmountOfSubs
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AmountOfSubstanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs
index 824ccb8c40..7b5387f888 100644
--- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs
@@ -392,7 +392,7 @@ public static AmplitudeRatioUnit ParseUnit(string str)
/// Error parsing string.
public static AmplitudeRatioUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -413,7 +413,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AmplitudeRat
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AmplitudeRatioUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs
index 20072f8797..746fed8f0c 100644
--- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs
@@ -573,7 +573,7 @@ public static AngleUnit ParseUnit(string str)
/// Error parsing string.
public static AngleUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -594,7 +594,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AngleUnit un
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AngleUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs
index 4a5eed40b2..172ad23e41 100644
--- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs
@@ -584,7 +584,7 @@ public static AreaUnit ParseUnit(string str)
/// Error parsing string.
public static AreaUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -605,7 +605,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AreaUnit uni
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AreaUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs
index 0092dc509e..225bbc013f 100644
--- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs
@@ -393,7 +393,7 @@ public static AreaDensityUnit ParseUnit(string str)
/// Error parsing string.
public static AreaDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -414,7 +414,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AreaDensityU
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AreaDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs
index 6ea9a72cb7..4dc2556bc6 100644
--- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs
@@ -442,7 +442,7 @@ public static AreaMomentOfInertiaUnit ParseUnit(string str)
/// Error parsing string.
public static AreaMomentOfInertiaUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -463,7 +463,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out AreaMomentOf
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out AreaMomentOfInertiaUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs
index 1fe6c8aa86..7c8e01dd41 100644
--- a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs
@@ -969,7 +969,7 @@ public static BitRateUnit ParseUnit(string str)
/// Error parsing string.
public static BitRateUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -990,7 +990,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out BitRateUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out BitRateUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs
index 3a1c2d2deb..4946afeea5 100644
--- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs
@@ -394,7 +394,7 @@ public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str)
/// Error parsing string.
public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -415,7 +415,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out BrakeSpecifi
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out BrakeSpecificFuelConsumptionUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs
index ac827c70b0..5781ba09eb 100644
--- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs
@@ -441,7 +441,7 @@ public static CoefficientOfThermalExpansionUnit ParseUnit(string str)
/// Error parsing string.
public static CoefficientOfThermalExpansionUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -462,7 +462,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out CoefficientO
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out CoefficientOfThermalExpansionUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs
index 4c83b57d46..5b8c6f92ae 100644
--- a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs
@@ -454,7 +454,7 @@ public static CompressibilityUnit ParseUnit(string str)
/// Error parsing string.
public static CompressibilityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -475,7 +475,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out Compressibil
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out CompressibilityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs
index 10d87c4116..3c014542de 100644
--- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs
@@ -1250,7 +1250,7 @@ public static DensityUnit ParseUnit(string str)
/// Error parsing string.
public static DensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -1271,7 +1271,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out DensityUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out DensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs b/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs
index abeb8f0ed7..bfd99bd4c9 100644
--- a/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs
@@ -665,7 +665,7 @@ public static DoseAreaProductUnit ParseUnit(string str)
/// Error parsing string.
public static DoseAreaProductUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -686,7 +686,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out DoseAreaProd
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out DoseAreaProductUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs
index 56545f36f8..24f12ae393 100644
--- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs
@@ -551,7 +551,7 @@ public static DurationUnit ParseUnit(string str)
/// Error parsing string.
public static DurationUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -572,7 +572,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out DurationUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out DurationUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs
index 179bc68925..3c6756c7df 100644
--- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs
@@ -509,7 +509,7 @@ public static DynamicViscosityUnit ParseUnit(string str)
/// Error parsing string.
public static DynamicViscosityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -530,7 +530,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out DynamicVisco
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out DynamicViscosityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs
index 17dce29980..ca1eee769b 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs
@@ -602,7 +602,7 @@ public static ElectricAdmittanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricAdmittanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -623,7 +623,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricAdmi
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricAdmittanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs
index 9145550d66..0c699e0c30 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs
@@ -390,7 +390,7 @@ public static ElectricApparentEnergyUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricApparentEnergyUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -411,7 +411,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricAppa
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricApparentEnergyUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs
index 6358382f46..a149b65326 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs
@@ -441,7 +441,7 @@ public static ElectricApparentPowerUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricApparentPowerUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -462,7 +462,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricAppa
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricApparentPowerUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs
index e3f0778380..5cb5215d69 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs
@@ -457,7 +457,7 @@ public static ElectricCapacitanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricCapacitanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -478,7 +478,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCapa
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricCapacitanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs
index 13300c172c..fcf9311194 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs
@@ -526,7 +526,7 @@ public static ElectricChargeUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricChargeUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -547,7 +547,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricChar
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricChargeUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs
index b80f4482d0..32461bd3f7 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs
@@ -361,7 +361,7 @@ public static ElectricChargeDensityUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricChargeDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -382,7 +382,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricChar
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricChargeDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs
index 67ed857b98..fae21dd1fa 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs
@@ -601,7 +601,7 @@ public static ElectricConductanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricConductanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -622,7 +622,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCond
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricConductanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs
index 528070f486..5fed8c31e8 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs
@@ -441,7 +441,7 @@ public static ElectricConductivityUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricConductivityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -462,7 +462,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCond
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricConductivityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs
index 637605c6d2..4200e06c35 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs
@@ -496,7 +496,7 @@ public static ElectricCurrentUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricCurrentUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -517,7 +517,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCurr
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricCurrentUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs
index 3515d52d93..ecfd0d16ae 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs
@@ -393,7 +393,7 @@ public static ElectricCurrentDensityUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricCurrentDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -414,7 +414,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCurr
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricCurrentDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs
index c2601bedbe..d04ae5f314 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs
@@ -457,7 +457,7 @@ public static ElectricCurrentGradientUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricCurrentGradientUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -478,7 +478,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCurr
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricCurrentGradientUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs
index 7a0282e459..ee2521842d 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs
@@ -361,7 +361,7 @@ public static ElectricFieldUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricFieldUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -382,7 +382,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricFiel
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricFieldUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs
index 49a4f5531b..2644077589 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs
@@ -474,7 +474,7 @@ public static ElectricImpedanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricImpedanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -495,7 +495,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricImpe
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricImpedanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs
index 72b452c4ac..d097a7c27d 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs
@@ -425,7 +425,7 @@ public static ElectricInductanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricInductanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -446,7 +446,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricIndu
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricInductanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs
index 8e16e66487..704e694ad5 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs
@@ -447,7 +447,7 @@ public static ElectricPotentialUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricPotentialUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -468,7 +468,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricPote
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricPotentialUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs
index 691a696708..9d5d4f89a2 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs
@@ -662,7 +662,7 @@ public static ElectricPotentialChangeRateUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricPotentialChangeRateUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -683,7 +683,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricPote
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricPotentialChangeRateUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs
index 246fa5283e..c0f878043e 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs
@@ -473,7 +473,7 @@ public static ElectricReactanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricReactanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -494,7 +494,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricReac
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricReactanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs
index 1e6ce1b120..23b1548394 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs
@@ -390,7 +390,7 @@ public static ElectricReactiveEnergyUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricReactiveEnergyUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -411,7 +411,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricReac
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricReactiveEnergyUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs
index d16c1b0288..f099e10cab 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs
@@ -409,7 +409,7 @@ public static ElectricReactivePowerUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricReactivePowerUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -430,7 +430,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricReac
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricReactivePowerUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs
index 3b475ee618..4653677919 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs
@@ -476,7 +476,7 @@ public static ElectricResistanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricResistanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -497,7 +497,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricResi
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricResistanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs
index 4591efd124..72581feb7a 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs
@@ -569,7 +569,7 @@ public static ElectricResistivityUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricResistivityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -590,7 +590,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricResi
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricResistivityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs
index cf35e233e7..4adad40dd3 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs
@@ -393,7 +393,7 @@ public static ElectricSurfaceChargeDensityUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricSurfaceChargeDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -414,7 +414,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricSurf
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricSurfaceChargeDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs
index b7962e73d2..3529c1f7b6 100644
--- a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs
@@ -601,7 +601,7 @@ public static ElectricSusceptanceUnit ParseUnit(string str)
/// Error parsing string.
public static ElectricSusceptanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -622,7 +622,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricSusc
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricSusceptanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs
index ee650dd3b1..a113b3d5d2 100644
--- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs
@@ -997,7 +997,7 @@ public static EnergyUnit ParseUnit(string str)
/// Error parsing string.
public static EnergyUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -1018,7 +1018,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out EnergyUnit u
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out EnergyUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs
index c1b7ba7714..e1bec3211c 100644
--- a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs
@@ -537,7 +537,7 @@ public static EnergyDensityUnit ParseUnit(string str)
/// Error parsing string.
public static EnergyDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -558,7 +558,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out EnergyDensit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out EnergyDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs
index 2fb78647f0..8cc1205289 100644
--- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs
@@ -459,7 +459,7 @@ public static EntropyUnit ParseUnit(string str)
/// Error parsing string.
public static EntropyUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -480,7 +480,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out EntropyUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out EntropyUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs
index c5b1913563..e13f9b8e3b 100644
--- a/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs
@@ -649,7 +649,7 @@ public static FluidResistanceUnit ParseUnit(string str)
/// Error parsing string.
public static FluidResistanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -670,7 +670,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out FluidResista
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out FluidResistanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs
index 19e96dc347..0d0f2a152b 100644
--- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs
@@ -596,7 +596,7 @@ public static ForceUnit ParseUnit(string str)
/// Error parsing string.
public static ForceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -617,7 +617,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ForceUnit un
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ForceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs
index 3d2948e876..85efde80b2 100644
--- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs
@@ -585,7 +585,7 @@ public static ForceChangeRateUnit ParseUnit(string str)
/// Error parsing string.
public static ForceChangeRateUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -606,7 +606,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ForceChangeR
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ForceChangeRateUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs
index 5c4934c44c..d1de5aa977 100644
--- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs
@@ -961,7 +961,7 @@ public static ForcePerLengthUnit ParseUnit(string str)
/// Error parsing string.
public static ForcePerLengthUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -982,7 +982,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ForcePerLeng
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ForcePerLengthUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs
index 1e426e232b..aeb1055652 100644
--- a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs
@@ -537,7 +537,7 @@ public static FrequencyUnit ParseUnit(string str)
/// Error parsing string.
public static FrequencyUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -558,7 +558,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out FrequencyUni
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out FrequencyUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs
index 0532819357..afe38fcdc0 100644
--- a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs
@@ -409,7 +409,7 @@ public static FuelEfficiencyUnit ParseUnit(string str)
/// Error parsing string.
public static FuelEfficiencyUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -430,7 +430,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out FuelEfficien
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out FuelEfficiencyUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs
index 9865e36c85..c77e2665c0 100644
--- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs
@@ -633,7 +633,7 @@ public static HeatFluxUnit ParseUnit(string str)
/// Error parsing string.
public static HeatFluxUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -654,7 +654,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out HeatFluxUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out HeatFluxUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs
index fb4ebf6926..fdd3c49adb 100644
--- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs
@@ -422,7 +422,7 @@ public static HeatTransferCoefficientUnit ParseUnit(string str)
/// Error parsing string.
public static HeatTransferCoefficientUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -443,7 +443,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out HeatTransfer
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out HeatTransferCoefficientUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs
index 1a04548857..23c4ea1003 100644
--- a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs
@@ -412,7 +412,7 @@ public static IlluminanceUnit ParseUnit(string str)
/// Error parsing string.
public static IlluminanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -433,7 +433,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out IlluminanceU
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out IlluminanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs
index a56c939e48..5c41946c9f 100644
--- a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs
@@ -550,7 +550,7 @@ public static ImpulseUnit ParseUnit(string str)
/// Error parsing string.
public static ImpulseUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -571,7 +571,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out ImpulseUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out ImpulseUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Information.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.g.cs
index 834fdbf272..95b55122bc 100644
--- a/UnitsNet/GeneratedCode/Quantities/Information.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Information.g.cs
@@ -952,7 +952,7 @@ public static InformationUnit ParseUnit(string str)
/// Error parsing string.
public static InformationUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -973,7 +973,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out InformationU
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out InformationUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs
index 99279811f4..db202c4fc7 100644
--- a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs
@@ -566,7 +566,7 @@ public static IrradianceUnit ParseUnit(string str)
/// Error parsing string.
public static IrradianceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -587,7 +587,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out IrradianceUn
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out IrradianceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs
index 09e764f34d..c751455f3e 100644
--- a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs
@@ -489,7 +489,7 @@ public static IrradiationUnit ParseUnit(string str)
/// Error parsing string.
public static IrradiationUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -510,7 +510,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out IrradiationU
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out IrradiationUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs
index 24b2653260..26c3c5ec49 100644
--- a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs
@@ -521,7 +521,7 @@ public static JerkUnit ParseUnit(string str)
/// Error parsing string.
public static JerkUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -542,7 +542,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out JerkUnit uni
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out JerkUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs
index a1b8edc5a9..6b0ab18495 100644
--- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs
@@ -495,7 +495,7 @@ public static KinematicViscosityUnit ParseUnit(string str)
/// Error parsing string.
public static KinematicViscosityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -516,7 +516,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out KinematicVis
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out KinematicViscosityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs
index 8cf019115c..df75016505 100644
--- a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs
@@ -393,7 +393,7 @@ public static LeakRateUnit ParseUnit(string str)
/// Error parsing string.
public static LeakRateUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -414,7 +414,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LeakRateUnit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LeakRateUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs
index 114cd08a40..9b840b9345 100644
--- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs
@@ -1034,7 +1034,7 @@ public static LengthUnit ParseUnit(string str)
/// Error parsing string.
public static LengthUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -1055,7 +1055,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LengthUnit u
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LengthUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Level.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.g.cs
index a3471b0356..b3164608d9 100644
--- a/UnitsNet/GeneratedCode/Quantities/Level.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Level.g.cs
@@ -360,7 +360,7 @@ public static LevelUnit ParseUnit(string str)
/// Error parsing string.
public static LevelUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -381,7 +381,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LevelUnit un
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LevelUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs
index 14badeb281..b4331da451 100644
--- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs
@@ -638,7 +638,7 @@ public static LinearDensityUnit ParseUnit(string str)
/// Error parsing string.
public static LinearDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -659,7 +659,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LinearDensit
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LinearDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs
index 67279ce157..ba75d89525 100644
--- a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs
@@ -745,7 +745,7 @@ public static LinearPowerDensityUnit ParseUnit(string str)
/// Error parsing string.
public static LinearPowerDensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -766,7 +766,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LinearPowerD
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LinearPowerDensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs
index f4337dcb1f..8ffd9ce7bd 100644
--- a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs
@@ -508,7 +508,7 @@ public static LuminanceUnit ParseUnit(string str)
/// Error parsing string.
public static LuminanceUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -529,7 +529,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LuminanceUni
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LuminanceUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs
index 1ad38df36f..4605d714e9 100644
--- a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs
@@ -569,7 +569,7 @@ public static LuminosityUnit ParseUnit(string str)
/// Error parsing string.
public static LuminosityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -590,7 +590,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LuminosityUn
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LuminosityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs
index f7db868075..768a1f401c 100644
--- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs
@@ -365,7 +365,7 @@ public static LuminousFluxUnit ParseUnit(string str)
/// Error parsing string.
public static LuminousFluxUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -386,7 +386,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LuminousFlux
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LuminousFluxUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs
index 7e2d128ea3..3b67fb319c 100644
--- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs
@@ -365,7 +365,7 @@ public static LuminousIntensityUnit ParseUnit(string str)
/// Error parsing string.
public static LuminousIntensityUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -386,7 +386,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out LuminousInte
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out LuminousIntensityUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs
index cf5eff0f76..9785936997 100644
--- a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs
@@ -441,7 +441,7 @@ public static MagneticFieldUnit ParseUnit(string str)
/// Error parsing string.
public static MagneticFieldUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///
@@ -462,7 +462,7 @@ public static bool TryParseUnit([NotNullWhen(true)]string? str, out MagneticFiel
/// Format to use when parsing number and unit. Defaults to if null.
public static bool TryParseUnit([NotNullWhen(true)]string? str, IFormatProvider? provider, out MagneticFieldUnit unit)
{
- return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit);
+ return UnitParser.Default.TryParse(str, Info, provider, out unit);
}
#endregion
diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs
index 308eb4923c..5dad87e062 100644
--- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs
+++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs
@@ -361,7 +361,7 @@ public static MagneticFluxUnit ParseUnit(string str)
/// Error parsing string.
public static MagneticFluxUnit ParseUnit(string str, IFormatProvider? provider)
{
- return UnitsNetSetup.Default.UnitParser.Parse(str, provider);
+ return UnitParser.Default.Parse(str, Info.UnitInfos, provider).Value;
}
///