From 60e9a7c32321a86c9993adda3f3c6aaa74bb0baa Mon Sep 17 00:00:00 2001 From: lipchev Date: Wed, 3 Apr 2019 11:39:49 +0300 Subject: [PATCH 1/8] Concentration Units (mixtures/solutions) Added the following Concentration Units: - MassConcentration: SI = kg/m3, typically mg/l - VolumeConcentration : dimensionless, typically % - MassFraction: SI = kg/kg, typically mg/kg Modified the existing Molarity unit: - Some operations that were originally based on the Density units now use the MassConcentration units instead (Note: despite the fact that they share the same measurement units- the Density is a distnct QuantyType from the MassConcentration) - Removed all operators involving Molarity from the Density units Defined some basic operations that were missing from the AmountOfSubstance/MolarMass/Mass units Defined the triangular operations involving Mass/Molar/Volume concentrations (& the corresponding component's Density & MolarMass) All unit tests included most were defined by actual chemists(which I AM NOT). Note: one of the tests (QuantityIFormattableTests.VFormatEqualsValueToString)- was failing on my machine- it passes if I add CultureInfo.CurrentUICulture to the value.ToString() - as I presume was the intended behavior --- Common/UnitDefinitions/MassConcentration.json | 246 +++ Common/UnitDefinitions/MassFraction.json | 106 ++ Common/UnitDefinitions/Molarity.json | 15 +- .../UnitDefinitions/VolumeConcentration.json | 106 ++ .../CustomCode/AmountOfSubstanceTests.cs | 52 + UnitsNet.Tests/CustomCode/DensityTests.cs | 20 +- .../CustomCode/MassConcentrationTests.cs | 131 ++ .../CustomCode/MassFractionTests.cs | 93 + UnitsNet.Tests/CustomCode/MolarMassTests.cs | 13 + UnitsNet.Tests/CustomCode/MolarityTests.cs | 99 +- .../CustomCode/VolumeConcentrationTests.cs | 95 ++ UnitsNet.Tests/QuantityIFormattableTests.cs | 2 +- ...Concentration.WindowsRuntimeComponent.g.cs | 1246 ++++++++++++++ .../MassFraction.WindowsRuntimeComponent.g.cs | 974 +++++++++++ .../Molarity.WindowsRuntimeComponent.g.cs | 85 + ...Concentration.WindowsRuntimeComponent.g.cs | 906 ++++++++++ .../GeneratedCode/Quantity.g.cs | 18 + .../GeneratedCode/QuantityType.g.cs | 3 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 93 + .../Units/MassConcentrationUnit.g.cs | 72 + .../GeneratedCode/Units/MassFractionUnit.g.cs | 56 + .../GeneratedCode/Units/MolarityUnit.g.cs | 5 + .../Units/VolumeConcentrationUnit.g.cs | 52 + .../Quantities/AmountOfSubstance.extra.cs | 32 + .../CustomCode/Quantities/Density.extra.cs | 25 - .../Quantities/MassConcentration.extra.cs | 79 + .../Quantities/MassFraction.extra.cs | 57 + .../CustomCode/Quantities/MolarMass.extra.cs | 15 + .../CustomCode/Quantities/Molarity.extra.cs | 64 +- .../Quantities/VolumeConcentration.extra.cs | 69 + .../MassConcentration.NetFramework.g.cs | 1505 +++++++++++++++++ .../Quantities/MassFraction.NetFramework.g.cs | 1233 ++++++++++++++ .../Quantities/Molarity.NetFramework.g.cs | 85 + .../VolumeConcentration.NetFramework.g.cs | 1165 +++++++++++++ UnitsNet/GeneratedCode/Quantity.g.cs | 21 + UnitsNet/GeneratedCode/QuantityType.g.cs | 3 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 93 + .../Units/MassConcentrationUnit.g.cs | 72 + .../GeneratedCode/Units/MassFractionUnit.g.cs | 56 + .../GeneratedCode/Units/MolarityUnit.g.cs | 5 + .../Units/VolumeConcentrationUnit.g.cs | 52 + 41 files changed, 9044 insertions(+), 75 deletions(-) create mode 100644 Common/UnitDefinitions/MassConcentration.json create mode 100644 Common/UnitDefinitions/MassFraction.json create mode 100644 Common/UnitDefinitions/VolumeConcentration.json create mode 100644 UnitsNet.Tests/CustomCode/MassConcentrationTests.cs create mode 100644 UnitsNet.Tests/CustomCode/MassFractionTests.cs create mode 100644 UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/VolumeConcentration.WindowsRuntimeComponent.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassConcentrationUnit.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/VolumeConcentrationUnit.g.cs create mode 100644 UnitsNet/CustomCode/Quantities/MassConcentration.extra.cs create mode 100644 UnitsNet/CustomCode/Quantities/MassFraction.extra.cs create mode 100644 UnitsNet/CustomCode/Quantities/MolarMass.extra.cs create mode 100644 UnitsNet/CustomCode/Quantities/VolumeConcentration.extra.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/VolumeConcentration.NetFramework.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/MassConcentrationUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/VolumeConcentrationUnit.g.cs diff --git a/Common/UnitDefinitions/MassConcentration.json b/Common/UnitDefinitions/MassConcentration.json new file mode 100644 index 0000000000..ed9bdb01e9 --- /dev/null +++ b/Common/UnitDefinitions/MassConcentration.json @@ -0,0 +1,246 @@ +{ + "Name": "MassConcentration", + "BaseUnit": "KilogramPerCubicMeter", + "XmlDoc": "In chemistry, the mass concentration ρi (or γi) is defined as the mass of a constituent mi divided by the volume of the mixture V", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Mass_concentration_(chemistry)", + "BaseDimensions": { + "L": -3, + "M": 1 + }, + "Units": [ + { + "SingularName": "GramPerCubicMillimeter", + "PluralName": "GramsPerCubicMillimeter", + "BaseUnits": { + "L": "Millimeter", + "M": "Gram" + }, + "FromUnitToBaseFunc": "x/1e-6", + "FromBaseToUnitFunc": "x*1e-6", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/mm³" ] + } + ] + }, + { + "SingularName": "GramPerCubicCentimeter", + "PluralName": "GramsPerCubicCentimeter", + "BaseUnits": { + "L": "Centimeter", + "M": "Gram" + }, + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/cm³" ] + } + ] + }, + { + "SingularName": "GramPerCubicMeter", + "PluralName": "GramsPerCubicMeter", + "BaseUnits": { + "L": "Meter", + "M": "Gram" + }, + "FromUnitToBaseFunc": "x/1e3", + "FromBaseToUnitFunc": "x*1e3", + "Prefixes": [ "Kilo", "Milli", "Micro" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/m³" ] + }, + { + "Culture": "ru-RU", + "Abbreviations": [ "г/м³" ] + } + ] + }, + { + "SingularName": "PoundPerCubicInch", + "PluralName": "PoundsPerCubicInch", + "BaseUnits": { + "L": "Inch", + "M": "Pound" + }, + "FromUnitToBaseFunc": "x/3.6127298147753e-5", + "FromBaseToUnitFunc": "x*3.6127298147753e-5", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lb/in³" ], + "AbbreviationsWithPrefixes": [ "kip/in³" ] + } + ] + }, + { + "SingularName": "PoundPerCubicFoot", + "PluralName": "PoundsPerCubicFoot", + "BaseUnits": { + "L": "Foot", + "M": "Pound" + }, + "FromUnitToBaseFunc": "x/0.062427961", + "FromBaseToUnitFunc": "x*0.062427961", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lb/ft³" ], + "AbbreviationsWithPrefixes": [ "kip/ft³" ] + } + ] + }, + { + "SingularName": "TonnePerCubicMillimeter", + "PluralName": "TonnesPerCubicMillimeter", + "BaseUnits": { + "L": "Millimeter", + "M": "Tonne" + }, + "FromUnitToBaseFunc": "x/1e-12", + "FromBaseToUnitFunc": "x*1e-12", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "t/mm³" ] + } + ] + }, + { + "SingularName": "TonnePerCubicCentimeter", + "PluralName": "TonnesPerCubicCentimeter", + "BaseUnits": { + "L": "Centimeter", + "M": "Tonne" + }, + "FromUnitToBaseFunc": "x/1e-9", + "FromBaseToUnitFunc": "x*1e-9", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "t/cm³" ] + } + ] + }, + { + "SingularName": "TonnePerCubicMeter", + "PluralName": "TonnesPerCubicMeter", + "BaseUnits": { + "L": "Meter", + "M": "Tonne" + }, + "FromUnitToBaseFunc": "x/0.001", + "FromBaseToUnitFunc": "x*0.001", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "t/m³" ] + } + ] + }, + { + "SingularName": "SlugPerCubicFoot", + "PluralName": "SlugsPerCubicFoot", + "BaseUnits": { + "L": "Foot", + "M": "Slug" + }, + "FromUnitToBaseFunc": "x*515.378818", + "FromBaseToUnitFunc": "x*0.00194032033", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "slug/ft³" ] + } + ] + }, + { + "SingularName": "GramPerLiter", + "PluralName": "GramsPerLiter", + "FromUnitToBaseFunc": "x/1", + "FromBaseToUnitFunc": "x*1", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/l"] + } + ] + }, + { + "SingularName": "GramPerDeciliter", + "PluralName": "GramsPerDeciLiter", + "FromUnitToBaseFunc": "x/1e-1", + "FromBaseToUnitFunc": "x*1e-1", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/dl" ] + } + ] + }, + { + "SingularName": "GramPerMilliliter", + "PluralName": "GramsPerMilliliter", + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/ml" ] + } + ] + }, + { + "SingularName": "PoundPerUSGallon", + "PluralName": "PoundsPerUSGallon", + "FromUnitToBaseFunc": "x*1.19826427e2", + "FromBaseToUnitFunc": "x/1.19826427e2", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppg (U.S.)" ] + } + ] + }, + { + "SingularName": "PoundPerImperialGallon", + "PluralName": "PoundsPerImperialGallon", + "FromUnitToBaseFunc": "x*9.9776398e1", + "FromBaseToUnitFunc": "x/9.9776398e1", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppg (imp.)" ] + } + ] + }, + { + "SingularName": "KilogramPerLiter", + "PluralName": "KilogramsPerLiter", + "BaseUnits": { + "L": "Decimeter", + "M": "Kilogram" + }, + "FromUnitToBaseFunc": "x*1e3", + "FromBaseToUnitFunc": "x/1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kg/l" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/MassFraction.json b/Common/UnitDefinitions/MassFraction.json new file mode 100644 index 0000000000..53f741eb66 --- /dev/null +++ b/Common/UnitDefinitions/MassFraction.json @@ -0,0 +1,106 @@ +{ + "Name": "MassFraction", + "BaseUnit": "DecimalFraction", + "XmlDoc": "The mass fraction is defined as the mass of a constituent divided by the total mass of the mixture.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Mass_fraction_(chemistry)", + "Units": [ + { + "SingularName": "DecimalFraction", + "PluralName": "DecimalFractions", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "" ] + } + ] + }, + { + "SingularName": "GramPerGram", + "PluralName": "GramsPerGram", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/g" ] + } + ] + }, + { + "SingularName": "GramPerKiloGram", + "PluralName": "GramsPerKiloGram", + "FromUnitToBaseFunc": "x/1e3", + "FromBaseToUnitFunc": "x*1e3", + "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/kg" ] + } + ] + }, + { + "SingularName": "Percent", + "PluralName": "Percent", + "FromUnitToBaseFunc": "x/1e2", + "FromBaseToUnitFunc": "x*1e2", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "%", "% (w/w)" ] + } + ] + }, + { + "SingularName": "PartPerThousand", + "PluralName": "PartsPerThousand", + "FromUnitToBaseFunc": "x/1e3", + "FromBaseToUnitFunc": "x*1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "‰" ] + } + ] + }, + { + "SingularName": "PartPerMillion", + "PluralName": "PartsPerMillion", + "FromUnitToBaseFunc": "x/1e6", + "FromBaseToUnitFunc": "x*1e6", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppm" ] + } + ] + }, + { + "SingularName": "PartPerBillion", + "PluralName": "PartsPerBillion", + "FromUnitToBaseFunc": "x/1e9", + "FromBaseToUnitFunc": "x*1e9", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppb" ] + } + ] + }, + { + "SingularName": "PartPerTrillion", + "PluralName": "PartsPerTrillion", + "FromUnitToBaseFunc": "x/1e12", + "FromBaseToUnitFunc": "x*1e12", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppt" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Common/UnitDefinitions/Molarity.json b/Common/UnitDefinitions/Molarity.json index f70918e9c1..c4584a1ef7 100644 --- a/Common/UnitDefinitions/Molarity.json +++ b/Common/UnitDefinitions/Molarity.json @@ -30,7 +30,20 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "mol/L" ] + "Abbreviations": [ "mol/L"] + } + ] + }, + { + "SingularName": "Molar", + "PluralName": "Molar", + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli"], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "M"] } ] } diff --git a/Common/UnitDefinitions/VolumeConcentration.json b/Common/UnitDefinitions/VolumeConcentration.json new file mode 100644 index 0000000000..6983544d4b --- /dev/null +++ b/Common/UnitDefinitions/VolumeConcentration.json @@ -0,0 +1,106 @@ +{ + "Name": "VolumeConcentration", + "BaseUnit": "DecimalFraction", + "XmlDoc": "The volume concentration (not to be confused with volume fraction) is defined as the volume of a constituent divided by the total volume of the mixture.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Concentration#Volume_concentration", + "Units": [ + { + "SingularName": "DecimalFraction", + "PluralName": "DecimalFractions", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "" ] + } + ] + }, + { + "SingularName": "LitersPerLiter", + "PluralName": "LitersPerLiter", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "l/l" ] + } + ] + }, + { + "SingularName": "LitersPerMililiter", + "PluralName": "LitersPerMililiter", + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "l/ml" ] + } + ] + }, + { + "SingularName": "Percent", + "PluralName": "Percent", + "FromUnitToBaseFunc": "x/1e2", + "FromBaseToUnitFunc": "x*1e2", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "%", "% (v/v)" ] + } + ] + }, + { + "SingularName": "PartPerThousand", + "PluralName": "PartsPerThousand", + "FromUnitToBaseFunc": "x/1e3", + "FromBaseToUnitFunc": "x*1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "‰" ] + } + ] + }, + { + "SingularName": "PartPerMillion", + "PluralName": "PartsPerMillion", + "FromUnitToBaseFunc": "x/1e6", + "FromBaseToUnitFunc": "x*1e6", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppm" ] + } + ] + }, + { + "SingularName": "PartPerBillion", + "PluralName": "PartsPerBillion", + "FromUnitToBaseFunc": "x/1e9", + "FromBaseToUnitFunc": "x*1e9", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppb" ] + } + ] + }, + { + "SingularName": "PartPerTrillion", + "PluralName": "PartsPerTrillion", + "FromUnitToBaseFunc": "x/1e12", + "FromBaseToUnitFunc": "x*1e12", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ppt" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs index da4b7acf9f..f11d0f9a9a 100644 --- a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs +++ b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs @@ -42,6 +42,17 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase protected override double NanopoundMolesInOneMole => 0.002204622621848776 * 1e9; protected override double PoundMolesInOneMole => 0.002204622621848776; protected override double MegamolesInOneMole => 1e-6; + + private static double MolarMassOfOxygen = 15.999; + private static double MolesInTenGramsOfOxygen = 0.6250390649415588; + + + private static double MolarMassHClInGramsPerMole = 36.46; + private static double MassOfSubstanceInGrams = 5; + private static double VolumeOfSolutionInLiters = 1.2; + + private static double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M + [Fact] public void NumberOfParticlesInOneMoleEqualsAvogadroConstant() @@ -58,5 +69,46 @@ public void NumberOfParticlesInTwoMolesIsDoubleAvogadroConstant() var numberOfParticles = twoMoles.NumberOfParticles(); Assert.Equal(AmountOfSubstance.AvogadroConstant * 2, numberOfParticles); } + + [Fact] + public void TenMolesOfOxygenToMassEqualToExpected() + { + AmountOfSubstance tenMoles = AmountOfSubstance.FromMoles(10); + MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassOfOxygen); + AssertEx.EqualTolerance(10 * MolarMassOfOxygen, (tenMoles * molarMass).Grams, MolesTolerance); + } + + [Fact] + public void TenGramsOfOxygenToMolesEqualToExpected() + { + Mass tenGrams = Mass.FromGrams(10); + MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassOfOxygen); + AssertEx.EqualTolerance(MolesInTenGramsOfOxygen, (tenGrams / molarMass).Moles, MolesTolerance); + } + + [Fact] + public void HClSolutionVolumeIsEqualToExpected() + { + MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); + Mass substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); + AmountOfSubstance amountOfSubstance = substanceMass / molarMass; + Molarity molarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); + + Volume volumeSolution = amountOfSubstance / molarity; + AssertEx.EqualTolerance(VolumeOfSolutionInLiters, volumeSolution.Liters, MolesTolerance); + } + + [Fact] + public void HClSolutionMolarityIsEqualToExpected() + { + MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); + Mass substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); + AmountOfSubstance amountOfSubstance = substanceMass / molarMass; + Volume volumeSolution = Volume.FromLiters(VolumeOfSolutionInLiters); + + Molarity molarity = amountOfSubstance / volumeSolution; + AssertEx.EqualTolerance(ExpectedMolarityMolesPerLiter, molarity.MolesPerLiter, MolesTolerance); + } + } } diff --git a/UnitsNet.Tests/CustomCode/DensityTests.cs b/UnitsNet.Tests/CustomCode/DensityTests.cs index 9dabe74215..6d70e059c2 100644 --- a/UnitsNet.Tests/CustomCode/DensityTests.cs +++ b/UnitsNet.Tests/CustomCode/DensityTests.cs @@ -107,25 +107,7 @@ public static void DensityTimesKinematicViscosityEqualsDynamicViscosity() DynamicViscosity dynamicViscosity = Density.FromKilogramsPerCubicMeter(2) * KinematicViscosity.FromSquareMetersPerSecond(10); Assert.Equal(dynamicViscosity, DynamicViscosity.FromNewtonSecondsPerMeterSquared(20)); } - - [Fact] - public void ExpectMolarityConvertedToDensityCorrectly() - { - var molarity = Molarity.FromMolesPerLiter(1.02698355); - var mw = Mass.FromGrams(58.443); - var density = Density.FromMolarity(molarity, mw).KilogramsPerCubicMeter; - AssertEx.EqualTolerance(60.02, density, KilogramsPerCubicMeterTolerance); - } - - [Fact] - public void ExpectDensityConvertedToMolarityCorrectly() - { - var density = Density.FromKilogramsPerCubicMeter(60.02); - var mw = Mass.FromGrams(58.443); - var molarity = density.ToMolarity(mw).MolesPerCubicMeter; - AssertEx.EqualTolerance(1026.98355, molarity, KilogramsPerCubicMeterTolerance); - } - + [Fact] public void DensityTimesSpeedEqualsMassFlux() { diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs new file mode 100644 index 0000000000..3aacc9c8e4 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -0,0 +1,131 @@ +//------------------------------------------------------------------------------ +// +// This code was generated (once) by \generate-code.bat, but will not be +// regenerated when it already exists. The purpose of creating this file is to make +// it easier to remember to implement all the unit conversion test cases. +// +// Whenever a new unit is added to this quantity and \generate-code.bat is run, +// the base test class will get a new abstract property and cause a compile error +// in this derived class, reminding the developer to implement the test case +// for the new unit. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using UnitsNet.Units; +using Xunit; + +namespace UnitsNet.Tests.CustomCode +{ + public class MassConcentrationTests : MassConcentrationTestsBase + { + protected override double PicogramsPerLiterInOneKilogramPerCubicMeter => 1e12; + protected override double PicogramsPerDeciLiterInOneKilogramPerCubicMeter => 1e11; + protected override double NanogramsPerLiterInOneKilogramPerCubicMeter => 1e9; + protected override double PicogramsPerMilliliterInOneKilogramPerCubicMeter => 1e9; + protected override double MicrogramsPerCubicMeterInOneKilogramPerCubicMeter => 1e9; + protected override double NanogramsPerDeciLiterInOneKilogramPerCubicMeter => 1e8; + protected override double NanogramsPerMilliliterInOneKilogramPerCubicMeter => 1e6; + protected override double MicrogramsPerLiterInOneKilogramPerCubicMeter => 1e6; + protected override double MilligramsPerCubicMeterInOneKilogramPerCubicMeter => 1e6; + protected override double MicrogramsPerDeciLiterInOneKilogramPerCubicMeter => 1e5; + protected override double MicrogramsPerMilliliterInOneKilogramPerCubicMeter => 1e3; + protected override double GramsPerCubicMeterInOneKilogramPerCubicMeter => 1e3; + protected override double MilligramsPerLiterInOneKilogramPerCubicMeter => 1e3; + protected override double CentigramsPerLiterInOneKilogramPerCubicMeter => 1e2; + protected override double MilligramsPerDeciLiterInOneKilogramPerCubicMeter => 1e2; + protected override double MilligramsPerMilliliterInOneKilogramPerCubicMeter => 1; + protected override double GramsPerLiterInOneKilogramPerCubicMeter => 1; + protected override double KilogramsPerCubicMeterInOneKilogramPerCubicMeter => 1; + protected override double CentigramsPerDeciLiterInOneKilogramPerCubicMeter => 1e1; + protected override double DecigramsPerDeciLiterInOneKilogramPerCubicMeter => 1; + protected override double DecigramsPerLiterInOneKilogramPerCubicMeter => 1e1; + protected override double CentigramsPerMilliliterInOneKilogramPerCubicMeter => 1e-1; + protected override double GramsPerDeciLiterInOneKilogramPerCubicMeter => 1e-1; + protected override double DecigramsPerMilliliterInOneKilogramPerCubicMeter => 1e-2; + protected override double KilogramsPerLiterInOneKilogramPerCubicMeter => 1e-3; + protected override double GramsPerMilliliterInOneKilogramPerCubicMeter => 1e-3; + protected override double GramsPerCubicCentimeterInOneKilogramPerCubicMeter => 1e-3; + protected override double TonnesPerCubicMeterInOneKilogramPerCubicMeter => 1e-3; + protected override double GramsPerCubicMillimeterInOneKilogramPerCubicMeter => 1e-6; + protected override double KilogramsPerCubicCentimeterInOneKilogramPerCubicMeter => 1e-6; + protected override double KilogramsPerCubicMillimeterInOneKilogramPerCubicMeter => 1e-9; + protected override double TonnesPerCubicCentimeterInOneKilogramPerCubicMeter => 1e-9; + protected override double TonnesPerCubicMillimeterInOneKilogramPerCubicMeter => 1e-12; + + protected override double PoundsPerImperialGallonInOneKilogramPerCubicMeter => 1.002241e-2; + protected override double KilopoundsPerCubicFootInOneKilogramPerCubicMeter => 6.242796e-5; + protected override double KilopoundsPerCubicInchInOneKilogramPerCubicMeter => 3.6127292e-8; + protected override double PoundsPerCubicFootInOneKilogramPerCubicMeter => 6.242796e-2; + protected override double PoundsPerCubicInchInOneKilogramPerCubicMeter => 3.61272923e-5; + protected override double PoundsPerUSGallonInOneKilogramPerCubicMeter => 8.3454045e-3; + protected override double SlugsPerCubicFootInOneKilogramPerCubicMeter => 0.00194032; + +// private static double MolarMassOfEthanolInGramsPerMole = 46.06844; + private static double DensityOfEthanolInKgPerCubicMeter = 789; + private static double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; + + [Fact] + public static void MassConcentrationTimesVolumeEqualsMass() + { + Mass mass = MassConcentration.FromKilogramsPerCubicMeter(2) * Volume.FromCubicMeters(3); + Assert.Equal(mass, Mass.FromKilograms(6)); + } + + [Fact] + public static void VolumeTimesMassConcentrationEqualsMass() + { + Mass mass = Volume.FromCubicMeters(3) * MassConcentration.FromKilogramsPerCubicMeter(2); + Assert.Equal(mass, Mass.FromKilograms(6)); + } + + [Fact] + public void ExpectMolarityConvertedToMassConcentrationCorrectly() + { + var molarity = Molarity.FromMolesPerLiter(1.02698355); + var molarMass = MolarMass.FromGramsPerMole(58.443); + + MassConcentration concentration = molarity.ToMassConcentration(molarMass); // molarity * molarMass + AssertEx.EqualTolerance(60.02, concentration.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); + } + + [Fact] + public void ExpectMassConcentrationConvertedToMolarityCorrectly() + { + var concentration = MassConcentration.FromKilogramsPerCubicMeter(60.02); + var molarMass = MolarMass.FromGramsPerMole(58.443); + + Molarity molarity = concentration.ToMolarity(molarMass); // molarity / molarMass + AssertEx.EqualTolerance(1026.98355, molarity.MolesPerCubicMeter, KilogramsPerCubicMeterTolerance); + } + + [Fact] + public void MassConcentrationFromVolumeConcentrationAndDensity() + { + var volumeConcentration = VolumeConcentration.FromPercent(50); + var density = Density.FromGramsPerCubicMeter(10); + + MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); // volumeConcentration * density + AssertEx.EqualTolerance(5, massConcentration.GramsPerCubicMeter, GramsPerCubicMeterTolerance); + } + + [Fact] + public void MassConcentrationFromVolumeConcentrationEthanol() + { + var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); + var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); + + MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); + AssertEx.EqualTolerance(23.03422, massConcentration.GramsPerLiter, GramsPerCubicMeterTolerance); + } + } +} diff --git a/UnitsNet.Tests/CustomCode/MassFractionTests.cs b/UnitsNet.Tests/CustomCode/MassFractionTests.cs new file mode 100644 index 0000000000..33fd53957c --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MassFractionTests.cs @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated (once) by \generate-code.bat, but will not be +// regenerated when it already exists. The purpose of creating this file is to make +// it easier to remember to implement all the unit conversion test cases. +// +// Whenever a new unit is added to this quantity and \generate-code.bat is run, +// the base test class will get a new abstract property and cause a compile error +// in this derived class, reminding the developer to implement the test case +// for the new unit. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using Xunit; + +namespace UnitsNet.Tests.CustomCode +{ + public class MassFractionTests : MassFractionTestsBase + { + protected override double KilogramsPerKiloGramInOneDecimalFraction => 1; + protected override double HectogramsPerKiloGramInOneDecimalFraction => 10; + protected override double DecagramsPerKiloGramInOneDecimalFraction => 1E2; + protected override double GramsPerKiloGramInOneDecimalFraction => 1E3; + protected override double DecigramsPerKiloGramInOneDecimalFraction => 1E4; + protected override double CentigramsPerKiloGramInOneDecimalFraction => 1E5; + protected override double MilligramsPerKiloGramInOneDecimalFraction => 1E6; + protected override double MicrogramsPerKiloGramInOneDecimalFraction => 1E9; + protected override double NanogramsPerKiloGramInOneDecimalFraction => 1E12; + + protected override double KilogramsPerGramInOneDecimalFraction => 1E-3; + protected override double HectogramsPerGramInOneDecimalFraction => 1E-2; + protected override double DecagramsPerGramInOneDecimalFraction => 1E-1; + protected override double GramsPerGramInOneDecimalFraction => 1; + protected override double DecigramsPerGramInOneDecimalFraction => 10; + protected override double CentigramsPerGramInOneDecimalFraction => 1E2; + protected override double MilligramsPerGramInOneDecimalFraction => 1E3; + protected override double MicrogramsPerGramInOneDecimalFraction => 1E6; + protected override double NanogramsPerGramInOneDecimalFraction => 1E9; + + + protected override double DecimalFractionsInOneDecimalFraction => 1; + + protected override double PercentInOneDecimalFraction => 100; + + protected override double PartsPerBillionInOneDecimalFraction => 1e9; + + protected override double PartsPerMillionInOneDecimalFraction => 1e6; + + protected override double PartsPerThousandInOneDecimalFraction => 1e3; + + protected override double PartsPerTrillionInOneDecimalFraction => 1e12; + + [Fact] + public void MassFractionFromMassesConsturctedCorrectly() + { + var one_kg = Mass.FromKilograms(1); + var two_kg = Mass.FromKilograms(2); + + var massFraction = MassFraction.FromMasses(one_kg, two_kg); + AssertEx.EqualTolerance(50, massFraction.Percent, PercentTolerance); + } + + [Fact] + public void TotalMassFromMassFraction() + { + var componentMass = Mass.FromKilograms(1); + var massFraction = MassFraction.FromPercent(50); + + var totalMass = massFraction.GetTotalMass(componentMass); + AssertEx.EqualTolerance(2, totalMass.Kilograms, KilogramsPerKiloGramTolerance); + } + [Fact] + public void ComponentMassFromMassFraction() + { + var totalMass = Mass.FromKilograms(2); + var massFraction = MassFraction.FromPercent(50); + + var componentMass = massFraction.GetComponentMass(totalMass); + AssertEx.EqualTolerance(1, componentMass.Kilograms, KilogramsPerKiloGramTolerance); + } + + } +} diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs index 696d990359..fdb1bb0d2b 100644 --- a/UnitsNet.Tests/CustomCode/MolarMassTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs @@ -22,6 +22,7 @@ using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -40,5 +41,17 @@ public class MolarMassTests : MolarMassTestsBase protected override double NanogramsPerMoleTolerance => 1e-3; protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12; protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; + + private static double MolarMassOfOxygen = 15.999; + private static double MolesInTenGramsOfOxygen = 0.6250390649415588; + + [Fact] + public void TenGramsOfOxygenContainExpectedNumberOfMoles() + { + Mass tenGrams = Mass.FromGrams(10); + MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassOfOxygen); + AssertEx.EqualTolerance(MolesInTenGramsOfOxygen, (tenGrams/ molarMass).Moles, GramsPerMoleTolerance); + } + } } diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 0b65235b16..599c686e2e 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -30,29 +30,104 @@ public class MolarityTests : MolarityTestsBase { protected override double CentimolesPerLiterInOneMolesPerCubicMeter => 1e-1; protected override double DecimolesPerLiterInOneMolesPerCubicMeter => 1e-2; - protected override double MicromolesPerLiterInOneMolesPerCubicMeter => 1e3; - protected override double MillimolesPerLiterInOneMolesPerCubicMeter => 1; protected override double MolesPerLiterInOneMolesPerCubicMeter => 1e-3; + protected override double MillimolesPerLiterInOneMolesPerCubicMeter => 1; + protected override double MolesPerCubicMeterInOneMolesPerCubicMeter => 1; + protected override double MicromolesPerLiterInOneMolesPerCubicMeter => 1e3; protected override double NanomolesPerLiterInOneMolesPerCubicMeter => 1e6; protected override double PicomolesPerLiterInOneMolesPerCubicMeter => 1e9; - protected override double MolesPerCubicMeterInOneMolesPerCubicMeter => 1; + + protected override double MolarInOneMolesPerCubicMeter => 1E-3; + protected override double MillimolarInOneMolesPerCubicMeter => 1; + protected override double MicromolarInOneMolesPerCubicMeter => 1E3; + protected override double NanomolarInOneMolesPerCubicMeter => 1E6; + protected override double PicomolarInOneMolesPerCubicMeter => 1E9; + + private static double MolarMassHClInGramsPerMole = 36.46; + private static double MassOfSubstanceInGrams = 5; + private static double VolumeOfSolutionInLiters = 1.2; + + private static double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M + private static double ExpectedConcentrationInKgPerCubicMeter = 4.16667; + + private static double MolarMassOfEthanolInGramsPerMole = 46.06844; + private static double DensityOfEthanolInKgPerCubicMeter = 789; + private static double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; [Fact] - public void ExpectDensityConvertedToMolarityCorrectly() + public void ExpectMassConcentrationConvertedToMolarityCorrectly() { - var density = Density.FromKilogramsPerCubicMeter(60.02); - var mw = Mass.FromGrams(58.443); - var molarity = (density / mw).MolesPerCubicMeter; - AssertEx.EqualTolerance(1026.98355, molarity, MolesPerCubicMeterTolerance); + var massConcentration = MassConcentration.FromKilogramsPerCubicMeter(60.02); // used to be Density + var molarMass = MolarMass.FromGramsPerMole(58.443); // used to be Mass + + Molarity molarity = massConcentration / molarMass; + AssertEx.EqualTolerance(1026.98355, molarity.MolesPerCubicMeter, MolesPerCubicMeterTolerance); } [Fact] - public void ExpectMolarityConvertedToDensityCorrectly() + public void ExpectMolarityConvertedToMassConcentrationCorrectly() { var molarity = Molarity.FromMolesPerLiter(1.02698355); - var mw = Mass.FromGrams(58.443); - var density = molarity.ToDensity(mw).KilogramsPerCubicMeter; - AssertEx.EqualTolerance(60.02, density, MolesPerCubicMeterTolerance); + var molarMass = MolarMass.FromGramsPerMole(58.443); + + MassConcentration concentration = molarity.ToMassConcentration(molarMass); // molarity * molarMass + AssertEx.EqualTolerance(60.02, concentration.KilogramsPerCubicMeter, MolesPerCubicMeterTolerance); + } + + [Fact] + public void HClSolutionMolarityIsEqualToExpected() + { + // same test is performed in AmountOfSubstanceTests + var molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); + var substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); + var volumeSolution = Volume.FromLiters(VolumeOfSolutionInLiters); + AmountOfSubstance amountOfSubstance = substanceMass / molarMass; + + Molarity molarity = amountOfSubstance / volumeSolution; + AssertEx.EqualTolerance(ExpectedMolarityMolesPerLiter, molarity.MolesPerLiter, MolesPerLiterTolerance); + } + + [Fact] + public void HClSolutionConcentrationIsEqualToExpected() + { + var molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); + var molarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); + + MassConcentration concentration = molarity * molarMass; + AssertEx.EqualTolerance(ExpectedConcentrationInKgPerCubicMeter, concentration.KilogramsPerCubicMeter, MolesPerLiterTolerance); + } + + [Fact] + public void TenPercentHClSolutionMolarityIsEqualToExpected() + { + var originalMolarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); + + Molarity tenPercentMolarity = originalMolarity * VolumeConcentration.FromPercent(10); + AssertEx.EqualTolerance(ExpectedMolarityMolesPerLiter / 10, tenPercentMolarity.MolesPerLiter, MolesPerLiterTolerance); + } + + [Fact] + public void MolarityFromVolumeConcentrationEthanol() + { + var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); + var molarMass = MolarMass.FromGramsPerMole(MolarMassOfEthanolInGramsPerMole); + var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); + + Molarity molarity = volumeConcentration.ToMolarity(density, molarMass); // volumeConcentration * density / molarMass + AssertEx.EqualTolerance(0.5, molarity.MolesPerLiter, MolesPerCubicMeterTolerance); + } + + [Fact] + public void OneMolarFromStringParsedCorrectly() + { + Assert.Equal(Molarity.Parse("1M"), Molarity.Parse("1 mol/L")); + } + + [Fact] + public void OneMilliMolarFromStringParsedCorrectly() + { + var one_mM = Molarity.Parse("1000 mM"); + Assert.Equal(1, one_mM.MolesPerLiter); } } diff --git a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs new file mode 100644 index 0000000000..81ef12e658 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------------ +// +// This code was generated (once) by \generate-code.bat, but will not be +// regenerated when it already exists. The purpose of creating this file is to make +// it easier to remember to implement all the unit conversion test cases. +// +// Whenever a new unit is added to this quantity and \generate-code.bat is run, +// the base test class will get a new abstract property and cause a compile error +// in this derived class, reminding the developer to implement the test case +// for the new unit. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using Xunit; + +namespace UnitsNet.Tests.CustomCode +{ + public class VolumeConcentrationTests : VolumeConcentrationTestsBase + { + protected override double LitersPerMililiterInOneDecimalFraction => 1E-3; + protected override double DecilitersPerMililiterInOneDecimalFraction => 1E-2; + protected override double CentilitersPerMililiterInOneDecimalFraction => 1E-1; + protected override double MillilitersPerMililiterInOneDecimalFraction => 1; + protected override double MicrolitersPerMililiterInOneDecimalFraction => 1E3; + protected override double NanolitersPerMililiterInOneDecimalFraction => 1E6; + protected override double PicolitersPerMililiterInOneDecimalFraction => 1E9; + + protected override double LitersPerLiterInOneDecimalFraction => 1; + protected override double DecilitersPerLiterInOneDecimalFraction => 10; + protected override double CentilitersPerLiterInOneDecimalFraction => 1E2; + protected override double MillilitersPerLiterInOneDecimalFraction => 1E3; + protected override double MicrolitersPerLiterInOneDecimalFraction => 1E6; + protected override double NanolitersPerLiterInOneDecimalFraction => 1E9; + protected override double PicolitersPerLiterInOneDecimalFraction => 1E12; + + protected override double DecimalFractionsInOneDecimalFraction => 1; + + protected override double PercentInOneDecimalFraction => 100; + + protected override double PartsPerBillionInOneDecimalFraction => 1e9; + + protected override double PartsPerMillionInOneDecimalFraction => 1e6; + + protected override double PartsPerThousandInOneDecimalFraction => 1e3; + + protected override double PartsPerTrillionInOneDecimalFraction => 1e12; + + private static double MolarMassOfEthanolInGramsPerMole = 46.06844; + private static double DensityOfEthanolInKgPerCubicMeter = 789; + private static double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; + + + [Fact] + public void MassConcentrationFromVolumeConcentrationAndDensity() + { + var density = Density.FromGramsPerCubicMeter(10); + var volumeConcentration = VolumeConcentration.FromPercent(50); + + MassConcentration massConcentration = volumeConcentration * density; + AssertEx.EqualTolerance(5, massConcentration.GramsPerCubicMeter, DecimalFractionsTolerance); + } + + [Fact] + public void VolumeConcentrationFromMassConcentrationAndDensity() + { + var density = Density.FromGramsPerCubicMeter(10); + var massConcentration = MassConcentration.FromGramsPerCubicMeter(5); + + VolumeConcentration volumeConcentration = massConcentration / density; + AssertEx.EqualTolerance(0.5, volumeConcentration.DecimalFractions, DecimalFractionsTolerance); + } + + [Fact] + public void VolumeConcentrationFromMolarityOfEthanol() + { + var molarity = Molarity.FromMolesPerLiter(0.5); + var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); + var molarMass = MolarMass.FromGramsPerMole(MolarMassOfEthanolInGramsPerMole); + + VolumeConcentration volumeConcentration = molarity.ToVolumeConcentration(density, molarMass); + AssertEx.EqualTolerance(VolumeConcentration_0_5M_Ethanol, volumeConcentration.MillilitersPerLiter, MillilitersPerLiterTolerance); + } + + } +} diff --git a/UnitsNet.Tests/QuantityIFormattableTests.cs b/UnitsNet.Tests/QuantityIFormattableTests.cs index 3aaaf4ccbf..059b5b22e2 100644 --- a/UnitsNet.Tests/QuantityIFormattableTests.cs +++ b/UnitsNet.Tests/QuantityIFormattableTests.cs @@ -43,7 +43,7 @@ public void AFormatWithInvalidIndexThrowsFormatException() [Fact] public void VFormatEqualsValueToString() { - Assert.Equal(length.Value.ToString(), length.ToString("v")); + Assert.Equal(length.Value.ToString(CultureInfo.CurrentUICulture), length.ToString("v")); } [Fact] diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs new file mode 100644 index 0000000000..04aa891b8b --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs @@ -0,0 +1,1246 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// In chemistry, the mass concentration ρi (or γi) is defined as the mass of a constituent mi divided by the volume of the mixture V + /// + /// + /// https://en.wikipedia.org/wiki/Mass_concentration_(chemistry) + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class MassConcentration : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly MassConcentrationUnit? _unit; + + static MassConcentration() + { + BaseDimensions = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0); + Info = new QuantityInfo(QuantityType.MassConcentration, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit KilogramPerCubicMeter. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public MassConcentration() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private MassConcentration(double numericValue, MassConcentrationUnit unit) + { + if(unit == MassConcentrationUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of MassConcentration, which is KilogramPerCubicMeter. All conversions go via this value. + /// + public static MassConcentrationUnit BaseUnit { get; } = MassConcentrationUnit.KilogramPerCubicMeter; + + /// + /// Represents the largest possible value of MassConcentration + /// + public static MassConcentration MaxValue { get; } = new MassConcentration(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of MassConcentration + /// + public static MassConcentration MinValue { get; } = new MassConcentration(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.MassConcentration; + + /// + /// All units of measurement for the MassConcentration quantity. + /// + public static MassConcentrationUnit[] Units { get; } = Enum.GetValues(typeof(MassConcentrationUnit)).Cast().Except(new MassConcentrationUnit[]{ MassConcentrationUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerCubicMeter. + /// + public static MassConcentration Zero { get; } = new MassConcentration(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public MassConcentrationUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => MassConcentration.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => MassConcentration.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get MassConcentration in CentigramsPerDeciLiter. + /// + public double CentigramsPerDeciLiter => As(MassConcentrationUnit.CentigramPerDeciliter); + + /// + /// Get MassConcentration in CentigramsPerLiter. + /// + public double CentigramsPerLiter => As(MassConcentrationUnit.CentigramPerLiter); + + /// + /// Get MassConcentration in CentigramsPerMilliliter. + /// + public double CentigramsPerMilliliter => As(MassConcentrationUnit.CentigramPerMilliliter); + + /// + /// Get MassConcentration in DecigramsPerDeciLiter. + /// + public double DecigramsPerDeciLiter => As(MassConcentrationUnit.DecigramPerDeciliter); + + /// + /// Get MassConcentration in DecigramsPerLiter. + /// + public double DecigramsPerLiter => As(MassConcentrationUnit.DecigramPerLiter); + + /// + /// Get MassConcentration in DecigramsPerMilliliter. + /// + public double DecigramsPerMilliliter => As(MassConcentrationUnit.DecigramPerMilliliter); + + /// + /// Get MassConcentration in GramsPerCubicCentimeter. + /// + public double GramsPerCubicCentimeter => As(MassConcentrationUnit.GramPerCubicCentimeter); + + /// + /// Get MassConcentration in GramsPerCubicMeter. + /// + public double GramsPerCubicMeter => As(MassConcentrationUnit.GramPerCubicMeter); + + /// + /// Get MassConcentration in GramsPerCubicMillimeter. + /// + public double GramsPerCubicMillimeter => As(MassConcentrationUnit.GramPerCubicMillimeter); + + /// + /// Get MassConcentration in GramsPerDeciLiter. + /// + public double GramsPerDeciLiter => As(MassConcentrationUnit.GramPerDeciliter); + + /// + /// Get MassConcentration in GramsPerLiter. + /// + public double GramsPerLiter => As(MassConcentrationUnit.GramPerLiter); + + /// + /// Get MassConcentration in GramsPerMilliliter. + /// + public double GramsPerMilliliter => As(MassConcentrationUnit.GramPerMilliliter); + + /// + /// Get MassConcentration in KilogramsPerCubicCentimeter. + /// + public double KilogramsPerCubicCentimeter => As(MassConcentrationUnit.KilogramPerCubicCentimeter); + + /// + /// Get MassConcentration in KilogramsPerCubicMeter. + /// + public double KilogramsPerCubicMeter => As(MassConcentrationUnit.KilogramPerCubicMeter); + + /// + /// Get MassConcentration in KilogramsPerCubicMillimeter. + /// + public double KilogramsPerCubicMillimeter => As(MassConcentrationUnit.KilogramPerCubicMillimeter); + + /// + /// Get MassConcentration in KilogramsPerLiter. + /// + public double KilogramsPerLiter => As(MassConcentrationUnit.KilogramPerLiter); + + /// + /// Get MassConcentration in KilopoundsPerCubicFoot. + /// + public double KilopoundsPerCubicFoot => As(MassConcentrationUnit.KilopoundPerCubicFoot); + + /// + /// Get MassConcentration in KilopoundsPerCubicInch. + /// + public double KilopoundsPerCubicInch => As(MassConcentrationUnit.KilopoundPerCubicInch); + + /// + /// Get MassConcentration in MicrogramsPerCubicMeter. + /// + public double MicrogramsPerCubicMeter => As(MassConcentrationUnit.MicrogramPerCubicMeter); + + /// + /// Get MassConcentration in MicrogramsPerDeciLiter. + /// + public double MicrogramsPerDeciLiter => As(MassConcentrationUnit.MicrogramPerDeciliter); + + /// + /// Get MassConcentration in MicrogramsPerLiter. + /// + public double MicrogramsPerLiter => As(MassConcentrationUnit.MicrogramPerLiter); + + /// + /// Get MassConcentration in MicrogramsPerMilliliter. + /// + public double MicrogramsPerMilliliter => As(MassConcentrationUnit.MicrogramPerMilliliter); + + /// + /// Get MassConcentration in MilligramsPerCubicMeter. + /// + public double MilligramsPerCubicMeter => As(MassConcentrationUnit.MilligramPerCubicMeter); + + /// + /// Get MassConcentration in MilligramsPerDeciLiter. + /// + public double MilligramsPerDeciLiter => As(MassConcentrationUnit.MilligramPerDeciliter); + + /// + /// Get MassConcentration in MilligramsPerLiter. + /// + public double MilligramsPerLiter => As(MassConcentrationUnit.MilligramPerLiter); + + /// + /// Get MassConcentration in MilligramsPerMilliliter. + /// + public double MilligramsPerMilliliter => As(MassConcentrationUnit.MilligramPerMilliliter); + + /// + /// Get MassConcentration in NanogramsPerDeciLiter. + /// + public double NanogramsPerDeciLiter => As(MassConcentrationUnit.NanogramPerDeciliter); + + /// + /// Get MassConcentration in NanogramsPerLiter. + /// + public double NanogramsPerLiter => As(MassConcentrationUnit.NanogramPerLiter); + + /// + /// Get MassConcentration in NanogramsPerMilliliter. + /// + public double NanogramsPerMilliliter => As(MassConcentrationUnit.NanogramPerMilliliter); + + /// + /// Get MassConcentration in PicogramsPerDeciLiter. + /// + public double PicogramsPerDeciLiter => As(MassConcentrationUnit.PicogramPerDeciliter); + + /// + /// Get MassConcentration in PicogramsPerLiter. + /// + public double PicogramsPerLiter => As(MassConcentrationUnit.PicogramPerLiter); + + /// + /// Get MassConcentration in PicogramsPerMilliliter. + /// + public double PicogramsPerMilliliter => As(MassConcentrationUnit.PicogramPerMilliliter); + + /// + /// Get MassConcentration in PoundsPerCubicFoot. + /// + public double PoundsPerCubicFoot => As(MassConcentrationUnit.PoundPerCubicFoot); + + /// + /// Get MassConcentration in PoundsPerCubicInch. + /// + public double PoundsPerCubicInch => As(MassConcentrationUnit.PoundPerCubicInch); + + /// + /// Get MassConcentration in PoundsPerImperialGallon. + /// + public double PoundsPerImperialGallon => As(MassConcentrationUnit.PoundPerImperialGallon); + + /// + /// Get MassConcentration in PoundsPerUSGallon. + /// + public double PoundsPerUSGallon => As(MassConcentrationUnit.PoundPerUSGallon); + + /// + /// Get MassConcentration in SlugsPerCubicFoot. + /// + public double SlugsPerCubicFoot => As(MassConcentrationUnit.SlugPerCubicFoot); + + /// + /// Get MassConcentration in TonnesPerCubicCentimeter. + /// + public double TonnesPerCubicCentimeter => As(MassConcentrationUnit.TonnePerCubicCentimeter); + + /// + /// Get MassConcentration in TonnesPerCubicMeter. + /// + public double TonnesPerCubicMeter => As(MassConcentrationUnit.TonnePerCubicMeter); + + /// + /// Get MassConcentration in TonnesPerCubicMillimeter. + /// + public double TonnesPerCubicMillimeter => As(MassConcentrationUnit.TonnePerCubicMillimeter); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(MassConcentrationUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(MassConcentrationUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get MassConcentration from CentigramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromCentigramsPerDeciLiter(double centigramsperdeciliter) + { + double value = (double) centigramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.CentigramPerDeciliter); + } + /// + /// Get MassConcentration from CentigramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromCentigramsPerLiter(double centigramsperliter) + { + double value = (double) centigramsperliter; + return new MassConcentration(value, MassConcentrationUnit.CentigramPerLiter); + } + /// + /// Get MassConcentration from CentigramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromCentigramsPerMilliliter(double centigramspermilliliter) + { + double value = (double) centigramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.CentigramPerMilliliter); + } + /// + /// Get MassConcentration from DecigramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromDecigramsPerDeciLiter(double decigramsperdeciliter) + { + double value = (double) decigramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.DecigramPerDeciliter); + } + /// + /// Get MassConcentration from DecigramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromDecigramsPerLiter(double decigramsperliter) + { + double value = (double) decigramsperliter; + return new MassConcentration(value, MassConcentrationUnit.DecigramPerLiter); + } + /// + /// Get MassConcentration from DecigramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromDecigramsPerMilliliter(double decigramspermilliliter) + { + double value = (double) decigramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.DecigramPerMilliliter); + } + /// + /// Get MassConcentration from GramsPerCubicCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromGramsPerCubicCentimeter(double gramspercubiccentimeter) + { + double value = (double) gramspercubiccentimeter; + return new MassConcentration(value, MassConcentrationUnit.GramPerCubicCentimeter); + } + /// + /// Get MassConcentration from GramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromGramsPerCubicMeter(double gramspercubicmeter) + { + double value = (double) gramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.GramPerCubicMeter); + } + /// + /// Get MassConcentration from GramsPerCubicMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromGramsPerCubicMillimeter(double gramspercubicmillimeter) + { + double value = (double) gramspercubicmillimeter; + return new MassConcentration(value, MassConcentrationUnit.GramPerCubicMillimeter); + } + /// + /// Get MassConcentration from GramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromGramsPerDeciLiter(double gramsperdeciliter) + { + double value = (double) gramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.GramPerDeciliter); + } + /// + /// Get MassConcentration from GramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromGramsPerLiter(double gramsperliter) + { + double value = (double) gramsperliter; + return new MassConcentration(value, MassConcentrationUnit.GramPerLiter); + } + /// + /// Get MassConcentration from GramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromGramsPerMilliliter(double gramspermilliliter) + { + double value = (double) gramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.GramPerMilliliter); + } + /// + /// Get MassConcentration from KilogramsPerCubicCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromKilogramsPerCubicCentimeter(double kilogramspercubiccentimeter) + { + double value = (double) kilogramspercubiccentimeter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerCubicCentimeter); + } + /// + /// Get MassConcentration from KilogramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromKilogramsPerCubicMeter(double kilogramspercubicmeter) + { + double value = (double) kilogramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerCubicMeter); + } + /// + /// Get MassConcentration from KilogramsPerCubicMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromKilogramsPerCubicMillimeter(double kilogramspercubicmillimeter) + { + double value = (double) kilogramspercubicmillimeter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerCubicMillimeter); + } + /// + /// Get MassConcentration from KilogramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromKilogramsPerLiter(double kilogramsperliter) + { + double value = (double) kilogramsperliter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerLiter); + } + /// + /// Get MassConcentration from KilopoundsPerCubicFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromKilopoundsPerCubicFoot(double kilopoundspercubicfoot) + { + double value = (double) kilopoundspercubicfoot; + return new MassConcentration(value, MassConcentrationUnit.KilopoundPerCubicFoot); + } + /// + /// Get MassConcentration from KilopoundsPerCubicInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromKilopoundsPerCubicInch(double kilopoundspercubicinch) + { + double value = (double) kilopoundspercubicinch; + return new MassConcentration(value, MassConcentrationUnit.KilopoundPerCubicInch); + } + /// + /// Get MassConcentration from MicrogramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMicrogramsPerCubicMeter(double microgramspercubicmeter) + { + double value = (double) microgramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerCubicMeter); + } + /// + /// Get MassConcentration from MicrogramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMicrogramsPerDeciLiter(double microgramsperdeciliter) + { + double value = (double) microgramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerDeciliter); + } + /// + /// Get MassConcentration from MicrogramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMicrogramsPerLiter(double microgramsperliter) + { + double value = (double) microgramsperliter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerLiter); + } + /// + /// Get MassConcentration from MicrogramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMicrogramsPerMilliliter(double microgramspermilliliter) + { + double value = (double) microgramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerMilliliter); + } + /// + /// Get MassConcentration from MilligramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMilligramsPerCubicMeter(double milligramspercubicmeter) + { + double value = (double) milligramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerCubicMeter); + } + /// + /// Get MassConcentration from MilligramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMilligramsPerDeciLiter(double milligramsperdeciliter) + { + double value = (double) milligramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerDeciliter); + } + /// + /// Get MassConcentration from MilligramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMilligramsPerLiter(double milligramsperliter) + { + double value = (double) milligramsperliter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerLiter); + } + /// + /// Get MassConcentration from MilligramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromMilligramsPerMilliliter(double milligramspermilliliter) + { + double value = (double) milligramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerMilliliter); + } + /// + /// Get MassConcentration from NanogramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromNanogramsPerDeciLiter(double nanogramsperdeciliter) + { + double value = (double) nanogramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.NanogramPerDeciliter); + } + /// + /// Get MassConcentration from NanogramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromNanogramsPerLiter(double nanogramsperliter) + { + double value = (double) nanogramsperliter; + return new MassConcentration(value, MassConcentrationUnit.NanogramPerLiter); + } + /// + /// Get MassConcentration from NanogramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromNanogramsPerMilliliter(double nanogramspermilliliter) + { + double value = (double) nanogramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.NanogramPerMilliliter); + } + /// + /// Get MassConcentration from PicogramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPicogramsPerDeciLiter(double picogramsperdeciliter) + { + double value = (double) picogramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.PicogramPerDeciliter); + } + /// + /// Get MassConcentration from PicogramsPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPicogramsPerLiter(double picogramsperliter) + { + double value = (double) picogramsperliter; + return new MassConcentration(value, MassConcentrationUnit.PicogramPerLiter); + } + /// + /// Get MassConcentration from PicogramsPerMilliliter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPicogramsPerMilliliter(double picogramspermilliliter) + { + double value = (double) picogramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.PicogramPerMilliliter); + } + /// + /// Get MassConcentration from PoundsPerCubicFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPoundsPerCubicFoot(double poundspercubicfoot) + { + double value = (double) poundspercubicfoot; + return new MassConcentration(value, MassConcentrationUnit.PoundPerCubicFoot); + } + /// + /// Get MassConcentration from PoundsPerCubicInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPoundsPerCubicInch(double poundspercubicinch) + { + double value = (double) poundspercubicinch; + return new MassConcentration(value, MassConcentrationUnit.PoundPerCubicInch); + } + /// + /// Get MassConcentration from PoundsPerImperialGallon. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPoundsPerImperialGallon(double poundsperimperialgallon) + { + double value = (double) poundsperimperialgallon; + return new MassConcentration(value, MassConcentrationUnit.PoundPerImperialGallon); + } + /// + /// Get MassConcentration from PoundsPerUSGallon. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromPoundsPerUSGallon(double poundsperusgallon) + { + double value = (double) poundsperusgallon; + return new MassConcentration(value, MassConcentrationUnit.PoundPerUSGallon); + } + /// + /// Get MassConcentration from SlugsPerCubicFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromSlugsPerCubicFoot(double slugspercubicfoot) + { + double value = (double) slugspercubicfoot; + return new MassConcentration(value, MassConcentrationUnit.SlugPerCubicFoot); + } + /// + /// Get MassConcentration from TonnesPerCubicCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromTonnesPerCubicCentimeter(double tonnespercubiccentimeter) + { + double value = (double) tonnespercubiccentimeter; + return new MassConcentration(value, MassConcentrationUnit.TonnePerCubicCentimeter); + } + /// + /// Get MassConcentration from TonnesPerCubicMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromTonnesPerCubicMeter(double tonnespercubicmeter) + { + double value = (double) tonnespercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.TonnePerCubicMeter); + } + /// + /// Get MassConcentration from TonnesPerCubicMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassConcentration FromTonnesPerCubicMillimeter(double tonnespercubicmillimeter) + { + double value = (double) tonnespercubicmillimeter; + return new MassConcentration(value, MassConcentrationUnit.TonnePerCubicMillimeter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassConcentration unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static MassConcentration From(double value, MassConcentrationUnit fromUnit) + { + return new MassConcentration((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static MassConcentration Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static MassConcentration Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out MassConcentration result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out MassConcentration result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassConcentrationUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static MassConcentrationUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out MassConcentrationUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out MassConcentrationUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is MassConcentration objMassConcentration)) throw new ArgumentException("Expected type MassConcentration.", nameof(obj)); + + return CompareTo(objMassConcentration); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(MassConcentration other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is MassConcentration objMassConcentration)) + return false; + + return Equals(objMassConcentration); + } + + public bool Equals(MassConcentration other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another MassConcentration within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(MassConcentration other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current MassConcentration. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((MassConcentrationUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(MassConcentrationUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this MassConcentration to another MassConcentration with the unit representation . + /// + /// A MassConcentration with the specified unit. + public MassConcentration ToUnit(MassConcentrationUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new MassConcentration(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double AsBaseUnit() + { + switch(Unit) + { + case MassConcentrationUnit.CentigramPerDeciliter: return (_value/1e-1) * 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (_value/1) * 1e-2d; + case MassConcentrationUnit.CentigramPerMilliliter: return (_value/1e-3) * 1e-2d; + case MassConcentrationUnit.DecigramPerDeciliter: return (_value/1e-1) * 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (_value/1) * 1e-1d; + case MassConcentrationUnit.DecigramPerMilliliter: return (_value/1e-3) * 1e-1d; + case MassConcentrationUnit.GramPerCubicCentimeter: return _value/1e-3; + case MassConcentrationUnit.GramPerCubicMeter: return _value/1e3; + case MassConcentrationUnit.GramPerCubicMillimeter: return _value/1e-6; + case MassConcentrationUnit.GramPerDeciliter: return _value/1e-1; + case MassConcentrationUnit.GramPerLiter: return _value/1; + case MassConcentrationUnit.GramPerMilliliter: return _value/1e-3; + case MassConcentrationUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d; + case MassConcentrationUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d; + case MassConcentrationUnit.KilogramPerCubicMillimeter: return (_value/1e-6) * 1e3d; + case MassConcentrationUnit.KilogramPerLiter: return _value*1e3; + case MassConcentrationUnit.KilopoundPerCubicFoot: return (_value/0.062427961) * 1e3d; + case MassConcentrationUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d; + case MassConcentrationUnit.MicrogramPerCubicMeter: return (_value/1e3) * 1e-6d; + case MassConcentrationUnit.MicrogramPerDeciliter: return (_value/1e-1) * 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (_value/1) * 1e-6d; + case MassConcentrationUnit.MicrogramPerMilliliter: return (_value/1e-3) * 1e-6d; + case MassConcentrationUnit.MilligramPerCubicMeter: return (_value/1e3) * 1e-3d; + case MassConcentrationUnit.MilligramPerDeciliter: return (_value/1e-1) * 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (_value/1) * 1e-3d; + case MassConcentrationUnit.MilligramPerMilliliter: return (_value/1e-3) * 1e-3d; + case MassConcentrationUnit.NanogramPerDeciliter: return (_value/1e-1) * 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (_value/1) * 1e-9d; + case MassConcentrationUnit.NanogramPerMilliliter: return (_value/1e-3) * 1e-9d; + case MassConcentrationUnit.PicogramPerDeciliter: return (_value/1e-1) * 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (_value/1) * 1e-12d; + case MassConcentrationUnit.PicogramPerMilliliter: return (_value/1e-3) * 1e-12d; + case MassConcentrationUnit.PoundPerCubicFoot: return _value/0.062427961; + case MassConcentrationUnit.PoundPerCubicInch: return _value/3.6127298147753e-5; + case MassConcentrationUnit.PoundPerImperialGallon: return _value*9.9776398e1; + case MassConcentrationUnit.PoundPerUSGallon: return _value*1.19826427e2; + case MassConcentrationUnit.SlugPerCubicFoot: return _value*515.378818; + case MassConcentrationUnit.TonnePerCubicCentimeter: return _value/1e-9; + case MassConcentrationUnit.TonnePerCubicMeter: return _value/0.001; + case MassConcentrationUnit.TonnePerCubicMillimeter: return _value/1e-12; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(MassConcentrationUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case MassConcentrationUnit.CentigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (baseUnitValue*1) / 1e-2d; + case MassConcentrationUnit.CentigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-2d; + case MassConcentrationUnit.DecigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (baseUnitValue*1) / 1e-1d; + case MassConcentrationUnit.DecigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-1d; + case MassConcentrationUnit.GramPerCubicCentimeter: return baseUnitValue*1e-3; + case MassConcentrationUnit.GramPerCubicMeter: return baseUnitValue*1e3; + case MassConcentrationUnit.GramPerCubicMillimeter: return baseUnitValue*1e-6; + case MassConcentrationUnit.GramPerDeciliter: return baseUnitValue*1e-1; + case MassConcentrationUnit.GramPerLiter: return baseUnitValue*1; + case MassConcentrationUnit.GramPerMilliliter: return baseUnitValue*1e-3; + case MassConcentrationUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d; + case MassConcentrationUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d; + case MassConcentrationUnit.KilogramPerCubicMillimeter: return (baseUnitValue*1e-6) / 1e3d; + case MassConcentrationUnit.KilogramPerLiter: return baseUnitValue/1e3; + case MassConcentrationUnit.KilopoundPerCubicFoot: return (baseUnitValue*0.062427961) / 1e3d; + case MassConcentrationUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d; + case MassConcentrationUnit.MicrogramPerCubicMeter: return (baseUnitValue*1e3) / 1e-6d; + case MassConcentrationUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (baseUnitValue*1) / 1e-6d; + case MassConcentrationUnit.MicrogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-6d; + case MassConcentrationUnit.MilligramPerCubicMeter: return (baseUnitValue*1e3) / 1e-3d; + case MassConcentrationUnit.MilligramPerDeciliter: return (baseUnitValue*1e-1) / 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (baseUnitValue*1) / 1e-3d; + case MassConcentrationUnit.MilligramPerMilliliter: return (baseUnitValue*1e-3) / 1e-3d; + case MassConcentrationUnit.NanogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (baseUnitValue*1) / 1e-9d; + case MassConcentrationUnit.NanogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-9d; + case MassConcentrationUnit.PicogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (baseUnitValue*1) / 1e-12d; + case MassConcentrationUnit.PicogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-12d; + case MassConcentrationUnit.PoundPerCubicFoot: return baseUnitValue*0.062427961; + case MassConcentrationUnit.PoundPerCubicInch: return baseUnitValue*3.6127298147753e-5; + case MassConcentrationUnit.PoundPerImperialGallon: return baseUnitValue/9.9776398e1; + case MassConcentrationUnit.PoundPerUSGallon: return baseUnitValue/1.19826427e2; + case MassConcentrationUnit.SlugPerCubicFoot: return baseUnitValue*0.00194032033; + case MassConcentrationUnit.TonnePerCubicCentimeter: return baseUnitValue*1e-9; + case MassConcentrationUnit.TonnePerCubicMeter: return baseUnitValue*0.001; + case MassConcentrationUnit.TonnePerCubicMillimeter: return baseUnitValue*1e-12; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs new file mode 100644 index 0000000000..ef6677290f --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs @@ -0,0 +1,974 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// The mass fraction is defined as the mass of a constituent divided by the total mass of the mixture. + /// + /// + /// https://en.wikipedia.org/wiki/Mass_fraction_(chemistry) + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class MassFraction : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly MassFractionUnit? _unit; + + static MassFraction() + { + BaseDimensions = BaseDimensions.Dimensionless; + Info = new QuantityInfo(QuantityType.MassFraction, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit DecimalFraction. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public MassFraction() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private MassFraction(double numericValue, MassFractionUnit unit) + { + if(unit == MassFractionUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of MassFraction, which is DecimalFraction. All conversions go via this value. + /// + public static MassFractionUnit BaseUnit { get; } = MassFractionUnit.DecimalFraction; + + /// + /// Represents the largest possible value of MassFraction + /// + public static MassFraction MaxValue { get; } = new MassFraction(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of MassFraction + /// + public static MassFraction MinValue { get; } = new MassFraction(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.MassFraction; + + /// + /// All units of measurement for the MassFraction quantity. + /// + public static MassFractionUnit[] Units { get; } = Enum.GetValues(typeof(MassFractionUnit)).Cast().Except(new MassFractionUnit[]{ MassFractionUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. + /// + public static MassFraction Zero { get; } = new MassFraction(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public MassFractionUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => MassFraction.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => MassFraction.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get MassFraction in CentigramsPerGram. + /// + public double CentigramsPerGram => As(MassFractionUnit.CentigramPerGram); + + /// + /// Get MassFraction in CentigramsPerKiloGram. + /// + public double CentigramsPerKiloGram => As(MassFractionUnit.CentigramPerKiloGram); + + /// + /// Get MassFraction in DecagramsPerGram. + /// + public double DecagramsPerGram => As(MassFractionUnit.DecagramPerGram); + + /// + /// Get MassFraction in DecagramsPerKiloGram. + /// + public double DecagramsPerKiloGram => As(MassFractionUnit.DecagramPerKiloGram); + + /// + /// Get MassFraction in DecigramsPerGram. + /// + public double DecigramsPerGram => As(MassFractionUnit.DecigramPerGram); + + /// + /// Get MassFraction in DecigramsPerKiloGram. + /// + public double DecigramsPerKiloGram => As(MassFractionUnit.DecigramPerKiloGram); + + /// + /// Get MassFraction in DecimalFractions. + /// + public double DecimalFractions => As(MassFractionUnit.DecimalFraction); + + /// + /// Get MassFraction in GramsPerGram. + /// + public double GramsPerGram => As(MassFractionUnit.GramPerGram); + + /// + /// Get MassFraction in GramsPerKiloGram. + /// + public double GramsPerKiloGram => As(MassFractionUnit.GramPerKiloGram); + + /// + /// Get MassFraction in HectogramsPerGram. + /// + public double HectogramsPerGram => As(MassFractionUnit.HectogramPerGram); + + /// + /// Get MassFraction in HectogramsPerKiloGram. + /// + public double HectogramsPerKiloGram => As(MassFractionUnit.HectogramPerKiloGram); + + /// + /// Get MassFraction in KilogramsPerGram. + /// + public double KilogramsPerGram => As(MassFractionUnit.KilogramPerGram); + + /// + /// Get MassFraction in KilogramsPerKiloGram. + /// + public double KilogramsPerKiloGram => As(MassFractionUnit.KilogramPerKiloGram); + + /// + /// Get MassFraction in MicrogramsPerGram. + /// + public double MicrogramsPerGram => As(MassFractionUnit.MicrogramPerGram); + + /// + /// Get MassFraction in MicrogramsPerKiloGram. + /// + public double MicrogramsPerKiloGram => As(MassFractionUnit.MicrogramPerKiloGram); + + /// + /// Get MassFraction in MilligramsPerGram. + /// + public double MilligramsPerGram => As(MassFractionUnit.MilligramPerGram); + + /// + /// Get MassFraction in MilligramsPerKiloGram. + /// + public double MilligramsPerKiloGram => As(MassFractionUnit.MilligramPerKiloGram); + + /// + /// Get MassFraction in NanogramsPerGram. + /// + public double NanogramsPerGram => As(MassFractionUnit.NanogramPerGram); + + /// + /// Get MassFraction in NanogramsPerKiloGram. + /// + public double NanogramsPerKiloGram => As(MassFractionUnit.NanogramPerKiloGram); + + /// + /// Get MassFraction in PartsPerBillion. + /// + public double PartsPerBillion => As(MassFractionUnit.PartPerBillion); + + /// + /// Get MassFraction in PartsPerMillion. + /// + public double PartsPerMillion => As(MassFractionUnit.PartPerMillion); + + /// + /// Get MassFraction in PartsPerThousand. + /// + public double PartsPerThousand => As(MassFractionUnit.PartPerThousand); + + /// + /// Get MassFraction in PartsPerTrillion. + /// + public double PartsPerTrillion => As(MassFractionUnit.PartPerTrillion); + + /// + /// Get MassFraction in Percent. + /// + public double Percent => As(MassFractionUnit.Percent); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(MassFractionUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(MassFractionUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get MassFraction from CentigramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromCentigramsPerGram(double centigramspergram) + { + double value = (double) centigramspergram; + return new MassFraction(value, MassFractionUnit.CentigramPerGram); + } + /// + /// Get MassFraction from CentigramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromCentigramsPerKiloGram(double centigramsperkilogram) + { + double value = (double) centigramsperkilogram; + return new MassFraction(value, MassFractionUnit.CentigramPerKiloGram); + } + /// + /// Get MassFraction from DecagramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromDecagramsPerGram(double decagramspergram) + { + double value = (double) decagramspergram; + return new MassFraction(value, MassFractionUnit.DecagramPerGram); + } + /// + /// Get MassFraction from DecagramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromDecagramsPerKiloGram(double decagramsperkilogram) + { + double value = (double) decagramsperkilogram; + return new MassFraction(value, MassFractionUnit.DecagramPerKiloGram); + } + /// + /// Get MassFraction from DecigramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromDecigramsPerGram(double decigramspergram) + { + double value = (double) decigramspergram; + return new MassFraction(value, MassFractionUnit.DecigramPerGram); + } + /// + /// Get MassFraction from DecigramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromDecigramsPerKiloGram(double decigramsperkilogram) + { + double value = (double) decigramsperkilogram; + return new MassFraction(value, MassFractionUnit.DecigramPerKiloGram); + } + /// + /// Get MassFraction from DecimalFractions. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromDecimalFractions(double decimalfractions) + { + double value = (double) decimalfractions; + return new MassFraction(value, MassFractionUnit.DecimalFraction); + } + /// + /// Get MassFraction from GramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromGramsPerGram(double gramspergram) + { + double value = (double) gramspergram; + return new MassFraction(value, MassFractionUnit.GramPerGram); + } + /// + /// Get MassFraction from GramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromGramsPerKiloGram(double gramsperkilogram) + { + double value = (double) gramsperkilogram; + return new MassFraction(value, MassFractionUnit.GramPerKiloGram); + } + /// + /// Get MassFraction from HectogramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromHectogramsPerGram(double hectogramspergram) + { + double value = (double) hectogramspergram; + return new MassFraction(value, MassFractionUnit.HectogramPerGram); + } + /// + /// Get MassFraction from HectogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromHectogramsPerKiloGram(double hectogramsperkilogram) + { + double value = (double) hectogramsperkilogram; + return new MassFraction(value, MassFractionUnit.HectogramPerKiloGram); + } + /// + /// Get MassFraction from KilogramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromKilogramsPerGram(double kilogramspergram) + { + double value = (double) kilogramspergram; + return new MassFraction(value, MassFractionUnit.KilogramPerGram); + } + /// + /// Get MassFraction from KilogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromKilogramsPerKiloGram(double kilogramsperkilogram) + { + double value = (double) kilogramsperkilogram; + return new MassFraction(value, MassFractionUnit.KilogramPerKiloGram); + } + /// + /// Get MassFraction from MicrogramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromMicrogramsPerGram(double microgramspergram) + { + double value = (double) microgramspergram; + return new MassFraction(value, MassFractionUnit.MicrogramPerGram); + } + /// + /// Get MassFraction from MicrogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromMicrogramsPerKiloGram(double microgramsperkilogram) + { + double value = (double) microgramsperkilogram; + return new MassFraction(value, MassFractionUnit.MicrogramPerKiloGram); + } + /// + /// Get MassFraction from MilligramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromMilligramsPerGram(double milligramspergram) + { + double value = (double) milligramspergram; + return new MassFraction(value, MassFractionUnit.MilligramPerGram); + } + /// + /// Get MassFraction from MilligramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromMilligramsPerKiloGram(double milligramsperkilogram) + { + double value = (double) milligramsperkilogram; + return new MassFraction(value, MassFractionUnit.MilligramPerKiloGram); + } + /// + /// Get MassFraction from NanogramsPerGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromNanogramsPerGram(double nanogramspergram) + { + double value = (double) nanogramspergram; + return new MassFraction(value, MassFractionUnit.NanogramPerGram); + } + /// + /// Get MassFraction from NanogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromNanogramsPerKiloGram(double nanogramsperkilogram) + { + double value = (double) nanogramsperkilogram; + return new MassFraction(value, MassFractionUnit.NanogramPerKiloGram); + } + /// + /// Get MassFraction from PartsPerBillion. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromPartsPerBillion(double partsperbillion) + { + double value = (double) partsperbillion; + return new MassFraction(value, MassFractionUnit.PartPerBillion); + } + /// + /// Get MassFraction from PartsPerMillion. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromPartsPerMillion(double partspermillion) + { + double value = (double) partspermillion; + return new MassFraction(value, MassFractionUnit.PartPerMillion); + } + /// + /// Get MassFraction from PartsPerThousand. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromPartsPerThousand(double partsperthousand) + { + double value = (double) partsperthousand; + return new MassFraction(value, MassFractionUnit.PartPerThousand); + } + /// + /// Get MassFraction from PartsPerTrillion. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromPartsPerTrillion(double partspertrillion) + { + double value = (double) partspertrillion; + return new MassFraction(value, MassFractionUnit.PartPerTrillion); + } + /// + /// Get MassFraction from Percent. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFraction FromPercent(double percent) + { + double value = (double) percent; + return new MassFraction(value, MassFractionUnit.Percent); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassFraction unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static MassFraction From(double value, MassFractionUnit fromUnit) + { + return new MassFraction((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static MassFraction Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static MassFraction Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out MassFraction result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out MassFraction result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassFractionUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static MassFractionUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out MassFractionUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out MassFractionUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is MassFraction objMassFraction)) throw new ArgumentException("Expected type MassFraction.", nameof(obj)); + + return CompareTo(objMassFraction); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(MassFraction other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is MassFraction objMassFraction)) + return false; + + return Equals(objMassFraction); + } + + public bool Equals(MassFraction other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another MassFraction within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(MassFraction other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current MassFraction. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((MassFractionUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(MassFractionUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this MassFraction to another MassFraction with the unit representation . + /// + /// A MassFraction with the specified unit. + public MassFraction ToUnit(MassFractionUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new MassFraction(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double AsBaseUnit() + { + switch(Unit) + { + case MassFractionUnit.CentigramPerGram: return (_value) * 1e-2d; + case MassFractionUnit.CentigramPerKiloGram: return (_value/1e3) * 1e-2d; + case MassFractionUnit.DecagramPerGram: return (_value) * 1e1d; + case MassFractionUnit.DecagramPerKiloGram: return (_value/1e3) * 1e1d; + case MassFractionUnit.DecigramPerGram: return (_value) * 1e-1d; + case MassFractionUnit.DecigramPerKiloGram: return (_value/1e3) * 1e-1d; + case MassFractionUnit.DecimalFraction: return _value; + case MassFractionUnit.GramPerGram: return _value; + case MassFractionUnit.GramPerKiloGram: return _value/1e3; + case MassFractionUnit.HectogramPerGram: return (_value) * 1e2d; + case MassFractionUnit.HectogramPerKiloGram: return (_value/1e3) * 1e2d; + case MassFractionUnit.KilogramPerGram: return (_value) * 1e3d; + case MassFractionUnit.KilogramPerKiloGram: return (_value/1e3) * 1e3d; + case MassFractionUnit.MicrogramPerGram: return (_value) * 1e-6d; + case MassFractionUnit.MicrogramPerKiloGram: return (_value/1e3) * 1e-6d; + case MassFractionUnit.MilligramPerGram: return (_value) * 1e-3d; + case MassFractionUnit.MilligramPerKiloGram: return (_value/1e3) * 1e-3d; + case MassFractionUnit.NanogramPerGram: return (_value) * 1e-9d; + case MassFractionUnit.NanogramPerKiloGram: return (_value/1e3) * 1e-9d; + case MassFractionUnit.PartPerBillion: return _value/1e9; + case MassFractionUnit.PartPerMillion: return _value/1e6; + case MassFractionUnit.PartPerThousand: return _value/1e3; + case MassFractionUnit.PartPerTrillion: return _value/1e12; + case MassFractionUnit.Percent: return _value/1e2; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(MassFractionUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case MassFractionUnit.CentigramPerGram: return (baseUnitValue) / 1e-2d; + case MassFractionUnit.CentigramPerKiloGram: return (baseUnitValue*1e3) / 1e-2d; + case MassFractionUnit.DecagramPerGram: return (baseUnitValue) / 1e1d; + case MassFractionUnit.DecagramPerKiloGram: return (baseUnitValue*1e3) / 1e1d; + case MassFractionUnit.DecigramPerGram: return (baseUnitValue) / 1e-1d; + case MassFractionUnit.DecigramPerKiloGram: return (baseUnitValue*1e3) / 1e-1d; + case MassFractionUnit.DecimalFraction: return baseUnitValue; + case MassFractionUnit.GramPerGram: return baseUnitValue; + case MassFractionUnit.GramPerKiloGram: return baseUnitValue*1e3; + case MassFractionUnit.HectogramPerGram: return (baseUnitValue) / 1e2d; + case MassFractionUnit.HectogramPerKiloGram: return (baseUnitValue*1e3) / 1e2d; + case MassFractionUnit.KilogramPerGram: return (baseUnitValue) / 1e3d; + case MassFractionUnit.KilogramPerKiloGram: return (baseUnitValue*1e3) / 1e3d; + case MassFractionUnit.MicrogramPerGram: return (baseUnitValue) / 1e-6d; + case MassFractionUnit.MicrogramPerKiloGram: return (baseUnitValue*1e3) / 1e-6d; + case MassFractionUnit.MilligramPerGram: return (baseUnitValue) / 1e-3d; + case MassFractionUnit.MilligramPerKiloGram: return (baseUnitValue*1e3) / 1e-3d; + case MassFractionUnit.NanogramPerGram: return (baseUnitValue) / 1e-9d; + case MassFractionUnit.NanogramPerKiloGram: return (baseUnitValue*1e3) / 1e-9d; + case MassFractionUnit.PartPerBillion: return baseUnitValue*1e9; + case MassFractionUnit.PartPerMillion: return baseUnitValue*1e6; + case MassFractionUnit.PartPerThousand: return baseUnitValue*1e3; + case MassFractionUnit.PartPerTrillion: return baseUnitValue*1e12; + case MassFractionUnit.Percent: return baseUnitValue*1e2; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs index 3fa75e3c27..95383777c4 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs @@ -168,16 +168,31 @@ private Molarity(double numericValue, MolarityUnit unit) /// public double DecimolesPerLiter => As(MolarityUnit.DecimolesPerLiter); + /// + /// Get Molarity in Micromolar. + /// + public double Micromolar => As(MolarityUnit.Micromolar); + /// /// Get Molarity in MicromolesPerLiter. /// public double MicromolesPerLiter => As(MolarityUnit.MicromolesPerLiter); + /// + /// Get Molarity in Millimolar. + /// + public double Millimolar => As(MolarityUnit.Millimolar); + /// /// Get Molarity in MillimolesPerLiter. /// public double MillimolesPerLiter => As(MolarityUnit.MillimolesPerLiter); + /// + /// Get Molarity in Molar. + /// + public double Molar => As(MolarityUnit.Molar); + /// /// Get Molarity in MolesPerCubicMeter. /// @@ -188,11 +203,21 @@ private Molarity(double numericValue, MolarityUnit unit) /// public double MolesPerLiter => As(MolarityUnit.MolesPerLiter); + /// + /// Get Molarity in Nanomolar. + /// + public double Nanomolar => As(MolarityUnit.Nanomolar); + /// /// Get Molarity in NanomolesPerLiter. /// public double NanomolesPerLiter => As(MolarityUnit.NanomolesPerLiter); + /// + /// Get Molarity in Picomolar. + /// + public double Picomolar => As(MolarityUnit.Picomolar); + /// /// Get Molarity in PicomolesPerLiter. /// @@ -249,6 +274,16 @@ public static Molarity FromDecimolesPerLiter(double decimolesperliter) return new Molarity(value, MolarityUnit.DecimolesPerLiter); } /// + /// Get Molarity from Micromolar. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Molarity FromMicromolar(double micromolar) + { + double value = (double) micromolar; + return new Molarity(value, MolarityUnit.Micromolar); + } + /// /// Get Molarity from MicromolesPerLiter. /// /// If value is NaN or Infinity. @@ -259,6 +294,16 @@ public static Molarity FromMicromolesPerLiter(double micromolesperliter) return new Molarity(value, MolarityUnit.MicromolesPerLiter); } /// + /// Get Molarity from Millimolar. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Molarity FromMillimolar(double millimolar) + { + double value = (double) millimolar; + return new Molarity(value, MolarityUnit.Millimolar); + } + /// /// Get Molarity from MillimolesPerLiter. /// /// If value is NaN or Infinity. @@ -269,6 +314,16 @@ public static Molarity FromMillimolesPerLiter(double millimolesperliter) return new Molarity(value, MolarityUnit.MillimolesPerLiter); } /// + /// Get Molarity from Molar. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Molarity FromMolar(double molar) + { + double value = (double) molar; + return new Molarity(value, MolarityUnit.Molar); + } + /// /// Get Molarity from MolesPerCubicMeter. /// /// If value is NaN or Infinity. @@ -289,6 +344,16 @@ public static Molarity FromMolesPerLiter(double molesperliter) return new Molarity(value, MolarityUnit.MolesPerLiter); } /// + /// Get Molarity from Nanomolar. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Molarity FromNanomolar(double nanomolar) + { + double value = (double) nanomolar; + return new Molarity(value, MolarityUnit.Nanomolar); + } + /// /// Get Molarity from NanomolesPerLiter. /// /// If value is NaN or Infinity. @@ -299,6 +364,16 @@ public static Molarity FromNanomolesPerLiter(double nanomolesperliter) return new Molarity(value, MolarityUnit.NanomolesPerLiter); } /// + /// Get Molarity from Picomolar. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Molarity FromPicomolar(double picomolar) + { + double value = (double) picomolar; + return new Molarity(value, MolarityUnit.Picomolar); + } + /// /// Get Molarity from PicomolesPerLiter. /// /// If value is NaN or Infinity. @@ -601,11 +676,16 @@ private double AsBaseUnit() { case MolarityUnit.CentimolesPerLiter: return (_value/1e-3) * 1e-2d; case MolarityUnit.DecimolesPerLiter: return (_value/1e-3) * 1e-1d; + case MolarityUnit.Micromolar: return (_value/1e-3) * 1e-6d; case MolarityUnit.MicromolesPerLiter: return (_value/1e-3) * 1e-6d; + case MolarityUnit.Millimolar: return (_value/1e-3) * 1e-3d; case MolarityUnit.MillimolesPerLiter: return (_value/1e-3) * 1e-3d; + case MolarityUnit.Molar: return _value/1e-3; case MolarityUnit.MolesPerCubicMeter: return _value; case MolarityUnit.MolesPerLiter: return _value/1e-3; + case MolarityUnit.Nanomolar: return (_value/1e-3) * 1e-9d; case MolarityUnit.NanomolesPerLiter: return (_value/1e-3) * 1e-9d; + case MolarityUnit.Picomolar: return (_value/1e-3) * 1e-12d; case MolarityUnit.PicomolesPerLiter: return (_value/1e-3) * 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to base units."); @@ -623,11 +703,16 @@ private double AsBaseNumericType(MolarityUnit unit) { case MolarityUnit.CentimolesPerLiter: return (baseUnitValue*1e-3) / 1e-2d; case MolarityUnit.DecimolesPerLiter: return (baseUnitValue*1e-3) / 1e-1d; + case MolarityUnit.Micromolar: return (baseUnitValue*1e-3) / 1e-6d; case MolarityUnit.MicromolesPerLiter: return (baseUnitValue*1e-3) / 1e-6d; + case MolarityUnit.Millimolar: return (baseUnitValue*1e-3) / 1e-3d; case MolarityUnit.MillimolesPerLiter: return (baseUnitValue*1e-3) / 1e-3d; + case MolarityUnit.Molar: return baseUnitValue*1e-3; case MolarityUnit.MolesPerCubicMeter: return baseUnitValue; case MolarityUnit.MolesPerLiter: return baseUnitValue*1e-3; + case MolarityUnit.Nanomolar: return (baseUnitValue*1e-3) / 1e-9d; case MolarityUnit.NanomolesPerLiter: return (baseUnitValue*1e-3) / 1e-9d; + case MolarityUnit.Picomolar: return (baseUnitValue*1e-3) / 1e-12d; case MolarityUnit.PicomolesPerLiter: return (baseUnitValue*1e-3) / 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/VolumeConcentration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/VolumeConcentration.WindowsRuntimeComponent.g.cs new file mode 100644 index 0000000000..2589f1830e --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/VolumeConcentration.WindowsRuntimeComponent.g.cs @@ -0,0 +1,906 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// The volume concentration (not to be confused with volume fraction) is defined as the volume of a constituent divided by the total volume of the mixture. + /// + /// + /// https://en.wikipedia.org/wiki/Concentration#Volume_concentration + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class VolumeConcentration : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly VolumeConcentrationUnit? _unit; + + static VolumeConcentration() + { + BaseDimensions = BaseDimensions.Dimensionless; + Info = new QuantityInfo(QuantityType.VolumeConcentration, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit DecimalFraction. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public VolumeConcentration() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private VolumeConcentration(double numericValue, VolumeConcentrationUnit unit) + { + if(unit == VolumeConcentrationUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of VolumeConcentration, which is DecimalFraction. All conversions go via this value. + /// + public static VolumeConcentrationUnit BaseUnit { get; } = VolumeConcentrationUnit.DecimalFraction; + + /// + /// Represents the largest possible value of VolumeConcentration + /// + public static VolumeConcentration MaxValue { get; } = new VolumeConcentration(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of VolumeConcentration + /// + public static VolumeConcentration MinValue { get; } = new VolumeConcentration(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.VolumeConcentration; + + /// + /// All units of measurement for the VolumeConcentration quantity. + /// + public static VolumeConcentrationUnit[] Units { get; } = Enum.GetValues(typeof(VolumeConcentrationUnit)).Cast().Except(new VolumeConcentrationUnit[]{ VolumeConcentrationUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. + /// + public static VolumeConcentration Zero { get; } = new VolumeConcentration(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public VolumeConcentrationUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => VolumeConcentration.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => VolumeConcentration.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get VolumeConcentration in CentilitersPerLiter. + /// + public double CentilitersPerLiter => As(VolumeConcentrationUnit.CentilitersPerLiter); + + /// + /// Get VolumeConcentration in CentilitersPerMililiter. + /// + public double CentilitersPerMililiter => As(VolumeConcentrationUnit.CentilitersPerMililiter); + + /// + /// Get VolumeConcentration in DecilitersPerLiter. + /// + public double DecilitersPerLiter => As(VolumeConcentrationUnit.DecilitersPerLiter); + + /// + /// Get VolumeConcentration in DecilitersPerMililiter. + /// + public double DecilitersPerMililiter => As(VolumeConcentrationUnit.DecilitersPerMililiter); + + /// + /// Get VolumeConcentration in DecimalFractions. + /// + public double DecimalFractions => As(VolumeConcentrationUnit.DecimalFraction); + + /// + /// Get VolumeConcentration in LitersPerLiter. + /// + public double LitersPerLiter => As(VolumeConcentrationUnit.LitersPerLiter); + + /// + /// Get VolumeConcentration in LitersPerMililiter. + /// + public double LitersPerMililiter => As(VolumeConcentrationUnit.LitersPerMililiter); + + /// + /// Get VolumeConcentration in MicrolitersPerLiter. + /// + public double MicrolitersPerLiter => As(VolumeConcentrationUnit.MicrolitersPerLiter); + + /// + /// Get VolumeConcentration in MicrolitersPerMililiter. + /// + public double MicrolitersPerMililiter => As(VolumeConcentrationUnit.MicrolitersPerMililiter); + + /// + /// Get VolumeConcentration in MillilitersPerLiter. + /// + public double MillilitersPerLiter => As(VolumeConcentrationUnit.MillilitersPerLiter); + + /// + /// Get VolumeConcentration in MillilitersPerMililiter. + /// + public double MillilitersPerMililiter => As(VolumeConcentrationUnit.MillilitersPerMililiter); + + /// + /// Get VolumeConcentration in NanolitersPerLiter. + /// + public double NanolitersPerLiter => As(VolumeConcentrationUnit.NanolitersPerLiter); + + /// + /// Get VolumeConcentration in NanolitersPerMililiter. + /// + public double NanolitersPerMililiter => As(VolumeConcentrationUnit.NanolitersPerMililiter); + + /// + /// Get VolumeConcentration in PartsPerBillion. + /// + public double PartsPerBillion => As(VolumeConcentrationUnit.PartPerBillion); + + /// + /// Get VolumeConcentration in PartsPerMillion. + /// + public double PartsPerMillion => As(VolumeConcentrationUnit.PartPerMillion); + + /// + /// Get VolumeConcentration in PartsPerThousand. + /// + public double PartsPerThousand => As(VolumeConcentrationUnit.PartPerThousand); + + /// + /// Get VolumeConcentration in PartsPerTrillion. + /// + public double PartsPerTrillion => As(VolumeConcentrationUnit.PartPerTrillion); + + /// + /// Get VolumeConcentration in Percent. + /// + public double Percent => As(VolumeConcentrationUnit.Percent); + + /// + /// Get VolumeConcentration in PicolitersPerLiter. + /// + public double PicolitersPerLiter => As(VolumeConcentrationUnit.PicolitersPerLiter); + + /// + /// Get VolumeConcentration in PicolitersPerMililiter. + /// + public double PicolitersPerMililiter => As(VolumeConcentrationUnit.PicolitersPerMililiter); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(VolumeConcentrationUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(VolumeConcentrationUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get VolumeConcentration from CentilitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromCentilitersPerLiter(double centilitersperliter) + { + double value = (double) centilitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.CentilitersPerLiter); + } + /// + /// Get VolumeConcentration from CentilitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromCentilitersPerMililiter(double centiliterspermililiter) + { + double value = (double) centiliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.CentilitersPerMililiter); + } + /// + /// Get VolumeConcentration from DecilitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromDecilitersPerLiter(double decilitersperliter) + { + double value = (double) decilitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.DecilitersPerLiter); + } + /// + /// Get VolumeConcentration from DecilitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromDecilitersPerMililiter(double deciliterspermililiter) + { + double value = (double) deciliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.DecilitersPerMililiter); + } + /// + /// Get VolumeConcentration from DecimalFractions. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromDecimalFractions(double decimalfractions) + { + double value = (double) decimalfractions; + return new VolumeConcentration(value, VolumeConcentrationUnit.DecimalFraction); + } + /// + /// Get VolumeConcentration from LitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromLitersPerLiter(double litersperliter) + { + double value = (double) litersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.LitersPerLiter); + } + /// + /// Get VolumeConcentration from LitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromLitersPerMililiter(double literspermililiter) + { + double value = (double) literspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.LitersPerMililiter); + } + /// + /// Get VolumeConcentration from MicrolitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromMicrolitersPerLiter(double microlitersperliter) + { + double value = (double) microlitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MicrolitersPerLiter); + } + /// + /// Get VolumeConcentration from MicrolitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromMicrolitersPerMililiter(double microliterspermililiter) + { + double value = (double) microliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MicrolitersPerMililiter); + } + /// + /// Get VolumeConcentration from MillilitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromMillilitersPerLiter(double millilitersperliter) + { + double value = (double) millilitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MillilitersPerLiter); + } + /// + /// Get VolumeConcentration from MillilitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromMillilitersPerMililiter(double milliliterspermililiter) + { + double value = (double) milliliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MillilitersPerMililiter); + } + /// + /// Get VolumeConcentration from NanolitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromNanolitersPerLiter(double nanolitersperliter) + { + double value = (double) nanolitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.NanolitersPerLiter); + } + /// + /// Get VolumeConcentration from NanolitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromNanolitersPerMililiter(double nanoliterspermililiter) + { + double value = (double) nanoliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.NanolitersPerMililiter); + } + /// + /// Get VolumeConcentration from PartsPerBillion. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPartsPerBillion(double partsperbillion) + { + double value = (double) partsperbillion; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerBillion); + } + /// + /// Get VolumeConcentration from PartsPerMillion. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPartsPerMillion(double partspermillion) + { + double value = (double) partspermillion; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerMillion); + } + /// + /// Get VolumeConcentration from PartsPerThousand. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPartsPerThousand(double partsperthousand) + { + double value = (double) partsperthousand; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerThousand); + } + /// + /// Get VolumeConcentration from PartsPerTrillion. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPartsPerTrillion(double partspertrillion) + { + double value = (double) partspertrillion; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerTrillion); + } + /// + /// Get VolumeConcentration from Percent. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPercent(double percent) + { + double value = (double) percent; + return new VolumeConcentration(value, VolumeConcentrationUnit.Percent); + } + /// + /// Get VolumeConcentration from PicolitersPerLiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPicolitersPerLiter(double picolitersperliter) + { + double value = (double) picolitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.PicolitersPerLiter); + } + /// + /// Get VolumeConcentration from PicolitersPerMililiter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static VolumeConcentration FromPicolitersPerMililiter(double picoliterspermililiter) + { + double value = (double) picoliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.PicolitersPerMililiter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// VolumeConcentration unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static VolumeConcentration From(double value, VolumeConcentrationUnit fromUnit) + { + return new VolumeConcentration((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static VolumeConcentration Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static VolumeConcentration Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out VolumeConcentration result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out VolumeConcentration result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static VolumeConcentrationUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static VolumeConcentrationUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out VolumeConcentrationUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out VolumeConcentrationUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is VolumeConcentration objVolumeConcentration)) throw new ArgumentException("Expected type VolumeConcentration.", nameof(obj)); + + return CompareTo(objVolumeConcentration); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(VolumeConcentration other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is VolumeConcentration objVolumeConcentration)) + return false; + + return Equals(objVolumeConcentration); + } + + public bool Equals(VolumeConcentration other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another VolumeConcentration within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(VolumeConcentration other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current VolumeConcentration. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((VolumeConcentrationUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(VolumeConcentrationUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this VolumeConcentration to another VolumeConcentration with the unit representation . + /// + /// A VolumeConcentration with the specified unit. + public VolumeConcentration ToUnit(VolumeConcentrationUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new VolumeConcentration(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double AsBaseUnit() + { + switch(Unit) + { + case VolumeConcentrationUnit.CentilitersPerLiter: return (_value) * 1e-2d; + case VolumeConcentrationUnit.CentilitersPerMililiter: return (_value/1e-3) * 1e-2d; + case VolumeConcentrationUnit.DecilitersPerLiter: return (_value) * 1e-1d; + case VolumeConcentrationUnit.DecilitersPerMililiter: return (_value/1e-3) * 1e-1d; + case VolumeConcentrationUnit.DecimalFraction: return _value; + case VolumeConcentrationUnit.LitersPerLiter: return _value; + case VolumeConcentrationUnit.LitersPerMililiter: return _value/1e-3; + case VolumeConcentrationUnit.MicrolitersPerLiter: return (_value) * 1e-6d; + case VolumeConcentrationUnit.MicrolitersPerMililiter: return (_value/1e-3) * 1e-6d; + case VolumeConcentrationUnit.MillilitersPerLiter: return (_value) * 1e-3d; + case VolumeConcentrationUnit.MillilitersPerMililiter: return (_value/1e-3) * 1e-3d; + case VolumeConcentrationUnit.NanolitersPerLiter: return (_value) * 1e-9d; + case VolumeConcentrationUnit.NanolitersPerMililiter: return (_value/1e-3) * 1e-9d; + case VolumeConcentrationUnit.PartPerBillion: return _value/1e9; + case VolumeConcentrationUnit.PartPerMillion: return _value/1e6; + case VolumeConcentrationUnit.PartPerThousand: return _value/1e3; + case VolumeConcentrationUnit.PartPerTrillion: return _value/1e12; + case VolumeConcentrationUnit.Percent: return _value/1e2; + case VolumeConcentrationUnit.PicolitersPerLiter: return (_value) * 1e-12d; + case VolumeConcentrationUnit.PicolitersPerMililiter: return (_value/1e-3) * 1e-12d; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(VolumeConcentrationUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case VolumeConcentrationUnit.CentilitersPerLiter: return (baseUnitValue) / 1e-2d; + case VolumeConcentrationUnit.CentilitersPerMililiter: return (baseUnitValue*1e-3) / 1e-2d; + case VolumeConcentrationUnit.DecilitersPerLiter: return (baseUnitValue) / 1e-1d; + case VolumeConcentrationUnit.DecilitersPerMililiter: return (baseUnitValue*1e-3) / 1e-1d; + case VolumeConcentrationUnit.DecimalFraction: return baseUnitValue; + case VolumeConcentrationUnit.LitersPerLiter: return baseUnitValue; + case VolumeConcentrationUnit.LitersPerMililiter: return baseUnitValue*1e-3; + case VolumeConcentrationUnit.MicrolitersPerLiter: return (baseUnitValue) / 1e-6d; + case VolumeConcentrationUnit.MicrolitersPerMililiter: return (baseUnitValue*1e-3) / 1e-6d; + case VolumeConcentrationUnit.MillilitersPerLiter: return (baseUnitValue) / 1e-3d; + case VolumeConcentrationUnit.MillilitersPerMililiter: return (baseUnitValue*1e-3) / 1e-3d; + case VolumeConcentrationUnit.NanolitersPerLiter: return (baseUnitValue) / 1e-9d; + case VolumeConcentrationUnit.NanolitersPerMililiter: return (baseUnitValue*1e-3) / 1e-9d; + case VolumeConcentrationUnit.PartPerBillion: return baseUnitValue*1e9; + case VolumeConcentrationUnit.PartPerMillion: return baseUnitValue*1e6; + case VolumeConcentrationUnit.PartPerThousand: return baseUnitValue*1e3; + case VolumeConcentrationUnit.PartPerTrillion: return baseUnitValue*1e12; + case VolumeConcentrationUnit.Percent: return baseUnitValue*1e2; + case VolumeConcentrationUnit.PicolitersPerLiter: return (baseUnitValue) / 1e-12d; + case VolumeConcentrationUnit.PicolitersPerMililiter: return (baseUnitValue*1e-3) / 1e-12d; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs index 3cb3fc2e03..3bfddc50b7 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs @@ -206,12 +206,18 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case MassUnit massUnit: quantity = Mass.From(value, massUnit); return true; + case MassConcentrationUnit massConcentrationUnit: + quantity = MassConcentration.From(value, massConcentrationUnit); + return true; case MassFlowUnit massFlowUnit: quantity = MassFlow.From(value, massFlowUnit); return true; case MassFluxUnit massFluxUnit: quantity = MassFlux.From(value, massFluxUnit); return true; + case MassFractionUnit massFractionUnit: + quantity = MassFraction.From(value, massFractionUnit); + return true; case MassMomentOfInertiaUnit massMomentOfInertiaUnit: quantity = MassMomentOfInertia.From(value, massMomentOfInertiaUnit); return true; @@ -311,6 +317,9 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case VolumeUnit volumeUnit: quantity = Volume.From(value, volumeUnit); return true; + case VolumeConcentrationUnit volumeConcentrationUnit: + quantity = VolumeConcentration.From(value, volumeConcentrationUnit); + return true; case VolumeFlowUnit volumeFlowUnit: quantity = VolumeFlow.From(value, volumeFlowUnit); return true; @@ -532,12 +541,18 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(Mass)) return parser.TryParse(quantityString, formatProvider, Mass.From, out quantity); + if (quantityType == typeof(MassConcentration)) + return parser.TryParse(quantityString, formatProvider, MassConcentration.From, out quantity); + if (quantityType == typeof(MassFlow)) return parser.TryParse(quantityString, formatProvider, MassFlow.From, out quantity); if (quantityType == typeof(MassFlux)) return parser.TryParse(quantityString, formatProvider, MassFlux.From, out quantity); + if (quantityType == typeof(MassFraction)) + return parser.TryParse(quantityString, formatProvider, MassFraction.From, out quantity); + if (quantityType == typeof(MassMomentOfInertia)) return parser.TryParse(quantityString, formatProvider, MassMomentOfInertia.From, out quantity); @@ -637,6 +652,9 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(Volume)) return parser.TryParse(quantityString, formatProvider, Volume.From, out quantity); + if (quantityType == typeof(VolumeConcentration)) + return parser.TryParse(quantityString, formatProvider, VolumeConcentration.From, out quantity); + if (quantityType == typeof(VolumeFlow)) return parser.TryParse(quantityString, formatProvider, VolumeFlow.From, out quantity); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs index 6f3669d6c7..a3b4f29970 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs @@ -84,8 +84,10 @@ public enum QuantityType MagneticFlux, Magnetization, Mass, + MassConcentration, MassFlow, MassFlux, + MassFraction, MassMomentOfInertia, MolarEnergy, MolarEntropy, @@ -119,6 +121,7 @@ public enum QuantityType Torque, VitaminA, Volume, + VolumeConcentration, VolumeFlow, VolumePerLength, } diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index f004d3978a..3fadbbf82c 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -582,6 +582,50 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassUnit), (int)MassUnit.Stone, new string[]{"st"}), ("en-US", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"t"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"т"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerDeciliter, new string[]{"cg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerLiter, new string[]{"cg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerMilliliter, new string[]{"cg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerDeciliter, new string[]{"dg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerLiter, new string[]{"dg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerMilliliter, new string[]{"dg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicCentimeter, new string[]{"g/cm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"g/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"г/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMillimeter, new string[]{"g/mm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerDeciliter, new string[]{"g/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerLiter, new string[]{"g/l", "g/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerMilliliter, new string[]{"g/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicCentimeter, new string[]{"kg/cm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kg/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kг/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMillimeter, new string[]{"kg/mm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerLiter, new string[]{"kg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicFoot, new string[]{"kip/ft³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicInch, new string[]{"kip/in³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µg/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µг/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerDeciliter, new string[]{"µg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerLiter, new string[]{"µg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerMilliliter, new string[]{"µg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mg/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mг/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerDeciliter, new string[]{"mg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerLiter, new string[]{"mg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerMilliliter, new string[]{"mg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerDeciliter, new string[]{"ng/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerLiter, new string[]{"ng/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerMilliliter, new string[]{"ng/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerDeciliter, new string[]{"pg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerLiter, new string[]{"pg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerMilliliter, new string[]{"pg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicFoot, new string[]{"lb/ft³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicInch, new string[]{"lb/in³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerImperialGallon, new string[]{"ppg (imp.)"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerUSGallon, new string[]{"ppg (U.S.)"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.SlugPerCubicFoot, new string[]{"slug/ft³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.TonnePerCubicCentimeter, new string[]{"t/cm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.TonnePerCubicMeter, new string[]{"t/m³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.TonnePerCubicMillimeter, new string[]{"t/mm³"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.CentigramPerDay, new string[]{"cg/d"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.CentigramPerSecond, new string[]{"cg/S"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.DecagramPerDay, new string[]{"dag/d"}), @@ -617,6 +661,30 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.TonnePerHour, new string[]{"t/h"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMeter, new string[]{"g·s⁻¹·m⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMeter, new string[]{"kg·s⁻¹·m⁻²"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerGram, new string[]{"cg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKiloGram, new string[]{"cg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerGram, new string[]{"dag/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerKiloGram, new string[]{"dag/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerGram, new string[]{"dg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerKiloGram, new string[]{"dg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecimalFraction, new string[]{""}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerGram, new string[]{"g/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerKiloGram, new string[]{"g/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerGram, new string[]{"hg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerKiloGram, new string[]{"hg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerGram, new string[]{"kg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerKiloGram, new string[]{"kg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerGram, new string[]{"µg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerKiloGram, new string[]{"µg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerGram, new string[]{"mg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerKiloGram, new string[]{"mg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerGram, new string[]{"ng/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerKiloGram, new string[]{"ng/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerBillion, new string[]{"ppb"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerMillion, new string[]{"ppm"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerThousand, new string[]{"‰"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerTrillion, new string[]{"ppt"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.Percent, new string[]{"%", "% (w/w)"}), ("en-US", typeof(MassMomentOfInertiaUnit), (int)MassMomentOfInertiaUnit.GramSquareCentimeter, new string[]{"g·cm²"}), ("en-US", typeof(MassMomentOfInertiaUnit), (int)MassMomentOfInertiaUnit.GramSquareDecimeter, new string[]{"g·dm²"}), ("en-US", typeof(MassMomentOfInertiaUnit), (int)MassMomentOfInertiaUnit.GramSquareMeter, new string[]{"g·m²"}), @@ -653,11 +721,16 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MolarEntropyUnit), (int)MolarEntropyUnit.MegajoulePerMoleKelvin, new string[]{"MJ/(mol*K)"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.CentimolesPerLiter, new string[]{"cmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.DecimolesPerLiter, new string[]{"dmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Micromolar, new string[]{"µM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MicromolesPerLiter, new string[]{"µmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Millimolar, new string[]{"mM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MillimolesPerLiter, new string[]{"mmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Molar, new string[]{"M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerCubicMeter, new string[]{"mol/m³"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerLiter, new string[]{"mol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Nanomolar, new string[]{"nM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.NanomolesPerLiter, new string[]{"nmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Picomolar, new string[]{"pM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.PicomolesPerLiter, new string[]{"pmol/L"}), ("en-US", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"cg/mol"}), ("ru-RU", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"сг/моль"}), @@ -1100,6 +1173,26 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("ru-RU", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("nb-NO", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerLiter, new string[]{"cl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerMililiter, new string[]{"cl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerLiter, new string[]{"dl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerMililiter, new string[]{"dl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecimalFraction, new string[]{""}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerLiter, new string[]{"l/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerMililiter, new string[]{"l/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerLiter, new string[]{"µl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerMililiter, new string[]{"µl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerLiter, new string[]{"ml/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerMililiter, new string[]{"ml/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerLiter, new string[]{"nl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerMililiter, new string[]{"nl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerBillion, new string[]{"ppb"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerMillion, new string[]{"ppm"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerThousand, new string[]{"‰"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerTrillion, new string[]{"ppt"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.Percent, new string[]{"%", "% (v/v)"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerLiter, new string[]{"pl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerMililiter, new string[]{"pl/ml"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerDay, new string[]{"af/d"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerHour, new string[]{"af/h"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerMinute, new string[]{"af/m"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassConcentrationUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassConcentrationUnit.g.cs new file mode 100644 index 0000000000..8e869541f3 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassConcentrationUnit.g.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum MassConcentrationUnit + { + Undefined = 0, + CentigramPerDeciliter, + CentigramPerLiter, + CentigramPerMilliliter, + DecigramPerDeciliter, + DecigramPerLiter, + DecigramPerMilliliter, + GramPerCubicCentimeter, + GramPerCubicMeter, + GramPerCubicMillimeter, + GramPerDeciliter, + GramPerLiter, + GramPerMilliliter, + KilogramPerCubicCentimeter, + KilogramPerCubicMeter, + KilogramPerCubicMillimeter, + KilogramPerLiter, + KilopoundPerCubicFoot, + KilopoundPerCubicInch, + MicrogramPerCubicMeter, + MicrogramPerDeciliter, + MicrogramPerLiter, + MicrogramPerMilliliter, + MilligramPerCubicMeter, + MilligramPerDeciliter, + MilligramPerLiter, + MilligramPerMilliliter, + NanogramPerDeciliter, + NanogramPerLiter, + NanogramPerMilliliter, + PicogramPerDeciliter, + PicogramPerLiter, + PicogramPerMilliliter, + PoundPerCubicFoot, + PoundPerCubicInch, + PoundPerImperialGallon, + PoundPerUSGallon, + SlugPerCubicFoot, + TonnePerCubicCentimeter, + TonnePerCubicMeter, + TonnePerCubicMillimeter, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs new file mode 100644 index 0000000000..fe7f622126 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum MassFractionUnit + { + Undefined = 0, + CentigramPerGram, + CentigramPerKiloGram, + DecagramPerGram, + DecagramPerKiloGram, + DecigramPerGram, + DecigramPerKiloGram, + DecimalFraction, + GramPerGram, + GramPerKiloGram, + HectogramPerGram, + HectogramPerKiloGram, + KilogramPerGram, + KilogramPerKiloGram, + MicrogramPerGram, + MicrogramPerKiloGram, + MilligramPerGram, + MilligramPerKiloGram, + NanogramPerGram, + NanogramPerKiloGram, + PartPerBillion, + PartPerMillion, + PartPerThousand, + PartPerTrillion, + Percent, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs index be257aec48..089593b8ec 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs @@ -28,11 +28,16 @@ public enum MolarityUnit Undefined = 0, CentimolesPerLiter, DecimolesPerLiter, + Micromolar, MicromolesPerLiter, + Millimolar, MillimolesPerLiter, + Molar, MolesPerCubicMeter, MolesPerLiter, + Nanomolar, NanomolesPerLiter, + Picomolar, PicomolesPerLiter, } diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/VolumeConcentrationUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/VolumeConcentrationUnit.g.cs new file mode 100644 index 0000000000..6431bc77c0 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/VolumeConcentrationUnit.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum VolumeConcentrationUnit + { + Undefined = 0, + CentilitersPerLiter, + CentilitersPerMililiter, + DecilitersPerLiter, + DecilitersPerMililiter, + DecimalFraction, + LitersPerLiter, + LitersPerMililiter, + MicrolitersPerLiter, + MicrolitersPerMililiter, + MillilitersPerLiter, + MillilitersPerMililiter, + NanolitersPerLiter, + NanolitersPerMililiter, + PartPerBillion, + PartPerMillion, + PartPerThousand, + PartPerTrillion, + Percent, + PicolitersPerLiter, + PicolitersPerMililiter, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs index 1a206b9c04..30693f48eb 100644 --- a/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmountOfSubstance.extra.cs @@ -33,5 +33,37 @@ public double NumberOfParticles() var moles = GetValueAs(AmountOfSubstanceUnit.Mole); return AvogadroConstant * moles; } + + + /// Get from and a given . + public static AmountOfSubstance FromMass(Mass mass, MolarMass molarMass) + { + return mass / molarMass; + } + + /// Get from for a given . + public static Mass operator *(AmountOfSubstance amountOfSubstance, MolarMass molarMass) + { + return Mass.FromGrams(amountOfSubstance.Moles * molarMass.GramsPerMole); + } + + /// Get from for a given . + public static Mass operator *(MolarMass molarMass, AmountOfSubstance amountOfSubstance) + { + return Mass.FromGrams(amountOfSubstance.Moles * molarMass.GramsPerMole); + } + + /// Get from divided by . + public static Molarity operator /(AmountOfSubstance amountOfComponent, Volume mixtureVolume) + { + return Molarity.FromMolesPerCubicMeter(amountOfComponent.Moles / mixtureVolume.CubicMeters); + } + + /// Get from divided by . + public static Volume operator /(AmountOfSubstance amountOfSubstance, Molarity molarity) + { + return Volume.FromCubicMeters(amountOfSubstance.Moles / molarity.MolesPerCubicMeter); + } + } } diff --git a/UnitsNet/CustomCode/Quantities/Density.extra.cs b/UnitsNet/CustomCode/Quantities/Density.extra.cs index 43dfabbd42..4a98f59f70 100644 --- a/UnitsNet/CustomCode/Quantities/Density.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Density.extra.cs @@ -7,26 +7,6 @@ namespace UnitsNet { public partial struct Density { - /// - /// Gets from this . - /// - /// - public Molarity ToMolarity(Mass molecularWeight) - { - return Molarity.FromMolesPerCubicMeter(KilogramsPerCubicMeter / molecularWeight.Kilograms); - } - - #region Static Methods - - /// - /// Get from . - /// - public static Density FromMolarity(Molarity molarity, Mass molecularWeight) - { - return new Density(molarity.MolesPerCubicMeter * molecularWeight.Kilograms, DensityUnit.KilogramPerCubicMeter); - } - - #endregion /// Get from times . public static Mass operator *(Density density, Volume volume) @@ -58,10 +38,5 @@ public static Density FromMolarity(Molarity molarity, Mass molecularWeight) return new SpecificWeight(density.KilogramsPerCubicMeter * acceleration.MetersPerSecondSquared, SpecificWeightUnit.NewtonPerCubicMeter); } - /// Get from divided by . - public static Molarity operator /(Density density, Mass molecularWeight) - { - return new Molarity(density.KilogramsPerCubicMeter / molecularWeight.Kilograms, MolarityUnit.MolesPerCubicMeter); - } } } diff --git a/UnitsNet/CustomCode/Quantities/MassConcentration.extra.cs b/UnitsNet/CustomCode/Quantities/MassConcentration.extra.cs new file mode 100644 index 0000000000..edce6c4ee2 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/MassConcentration.extra.cs @@ -0,0 +1,79 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using UnitsNet.Units; + +namespace UnitsNet +{ + public partial struct MassConcentration + { + /// + /// Get from this using the known component . + /// + /// + public Molarity ToMolarity(MolarMass molecularWeight) + { + return this / molecularWeight; + } + + /// + /// Get from this using the known component . + /// + /// + /// + public VolumeConcentration ToVolumeConcentration(Density componentDensity) + { + return this / componentDensity; + } + + + #region Static Methods + + /// + /// Get from . + /// + public static MassConcentration FromMolarity(Molarity molarity, MolarMass mass) + { + return molarity * mass; + } + + /// + /// Get from and component . + /// + public static MassConcentration FromVolumeConcentration(VolumeConcentration volumeConcentration, Density componentDensity) + { + return volumeConcentration * componentDensity; + } + + #endregion + + #region Operators + + /// Get from times . + public static Mass operator *(MassConcentration density, Volume volume) + { + return Mass.FromKilograms(density.KilogramsPerCubicMeter * volume.CubicMeters); + } + + /// Get from times . + public static Mass operator *(Volume volume, MassConcentration density) + { + return Mass.FromKilograms(density.KilogramsPerCubicMeter * volume.CubicMeters); + } + + /// Get from divided by the component's . + public static Molarity operator /(MassConcentration massConcentration, MolarMass componentMass) + { + return Molarity.FromMolesPerCubicMeter(massConcentration.GramsPerCubicMeter / componentMass.GramsPerMole); + } + + /// Get from divided by the component's . + public static VolumeConcentration operator /(MassConcentration massConcentration, Density componentDensity) + { + return VolumeConcentration.FromDecimalFractions(massConcentration.KilogramsPerCubicMeter / componentDensity.KilogramsPerCubicMeter); + } + + #endregion + + } +} diff --git a/UnitsNet/CustomCode/Quantities/MassFraction.extra.cs b/UnitsNet/CustomCode/Quantities/MassFraction.extra.cs new file mode 100644 index 0000000000..c685887214 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/MassFraction.extra.cs @@ -0,0 +1,57 @@ +using UnitsNet.Units; + +namespace UnitsNet +{ + public partial struct MassFraction + { + /// + /// Get the of the component by multiplying the of the mixture and this . + /// + /// The total mass of the mixture + /// The actual mass of the component involved in this mixture + public Mass GetComponentMass(Mass totalMass) + { + return totalMass * this; + } + + /// + /// Get the total of the mixture by dividing the of the component by this + /// + /// The actual mass of the component involved in this mixture + /// The total mass of the mixture + public Mass GetTotalMass(Mass componentMass) + { + return componentMass / this; + } + + #region Static Methods + + /// + /// Get from a component and total mixture . + /// + public static MassFraction FromMasses(Mass componentMass, Mass mixtureMass) + { + return new MassFraction(componentMass / mixtureMass, MassFractionUnit.DecimalFraction); + } + + #endregion + + /// Get from multiplied by a . + public static Mass operator *(MassFraction massFraction, Mass mass) + { + return Mass.FromKilograms(massFraction.DecimalFractions * mass.Kilograms); + } + + /// Get from multiplied by a . + public static Mass operator *(Mass mass, MassFraction massFraction) + { + return Mass.FromKilograms(massFraction.DecimalFractions * mass.Kilograms); + } + /// Get the total by dividing the component by a . + public static Mass operator /(Mass mass, MassFraction massFraction) + { + return Mass.FromKilograms(mass.Kilograms / massFraction.DecimalFractions); + } + + } +} diff --git a/UnitsNet/CustomCode/Quantities/MolarMass.extra.cs b/UnitsNet/CustomCode/Quantities/MolarMass.extra.cs new file mode 100644 index 0000000000..2a9d853e81 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/MolarMass.extra.cs @@ -0,0 +1,15 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +namespace UnitsNet +{ + public partial struct MolarMass + { + /// Get from divided by . + public static AmountOfSubstance operator /(Mass mass, MolarMass molarMass) + { + return AmountOfSubstance.FromMoles(mass.Kilograms / molarMass.KilogramsPerMole); + } + + } +} diff --git a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs index b7ce39d5f3..372fa12817 100644 --- a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs @@ -5,40 +5,70 @@ namespace UnitsNet { public partial struct Molarity { + /// - /// Construct from divided by . + /// Get a from this . /// - /// - [Obsolete("This constructor will be removed in favor of operator overload Density.op_Division(UnitsNet.Density,UnitsNet.Mass).")] - public Molarity(Density density, Mass molecularWeight) - : this() + /// + public MassConcentration ToMassConcentration(MolarMass molecularWeight) { - _value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms; - _unit = MolarityUnit.MolesPerCubicMeter; + return this * molecularWeight; } /// - /// Get a from this . + /// Get a from this . /// - /// - public Density ToDensity(Mass molecularWeight) + /// + /// + public VolumeConcentration ToVolumeConcentration(Density componentDensity, MolarMass componentMass) { - return Density.FromKilogramsPerCubicMeter(MolesPerCubicMeter * molecularWeight.Kilograms); + return this * componentMass / componentDensity; } #region Static Methods + /// - /// Get from . + /// Get from and known component and . /// - /// - /// - [Obsolete("Use Density / Mass operator overload instead.")] - public static Molarity FromDensity(Density density, Mass molecularWeight) + /// + /// + /// + /// + public static Molarity FromVolumeConcentration(VolumeConcentration volumeConcentration, Density componentDensity, MolarMass componentMass) + { + return volumeConcentration * componentDensity / componentMass; + } + + #endregion + + #region Operators + + /// Get from times the . + public static MassConcentration operator *(Molarity molarity, MolarMass componentMass) { - return density / molecularWeight; + return MassConcentration.FromGramsPerCubicMeter(molarity.MolesPerCubicMeter * componentMass.GramsPerMole); + } + + /// Get from times the . + public static MassConcentration operator *(MolarMass componentMass, Molarity molarity) + { + return MassConcentration.FromGramsPerCubicMeter(molarity.MolesPerCubicMeter * componentMass.GramsPerMole); + } + + /// Get from diluting the current by the given . + public static Molarity operator *(Molarity molarity, VolumeConcentration volumeConcentration) + { + return new Molarity(molarity.MolesPerCubicMeter * volumeConcentration.DecimalFractions, MolarityUnit.MolesPerCubicMeter); + } + + /// Get from diluting the current by the given . + public static Molarity operator *(VolumeConcentration volumeConcentration, Molarity molarity) + { + return new Molarity(molarity.MolesPerCubicMeter * volumeConcentration.DecimalFractions, MolarityUnit.MolesPerCubicMeter); } #endregion + } } diff --git a/UnitsNet/CustomCode/Quantities/VolumeConcentration.extra.cs b/UnitsNet/CustomCode/Quantities/VolumeConcentration.extra.cs new file mode 100644 index 0000000000..e90942cfd1 --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/VolumeConcentration.extra.cs @@ -0,0 +1,69 @@ +using UnitsNet.Units; + +namespace UnitsNet +{ + public partial struct VolumeConcentration + { + /// + /// Get from this and component . + /// + /// + /// + public MassConcentration ToMassConcentration(Density componentDensity) + { + return this * componentDensity; + } + + /// + /// Get from this and component and . + /// + /// + /// + /// + public Molarity ToMolarity(Density componentDensity, MolarMass compontMolarMass) + { + return this * componentDensity / compontMolarMass; + } + + #region Static Methods + + /// + /// Get from a component and total mixture . + /// + public static VolumeConcentration FromVolumes(Volume componentVolume, Volume mixtureMass) + { + return new VolumeConcentration(componentVolume / mixtureMass, VolumeConcentrationUnit.DecimalFraction); + } + + /// + /// Get a from and a component and . + /// + /// + /// + /// + public static VolumeConcentration FromMolarity(Molarity molarity, Density componentDensity, MolarMass componentMolarMass) + { + return molarity * componentMolarMass / componentDensity; + } + + + #endregion + + #region Operators + + /// Get from times the component . + public static MassConcentration operator *(VolumeConcentration volumeConcentration, Density componentDensity) + { + return MassConcentration.FromKilogramsPerCubicMeter(volumeConcentration.DecimalFractions * componentDensity.KilogramsPerCubicMeter); + } + + /// Get from times the component . + public static MassConcentration operator *(Density componentDensity, VolumeConcentration volumeConcentration) + { + return MassConcentration.FromKilogramsPerCubicMeter(volumeConcentration.DecimalFractions * componentDensity.KilogramsPerCubicMeter); + } + + #endregion + + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs new file mode 100644 index 0000000000..ee111448a7 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs @@ -0,0 +1,1505 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// In chemistry, the mass concentration ρi (or γi) is defined as the mass of a constituent mi divided by the volume of the mixture V + /// + /// + /// https://en.wikipedia.org/wiki/Mass_concentration_(chemistry) + /// + public partial struct MassConcentration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly MassConcentrationUnit? _unit; + + static MassConcentration() + { + BaseDimensions = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0); + + Info = new QuantityInfo(QuantityType.MassConcentration, + new UnitInfo[] { + new UnitInfo(MassConcentrationUnit.CentigramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.CentigramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.CentigramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.DecigramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.DecigramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.DecigramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.GramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.GramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.KilogramPerCubicCentimeter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.KilogramPerCubicMeter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.KilogramPerCubicMillimeter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.KilogramPerLiter, new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.KilopoundPerCubicFoot, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.KilopoundPerCubicInch, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MicrogramPerCubicMeter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MicrogramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MicrogramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MicrogramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MilligramPerCubicMeter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MilligramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MilligramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.MilligramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.NanogramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.NanogramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.NanogramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PicogramPerDeciliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PicogramPerLiter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PicogramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PoundPerCubicFoot, new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)), + new UnitInfo(MassConcentrationUnit.PoundPerCubicInch, new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)), + new UnitInfo(MassConcentrationUnit.PoundPerImperialGallon, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PoundPerUSGallon, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.SlugPerCubicFoot, new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug)), + new UnitInfo(MassConcentrationUnit.TonnePerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne)), + new UnitInfo(MassConcentrationUnit.TonnePerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne)), + new UnitInfo(MassConcentrationUnit.TonnePerCubicMillimeter, new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne)), + }, + BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// If value is NaN or Infinity. + public MassConcentration(double numericValue, MassConcentrationUnit unit) + { + if(unit == MassConcentrationUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to contruct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public MassConcentration(double numericValue, UnitSystem unitSystem) + { + if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of MassConcentration, which is KilogramPerCubicMeter. All conversions go via this value. + /// + public static MassConcentrationUnit BaseUnit { get; } = MassConcentrationUnit.KilogramPerCubicMeter; + + /// + /// Represents the largest possible value of MassConcentration + /// + public static MassConcentration MaxValue { get; } = new MassConcentration(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of MassConcentration + /// + public static MassConcentration MinValue { get; } = new MassConcentration(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.MassConcentration; + + /// + /// All units of measurement for the MassConcentration quantity. + /// + public static MassConcentrationUnit[] Units { get; } = Enum.GetValues(typeof(MassConcentrationUnit)).Cast().Except(new MassConcentrationUnit[]{ MassConcentrationUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerCubicMeter. + /// + public static MassConcentration Zero { get; } = new MassConcentration(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public MassConcentrationUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => MassConcentration.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => MassConcentration.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get MassConcentration in CentigramsPerDeciLiter. + /// + public double CentigramsPerDeciLiter => As(MassConcentrationUnit.CentigramPerDeciliter); + + /// + /// Get MassConcentration in CentigramsPerLiter. + /// + public double CentigramsPerLiter => As(MassConcentrationUnit.CentigramPerLiter); + + /// + /// Get MassConcentration in CentigramsPerMilliliter. + /// + public double CentigramsPerMilliliter => As(MassConcentrationUnit.CentigramPerMilliliter); + + /// + /// Get MassConcentration in DecigramsPerDeciLiter. + /// + public double DecigramsPerDeciLiter => As(MassConcentrationUnit.DecigramPerDeciliter); + + /// + /// Get MassConcentration in DecigramsPerLiter. + /// + public double DecigramsPerLiter => As(MassConcentrationUnit.DecigramPerLiter); + + /// + /// Get MassConcentration in DecigramsPerMilliliter. + /// + public double DecigramsPerMilliliter => As(MassConcentrationUnit.DecigramPerMilliliter); + + /// + /// Get MassConcentration in GramsPerCubicCentimeter. + /// + public double GramsPerCubicCentimeter => As(MassConcentrationUnit.GramPerCubicCentimeter); + + /// + /// Get MassConcentration in GramsPerCubicMeter. + /// + public double GramsPerCubicMeter => As(MassConcentrationUnit.GramPerCubicMeter); + + /// + /// Get MassConcentration in GramsPerCubicMillimeter. + /// + public double GramsPerCubicMillimeter => As(MassConcentrationUnit.GramPerCubicMillimeter); + + /// + /// Get MassConcentration in GramsPerDeciLiter. + /// + public double GramsPerDeciLiter => As(MassConcentrationUnit.GramPerDeciliter); + + /// + /// Get MassConcentration in GramsPerLiter. + /// + public double GramsPerLiter => As(MassConcentrationUnit.GramPerLiter); + + /// + /// Get MassConcentration in GramsPerMilliliter. + /// + public double GramsPerMilliliter => As(MassConcentrationUnit.GramPerMilliliter); + + /// + /// Get MassConcentration in KilogramsPerCubicCentimeter. + /// + public double KilogramsPerCubicCentimeter => As(MassConcentrationUnit.KilogramPerCubicCentimeter); + + /// + /// Get MassConcentration in KilogramsPerCubicMeter. + /// + public double KilogramsPerCubicMeter => As(MassConcentrationUnit.KilogramPerCubicMeter); + + /// + /// Get MassConcentration in KilogramsPerCubicMillimeter. + /// + public double KilogramsPerCubicMillimeter => As(MassConcentrationUnit.KilogramPerCubicMillimeter); + + /// + /// Get MassConcentration in KilogramsPerLiter. + /// + public double KilogramsPerLiter => As(MassConcentrationUnit.KilogramPerLiter); + + /// + /// Get MassConcentration in KilopoundsPerCubicFoot. + /// + public double KilopoundsPerCubicFoot => As(MassConcentrationUnit.KilopoundPerCubicFoot); + + /// + /// Get MassConcentration in KilopoundsPerCubicInch. + /// + public double KilopoundsPerCubicInch => As(MassConcentrationUnit.KilopoundPerCubicInch); + + /// + /// Get MassConcentration in MicrogramsPerCubicMeter. + /// + public double MicrogramsPerCubicMeter => As(MassConcentrationUnit.MicrogramPerCubicMeter); + + /// + /// Get MassConcentration in MicrogramsPerDeciLiter. + /// + public double MicrogramsPerDeciLiter => As(MassConcentrationUnit.MicrogramPerDeciliter); + + /// + /// Get MassConcentration in MicrogramsPerLiter. + /// + public double MicrogramsPerLiter => As(MassConcentrationUnit.MicrogramPerLiter); + + /// + /// Get MassConcentration in MicrogramsPerMilliliter. + /// + public double MicrogramsPerMilliliter => As(MassConcentrationUnit.MicrogramPerMilliliter); + + /// + /// Get MassConcentration in MilligramsPerCubicMeter. + /// + public double MilligramsPerCubicMeter => As(MassConcentrationUnit.MilligramPerCubicMeter); + + /// + /// Get MassConcentration in MilligramsPerDeciLiter. + /// + public double MilligramsPerDeciLiter => As(MassConcentrationUnit.MilligramPerDeciliter); + + /// + /// Get MassConcentration in MilligramsPerLiter. + /// + public double MilligramsPerLiter => As(MassConcentrationUnit.MilligramPerLiter); + + /// + /// Get MassConcentration in MilligramsPerMilliliter. + /// + public double MilligramsPerMilliliter => As(MassConcentrationUnit.MilligramPerMilliliter); + + /// + /// Get MassConcentration in NanogramsPerDeciLiter. + /// + public double NanogramsPerDeciLiter => As(MassConcentrationUnit.NanogramPerDeciliter); + + /// + /// Get MassConcentration in NanogramsPerLiter. + /// + public double NanogramsPerLiter => As(MassConcentrationUnit.NanogramPerLiter); + + /// + /// Get MassConcentration in NanogramsPerMilliliter. + /// + public double NanogramsPerMilliliter => As(MassConcentrationUnit.NanogramPerMilliliter); + + /// + /// Get MassConcentration in PicogramsPerDeciLiter. + /// + public double PicogramsPerDeciLiter => As(MassConcentrationUnit.PicogramPerDeciliter); + + /// + /// Get MassConcentration in PicogramsPerLiter. + /// + public double PicogramsPerLiter => As(MassConcentrationUnit.PicogramPerLiter); + + /// + /// Get MassConcentration in PicogramsPerMilliliter. + /// + public double PicogramsPerMilliliter => As(MassConcentrationUnit.PicogramPerMilliliter); + + /// + /// Get MassConcentration in PoundsPerCubicFoot. + /// + public double PoundsPerCubicFoot => As(MassConcentrationUnit.PoundPerCubicFoot); + + /// + /// Get MassConcentration in PoundsPerCubicInch. + /// + public double PoundsPerCubicInch => As(MassConcentrationUnit.PoundPerCubicInch); + + /// + /// Get MassConcentration in PoundsPerImperialGallon. + /// + public double PoundsPerImperialGallon => As(MassConcentrationUnit.PoundPerImperialGallon); + + /// + /// Get MassConcentration in PoundsPerUSGallon. + /// + public double PoundsPerUSGallon => As(MassConcentrationUnit.PoundPerUSGallon); + + /// + /// Get MassConcentration in SlugsPerCubicFoot. + /// + public double SlugsPerCubicFoot => As(MassConcentrationUnit.SlugPerCubicFoot); + + /// + /// Get MassConcentration in TonnesPerCubicCentimeter. + /// + public double TonnesPerCubicCentimeter => As(MassConcentrationUnit.TonnePerCubicCentimeter); + + /// + /// Get MassConcentration in TonnesPerCubicMeter. + /// + public double TonnesPerCubicMeter => As(MassConcentrationUnit.TonnePerCubicMeter); + + /// + /// Get MassConcentration in TonnesPerCubicMillimeter. + /// + public double TonnesPerCubicMillimeter => As(MassConcentrationUnit.TonnePerCubicMillimeter); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(MassConcentrationUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(MassConcentrationUnit unit, [CanBeNull] IFormatProvider provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get MassConcentration from CentigramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromCentigramsPerDeciLiter(QuantityValue centigramsperdeciliter) + { + double value = (double) centigramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.CentigramPerDeciliter); + } + /// + /// Get MassConcentration from CentigramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromCentigramsPerLiter(QuantityValue centigramsperliter) + { + double value = (double) centigramsperliter; + return new MassConcentration(value, MassConcentrationUnit.CentigramPerLiter); + } + /// + /// Get MassConcentration from CentigramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromCentigramsPerMilliliter(QuantityValue centigramspermilliliter) + { + double value = (double) centigramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.CentigramPerMilliliter); + } + /// + /// Get MassConcentration from DecigramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromDecigramsPerDeciLiter(QuantityValue decigramsperdeciliter) + { + double value = (double) decigramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.DecigramPerDeciliter); + } + /// + /// Get MassConcentration from DecigramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromDecigramsPerLiter(QuantityValue decigramsperliter) + { + double value = (double) decigramsperliter; + return new MassConcentration(value, MassConcentrationUnit.DecigramPerLiter); + } + /// + /// Get MassConcentration from DecigramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromDecigramsPerMilliliter(QuantityValue decigramspermilliliter) + { + double value = (double) decigramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.DecigramPerMilliliter); + } + /// + /// Get MassConcentration from GramsPerCubicCentimeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromGramsPerCubicCentimeter(QuantityValue gramspercubiccentimeter) + { + double value = (double) gramspercubiccentimeter; + return new MassConcentration(value, MassConcentrationUnit.GramPerCubicCentimeter); + } + /// + /// Get MassConcentration from GramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromGramsPerCubicMeter(QuantityValue gramspercubicmeter) + { + double value = (double) gramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.GramPerCubicMeter); + } + /// + /// Get MassConcentration from GramsPerCubicMillimeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromGramsPerCubicMillimeter(QuantityValue gramspercubicmillimeter) + { + double value = (double) gramspercubicmillimeter; + return new MassConcentration(value, MassConcentrationUnit.GramPerCubicMillimeter); + } + /// + /// Get MassConcentration from GramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromGramsPerDeciLiter(QuantityValue gramsperdeciliter) + { + double value = (double) gramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.GramPerDeciliter); + } + /// + /// Get MassConcentration from GramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromGramsPerLiter(QuantityValue gramsperliter) + { + double value = (double) gramsperliter; + return new MassConcentration(value, MassConcentrationUnit.GramPerLiter); + } + /// + /// Get MassConcentration from GramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromGramsPerMilliliter(QuantityValue gramspermilliliter) + { + double value = (double) gramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.GramPerMilliliter); + } + /// + /// Get MassConcentration from KilogramsPerCubicCentimeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromKilogramsPerCubicCentimeter(QuantityValue kilogramspercubiccentimeter) + { + double value = (double) kilogramspercubiccentimeter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerCubicCentimeter); + } + /// + /// Get MassConcentration from KilogramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromKilogramsPerCubicMeter(QuantityValue kilogramspercubicmeter) + { + double value = (double) kilogramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerCubicMeter); + } + /// + /// Get MassConcentration from KilogramsPerCubicMillimeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromKilogramsPerCubicMillimeter(QuantityValue kilogramspercubicmillimeter) + { + double value = (double) kilogramspercubicmillimeter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerCubicMillimeter); + } + /// + /// Get MassConcentration from KilogramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromKilogramsPerLiter(QuantityValue kilogramsperliter) + { + double value = (double) kilogramsperliter; + return new MassConcentration(value, MassConcentrationUnit.KilogramPerLiter); + } + /// + /// Get MassConcentration from KilopoundsPerCubicFoot. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromKilopoundsPerCubicFoot(QuantityValue kilopoundspercubicfoot) + { + double value = (double) kilopoundspercubicfoot; + return new MassConcentration(value, MassConcentrationUnit.KilopoundPerCubicFoot); + } + /// + /// Get MassConcentration from KilopoundsPerCubicInch. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromKilopoundsPerCubicInch(QuantityValue kilopoundspercubicinch) + { + double value = (double) kilopoundspercubicinch; + return new MassConcentration(value, MassConcentrationUnit.KilopoundPerCubicInch); + } + /// + /// Get MassConcentration from MicrogramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMicrogramsPerCubicMeter(QuantityValue microgramspercubicmeter) + { + double value = (double) microgramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerCubicMeter); + } + /// + /// Get MassConcentration from MicrogramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMicrogramsPerDeciLiter(QuantityValue microgramsperdeciliter) + { + double value = (double) microgramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerDeciliter); + } + /// + /// Get MassConcentration from MicrogramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMicrogramsPerLiter(QuantityValue microgramsperliter) + { + double value = (double) microgramsperliter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerLiter); + } + /// + /// Get MassConcentration from MicrogramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMicrogramsPerMilliliter(QuantityValue microgramspermilliliter) + { + double value = (double) microgramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.MicrogramPerMilliliter); + } + /// + /// Get MassConcentration from MilligramsPerCubicMeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMilligramsPerCubicMeter(QuantityValue milligramspercubicmeter) + { + double value = (double) milligramspercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerCubicMeter); + } + /// + /// Get MassConcentration from MilligramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMilligramsPerDeciLiter(QuantityValue milligramsperdeciliter) + { + double value = (double) milligramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerDeciliter); + } + /// + /// Get MassConcentration from MilligramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMilligramsPerLiter(QuantityValue milligramsperliter) + { + double value = (double) milligramsperliter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerLiter); + } + /// + /// Get MassConcentration from MilligramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromMilligramsPerMilliliter(QuantityValue milligramspermilliliter) + { + double value = (double) milligramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.MilligramPerMilliliter); + } + /// + /// Get MassConcentration from NanogramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromNanogramsPerDeciLiter(QuantityValue nanogramsperdeciliter) + { + double value = (double) nanogramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.NanogramPerDeciliter); + } + /// + /// Get MassConcentration from NanogramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromNanogramsPerLiter(QuantityValue nanogramsperliter) + { + double value = (double) nanogramsperliter; + return new MassConcentration(value, MassConcentrationUnit.NanogramPerLiter); + } + /// + /// Get MassConcentration from NanogramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromNanogramsPerMilliliter(QuantityValue nanogramspermilliliter) + { + double value = (double) nanogramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.NanogramPerMilliliter); + } + /// + /// Get MassConcentration from PicogramsPerDeciLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPicogramsPerDeciLiter(QuantityValue picogramsperdeciliter) + { + double value = (double) picogramsperdeciliter; + return new MassConcentration(value, MassConcentrationUnit.PicogramPerDeciliter); + } + /// + /// Get MassConcentration from PicogramsPerLiter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPicogramsPerLiter(QuantityValue picogramsperliter) + { + double value = (double) picogramsperliter; + return new MassConcentration(value, MassConcentrationUnit.PicogramPerLiter); + } + /// + /// Get MassConcentration from PicogramsPerMilliliter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPicogramsPerMilliliter(QuantityValue picogramspermilliliter) + { + double value = (double) picogramspermilliliter; + return new MassConcentration(value, MassConcentrationUnit.PicogramPerMilliliter); + } + /// + /// Get MassConcentration from PoundsPerCubicFoot. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPoundsPerCubicFoot(QuantityValue poundspercubicfoot) + { + double value = (double) poundspercubicfoot; + return new MassConcentration(value, MassConcentrationUnit.PoundPerCubicFoot); + } + /// + /// Get MassConcentration from PoundsPerCubicInch. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPoundsPerCubicInch(QuantityValue poundspercubicinch) + { + double value = (double) poundspercubicinch; + return new MassConcentration(value, MassConcentrationUnit.PoundPerCubicInch); + } + /// + /// Get MassConcentration from PoundsPerImperialGallon. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPoundsPerImperialGallon(QuantityValue poundsperimperialgallon) + { + double value = (double) poundsperimperialgallon; + return new MassConcentration(value, MassConcentrationUnit.PoundPerImperialGallon); + } + /// + /// Get MassConcentration from PoundsPerUSGallon. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromPoundsPerUSGallon(QuantityValue poundsperusgallon) + { + double value = (double) poundsperusgallon; + return new MassConcentration(value, MassConcentrationUnit.PoundPerUSGallon); + } + /// + /// Get MassConcentration from SlugsPerCubicFoot. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromSlugsPerCubicFoot(QuantityValue slugspercubicfoot) + { + double value = (double) slugspercubicfoot; + return new MassConcentration(value, MassConcentrationUnit.SlugPerCubicFoot); + } + /// + /// Get MassConcentration from TonnesPerCubicCentimeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromTonnesPerCubicCentimeter(QuantityValue tonnespercubiccentimeter) + { + double value = (double) tonnespercubiccentimeter; + return new MassConcentration(value, MassConcentrationUnit.TonnePerCubicCentimeter); + } + /// + /// Get MassConcentration from TonnesPerCubicMeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromTonnesPerCubicMeter(QuantityValue tonnespercubicmeter) + { + double value = (double) tonnespercubicmeter; + return new MassConcentration(value, MassConcentrationUnit.TonnePerCubicMeter); + } + /// + /// Get MassConcentration from TonnesPerCubicMillimeter. + /// + /// If value is NaN or Infinity. + public static MassConcentration FromTonnesPerCubicMillimeter(QuantityValue tonnespercubicmillimeter) + { + double value = (double) tonnespercubicmillimeter; + return new MassConcentration(value, MassConcentrationUnit.TonnePerCubicMillimeter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassConcentration unit value. + public static MassConcentration From(QuantityValue value, MassConcentrationUnit fromUnit) + { + return new MassConcentration((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static MassConcentration Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static MassConcentration Parse(string str, [CanBeNull] IFormatProvider provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out MassConcentration result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassConcentration result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassConcentrationUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Format to use when parsing number and unit. Defaults to if null. + public static MassConcentrationUnit ParseUnit(string str, IFormatProvider provider = null) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out MassConcentrationUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider provider, out MassConcentrationUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static MassConcentration operator -(MassConcentration right) + { + return new MassConcentration(-right.Value, right.Unit); + } + + /// Get from adding two . + public static MassConcentration operator +(MassConcentration left, MassConcentration right) + { + return new MassConcentration(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static MassConcentration operator -(MassConcentration left, MassConcentration right) + { + return new MassConcentration(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static MassConcentration operator *(double left, MassConcentration right) + { + return new MassConcentration(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static MassConcentration operator *(MassConcentration left, double right) + { + return new MassConcentration(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static MassConcentration operator /(MassConcentration left, double right) + { + return new MassConcentration(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(MassConcentration left, MassConcentration right) + { + return left.KilogramsPerCubicMeter / right.KilogramsPerCubicMeter; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(MassConcentration left, MassConcentration right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(MassConcentration left, MassConcentration right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(MassConcentration left, MassConcentration right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(MassConcentration left, MassConcentration right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(MassConcentration left, MassConcentration right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(MassConcentration left, MassConcentration right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is MassConcentration objMassConcentration)) throw new ArgumentException("Expected type MassConcentration.", nameof(obj)); + + return CompareTo(objMassConcentration); + } + + /// + public int CompareTo(MassConcentration other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if(obj is null || !(obj is MassConcentration objMassConcentration)) + return false; + + return Equals(objMassConcentration); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(MassConcentration other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another MassConcentration within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(MassConcentration other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current MassConcentration. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(MassConcentrationUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassConcentrationUnit unitAsMassConcentrationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassConcentrationUnit)} is supported.", nameof(unit)); + + return As(unitAsMassConcentrationUnit); + } + + /// + /// Converts this MassConcentration to another MassConcentration with the unit representation . + /// + /// A MassConcentration with the specified unit. + public MassConcentration ToUnit(MassConcentrationUnit unit) + { + var convertedValue = GetValueAs(unit); + return new MassConcentration(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MassConcentrationUnit unitAsMassConcentrationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassConcentrationUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsMassConcentrationUnit); + } + + /// + public MassConcentration ToUnit(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(MassConcentrationUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case MassConcentrationUnit.CentigramPerDeciliter: return (_value/1e-1) * 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (_value/1) * 1e-2d; + case MassConcentrationUnit.CentigramPerMilliliter: return (_value/1e-3) * 1e-2d; + case MassConcentrationUnit.DecigramPerDeciliter: return (_value/1e-1) * 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (_value/1) * 1e-1d; + case MassConcentrationUnit.DecigramPerMilliliter: return (_value/1e-3) * 1e-1d; + case MassConcentrationUnit.GramPerCubicCentimeter: return _value/1e-3; + case MassConcentrationUnit.GramPerCubicMeter: return _value/1e3; + case MassConcentrationUnit.GramPerCubicMillimeter: return _value/1e-6; + case MassConcentrationUnit.GramPerDeciliter: return _value/1e-1; + case MassConcentrationUnit.GramPerLiter: return _value/1; + case MassConcentrationUnit.GramPerMilliliter: return _value/1e-3; + case MassConcentrationUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d; + case MassConcentrationUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d; + case MassConcentrationUnit.KilogramPerCubicMillimeter: return (_value/1e-6) * 1e3d; + case MassConcentrationUnit.KilogramPerLiter: return _value*1e3; + case MassConcentrationUnit.KilopoundPerCubicFoot: return (_value/0.062427961) * 1e3d; + case MassConcentrationUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d; + case MassConcentrationUnit.MicrogramPerCubicMeter: return (_value/1e3) * 1e-6d; + case MassConcentrationUnit.MicrogramPerDeciliter: return (_value/1e-1) * 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (_value/1) * 1e-6d; + case MassConcentrationUnit.MicrogramPerMilliliter: return (_value/1e-3) * 1e-6d; + case MassConcentrationUnit.MilligramPerCubicMeter: return (_value/1e3) * 1e-3d; + case MassConcentrationUnit.MilligramPerDeciliter: return (_value/1e-1) * 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (_value/1) * 1e-3d; + case MassConcentrationUnit.MilligramPerMilliliter: return (_value/1e-3) * 1e-3d; + case MassConcentrationUnit.NanogramPerDeciliter: return (_value/1e-1) * 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (_value/1) * 1e-9d; + case MassConcentrationUnit.NanogramPerMilliliter: return (_value/1e-3) * 1e-9d; + case MassConcentrationUnit.PicogramPerDeciliter: return (_value/1e-1) * 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (_value/1) * 1e-12d; + case MassConcentrationUnit.PicogramPerMilliliter: return (_value/1e-3) * 1e-12d; + case MassConcentrationUnit.PoundPerCubicFoot: return _value/0.062427961; + case MassConcentrationUnit.PoundPerCubicInch: return _value/3.6127298147753e-5; + case MassConcentrationUnit.PoundPerImperialGallon: return _value*9.9776398e1; + case MassConcentrationUnit.PoundPerUSGallon: return _value*1.19826427e2; + case MassConcentrationUnit.SlugPerCubicFoot: return _value*515.378818; + case MassConcentrationUnit.TonnePerCubicCentimeter: return _value/1e-9; + case MassConcentrationUnit.TonnePerCubicMeter: return _value/0.001; + case MassConcentrationUnit.TonnePerCubicMillimeter: return _value/1e-12; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double GetValueAs(MassConcentrationUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case MassConcentrationUnit.CentigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (baseUnitValue*1) / 1e-2d; + case MassConcentrationUnit.CentigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-2d; + case MassConcentrationUnit.DecigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (baseUnitValue*1) / 1e-1d; + case MassConcentrationUnit.DecigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-1d; + case MassConcentrationUnit.GramPerCubicCentimeter: return baseUnitValue*1e-3; + case MassConcentrationUnit.GramPerCubicMeter: return baseUnitValue*1e3; + case MassConcentrationUnit.GramPerCubicMillimeter: return baseUnitValue*1e-6; + case MassConcentrationUnit.GramPerDeciliter: return baseUnitValue*1e-1; + case MassConcentrationUnit.GramPerLiter: return baseUnitValue*1; + case MassConcentrationUnit.GramPerMilliliter: return baseUnitValue*1e-3; + case MassConcentrationUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d; + case MassConcentrationUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d; + case MassConcentrationUnit.KilogramPerCubicMillimeter: return (baseUnitValue*1e-6) / 1e3d; + case MassConcentrationUnit.KilogramPerLiter: return baseUnitValue/1e3; + case MassConcentrationUnit.KilopoundPerCubicFoot: return (baseUnitValue*0.062427961) / 1e3d; + case MassConcentrationUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d; + case MassConcentrationUnit.MicrogramPerCubicMeter: return (baseUnitValue*1e3) / 1e-6d; + case MassConcentrationUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (baseUnitValue*1) / 1e-6d; + case MassConcentrationUnit.MicrogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-6d; + case MassConcentrationUnit.MilligramPerCubicMeter: return (baseUnitValue*1e3) / 1e-3d; + case MassConcentrationUnit.MilligramPerDeciliter: return (baseUnitValue*1e-1) / 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (baseUnitValue*1) / 1e-3d; + case MassConcentrationUnit.MilligramPerMilliliter: return (baseUnitValue*1e-3) / 1e-3d; + case MassConcentrationUnit.NanogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (baseUnitValue*1) / 1e-9d; + case MassConcentrationUnit.NanogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-9d; + case MassConcentrationUnit.PicogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (baseUnitValue*1) / 1e-12d; + case MassConcentrationUnit.PicogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-12d; + case MassConcentrationUnit.PoundPerCubicFoot: return baseUnitValue*0.062427961; + case MassConcentrationUnit.PoundPerCubicInch: return baseUnitValue*3.6127298147753e-5; + case MassConcentrationUnit.PoundPerImperialGallon: return baseUnitValue/9.9776398e1; + case MassConcentrationUnit.PoundPerUSGallon: return baseUnitValue/1.19826427e2; + case MassConcentrationUnit.SlugPerCubicFoot: return baseUnitValue*0.00194032033; + case MassConcentrationUnit.TonnePerCubicCentimeter: return baseUnitValue*1e-9; + case MassConcentrationUnit.TonnePerCubicMeter: return baseUnitValue*0.001; + case MassConcentrationUnit.TonnePerCubicMillimeter: return baseUnitValue*1e-12; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] IFormatProvider provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider formatProvider) + { + return QuantityFormatter.Format(this, format, formatProvider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(MassConcentration)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(MassConcentration)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(MassConcentration)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if(conversionType == typeof(MassConcentration)) + return this; + else if(conversionType == typeof(MassConcentrationUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return MassConcentration.QuantityType; + else if(conversionType == typeof(BaseDimensions)) + return MassConcentration.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(MassConcentration)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs new file mode 100644 index 0000000000..0dc431006f --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs @@ -0,0 +1,1233 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// The mass fraction is defined as the mass of a constituent divided by the total mass of the mixture. + /// + /// + /// https://en.wikipedia.org/wiki/Mass_fraction_(chemistry) + /// + public partial struct MassFraction : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly MassFractionUnit? _unit; + + static MassFraction() + { + BaseDimensions = BaseDimensions.Dimensionless; + + Info = new QuantityInfo(QuantityType.MassFraction, + new UnitInfo[] { + new UnitInfo(MassFractionUnit.CentigramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.CentigramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecagramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecagramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecigramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecigramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecimalFraction, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.GramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.GramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.HectogramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.HectogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.KilogramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.KilogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.MicrogramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.MicrogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.MilligramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.MilligramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.NanogramPerGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.NanogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.PartPerBillion, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.PartPerMillion, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.PartPerThousand, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.PartPerTrillion, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.Percent, BaseUnits.Undefined), + }, + BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// If value is NaN or Infinity. + public MassFraction(double numericValue, MassFractionUnit unit) + { + if(unit == MassFractionUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to contruct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public MassFraction(double numericValue, UnitSystem unitSystem) + { + if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of MassFraction, which is DecimalFraction. All conversions go via this value. + /// + public static MassFractionUnit BaseUnit { get; } = MassFractionUnit.DecimalFraction; + + /// + /// Represents the largest possible value of MassFraction + /// + public static MassFraction MaxValue { get; } = new MassFraction(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of MassFraction + /// + public static MassFraction MinValue { get; } = new MassFraction(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.MassFraction; + + /// + /// All units of measurement for the MassFraction quantity. + /// + public static MassFractionUnit[] Units { get; } = Enum.GetValues(typeof(MassFractionUnit)).Cast().Except(new MassFractionUnit[]{ MassFractionUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. + /// + public static MassFraction Zero { get; } = new MassFraction(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public MassFractionUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => MassFraction.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => MassFraction.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get MassFraction in CentigramsPerGram. + /// + public double CentigramsPerGram => As(MassFractionUnit.CentigramPerGram); + + /// + /// Get MassFraction in CentigramsPerKiloGram. + /// + public double CentigramsPerKiloGram => As(MassFractionUnit.CentigramPerKiloGram); + + /// + /// Get MassFraction in DecagramsPerGram. + /// + public double DecagramsPerGram => As(MassFractionUnit.DecagramPerGram); + + /// + /// Get MassFraction in DecagramsPerKiloGram. + /// + public double DecagramsPerKiloGram => As(MassFractionUnit.DecagramPerKiloGram); + + /// + /// Get MassFraction in DecigramsPerGram. + /// + public double DecigramsPerGram => As(MassFractionUnit.DecigramPerGram); + + /// + /// Get MassFraction in DecigramsPerKiloGram. + /// + public double DecigramsPerKiloGram => As(MassFractionUnit.DecigramPerKiloGram); + + /// + /// Get MassFraction in DecimalFractions. + /// + public double DecimalFractions => As(MassFractionUnit.DecimalFraction); + + /// + /// Get MassFraction in GramsPerGram. + /// + public double GramsPerGram => As(MassFractionUnit.GramPerGram); + + /// + /// Get MassFraction in GramsPerKiloGram. + /// + public double GramsPerKiloGram => As(MassFractionUnit.GramPerKiloGram); + + /// + /// Get MassFraction in HectogramsPerGram. + /// + public double HectogramsPerGram => As(MassFractionUnit.HectogramPerGram); + + /// + /// Get MassFraction in HectogramsPerKiloGram. + /// + public double HectogramsPerKiloGram => As(MassFractionUnit.HectogramPerKiloGram); + + /// + /// Get MassFraction in KilogramsPerGram. + /// + public double KilogramsPerGram => As(MassFractionUnit.KilogramPerGram); + + /// + /// Get MassFraction in KilogramsPerKiloGram. + /// + public double KilogramsPerKiloGram => As(MassFractionUnit.KilogramPerKiloGram); + + /// + /// Get MassFraction in MicrogramsPerGram. + /// + public double MicrogramsPerGram => As(MassFractionUnit.MicrogramPerGram); + + /// + /// Get MassFraction in MicrogramsPerKiloGram. + /// + public double MicrogramsPerKiloGram => As(MassFractionUnit.MicrogramPerKiloGram); + + /// + /// Get MassFraction in MilligramsPerGram. + /// + public double MilligramsPerGram => As(MassFractionUnit.MilligramPerGram); + + /// + /// Get MassFraction in MilligramsPerKiloGram. + /// + public double MilligramsPerKiloGram => As(MassFractionUnit.MilligramPerKiloGram); + + /// + /// Get MassFraction in NanogramsPerGram. + /// + public double NanogramsPerGram => As(MassFractionUnit.NanogramPerGram); + + /// + /// Get MassFraction in NanogramsPerKiloGram. + /// + public double NanogramsPerKiloGram => As(MassFractionUnit.NanogramPerKiloGram); + + /// + /// Get MassFraction in PartsPerBillion. + /// + public double PartsPerBillion => As(MassFractionUnit.PartPerBillion); + + /// + /// Get MassFraction in PartsPerMillion. + /// + public double PartsPerMillion => As(MassFractionUnit.PartPerMillion); + + /// + /// Get MassFraction in PartsPerThousand. + /// + public double PartsPerThousand => As(MassFractionUnit.PartPerThousand); + + /// + /// Get MassFraction in PartsPerTrillion. + /// + public double PartsPerTrillion => As(MassFractionUnit.PartPerTrillion); + + /// + /// Get MassFraction in Percent. + /// + public double Percent => As(MassFractionUnit.Percent); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(MassFractionUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(MassFractionUnit unit, [CanBeNull] IFormatProvider provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get MassFraction from CentigramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromCentigramsPerGram(QuantityValue centigramspergram) + { + double value = (double) centigramspergram; + return new MassFraction(value, MassFractionUnit.CentigramPerGram); + } + /// + /// Get MassFraction from CentigramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromCentigramsPerKiloGram(QuantityValue centigramsperkilogram) + { + double value = (double) centigramsperkilogram; + return new MassFraction(value, MassFractionUnit.CentigramPerKiloGram); + } + /// + /// Get MassFraction from DecagramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromDecagramsPerGram(QuantityValue decagramspergram) + { + double value = (double) decagramspergram; + return new MassFraction(value, MassFractionUnit.DecagramPerGram); + } + /// + /// Get MassFraction from DecagramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromDecagramsPerKiloGram(QuantityValue decagramsperkilogram) + { + double value = (double) decagramsperkilogram; + return new MassFraction(value, MassFractionUnit.DecagramPerKiloGram); + } + /// + /// Get MassFraction from DecigramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromDecigramsPerGram(QuantityValue decigramspergram) + { + double value = (double) decigramspergram; + return new MassFraction(value, MassFractionUnit.DecigramPerGram); + } + /// + /// Get MassFraction from DecigramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromDecigramsPerKiloGram(QuantityValue decigramsperkilogram) + { + double value = (double) decigramsperkilogram; + return new MassFraction(value, MassFractionUnit.DecigramPerKiloGram); + } + /// + /// Get MassFraction from DecimalFractions. + /// + /// If value is NaN or Infinity. + public static MassFraction FromDecimalFractions(QuantityValue decimalfractions) + { + double value = (double) decimalfractions; + return new MassFraction(value, MassFractionUnit.DecimalFraction); + } + /// + /// Get MassFraction from GramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromGramsPerGram(QuantityValue gramspergram) + { + double value = (double) gramspergram; + return new MassFraction(value, MassFractionUnit.GramPerGram); + } + /// + /// Get MassFraction from GramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromGramsPerKiloGram(QuantityValue gramsperkilogram) + { + double value = (double) gramsperkilogram; + return new MassFraction(value, MassFractionUnit.GramPerKiloGram); + } + /// + /// Get MassFraction from HectogramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromHectogramsPerGram(QuantityValue hectogramspergram) + { + double value = (double) hectogramspergram; + return new MassFraction(value, MassFractionUnit.HectogramPerGram); + } + /// + /// Get MassFraction from HectogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromHectogramsPerKiloGram(QuantityValue hectogramsperkilogram) + { + double value = (double) hectogramsperkilogram; + return new MassFraction(value, MassFractionUnit.HectogramPerKiloGram); + } + /// + /// Get MassFraction from KilogramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromKilogramsPerGram(QuantityValue kilogramspergram) + { + double value = (double) kilogramspergram; + return new MassFraction(value, MassFractionUnit.KilogramPerGram); + } + /// + /// Get MassFraction from KilogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromKilogramsPerKiloGram(QuantityValue kilogramsperkilogram) + { + double value = (double) kilogramsperkilogram; + return new MassFraction(value, MassFractionUnit.KilogramPerKiloGram); + } + /// + /// Get MassFraction from MicrogramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromMicrogramsPerGram(QuantityValue microgramspergram) + { + double value = (double) microgramspergram; + return new MassFraction(value, MassFractionUnit.MicrogramPerGram); + } + /// + /// Get MassFraction from MicrogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromMicrogramsPerKiloGram(QuantityValue microgramsperkilogram) + { + double value = (double) microgramsperkilogram; + return new MassFraction(value, MassFractionUnit.MicrogramPerKiloGram); + } + /// + /// Get MassFraction from MilligramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromMilligramsPerGram(QuantityValue milligramspergram) + { + double value = (double) milligramspergram; + return new MassFraction(value, MassFractionUnit.MilligramPerGram); + } + /// + /// Get MassFraction from MilligramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromMilligramsPerKiloGram(QuantityValue milligramsperkilogram) + { + double value = (double) milligramsperkilogram; + return new MassFraction(value, MassFractionUnit.MilligramPerKiloGram); + } + /// + /// Get MassFraction from NanogramsPerGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromNanogramsPerGram(QuantityValue nanogramspergram) + { + double value = (double) nanogramspergram; + return new MassFraction(value, MassFractionUnit.NanogramPerGram); + } + /// + /// Get MassFraction from NanogramsPerKiloGram. + /// + /// If value is NaN or Infinity. + public static MassFraction FromNanogramsPerKiloGram(QuantityValue nanogramsperkilogram) + { + double value = (double) nanogramsperkilogram; + return new MassFraction(value, MassFractionUnit.NanogramPerKiloGram); + } + /// + /// Get MassFraction from PartsPerBillion. + /// + /// If value is NaN or Infinity. + public static MassFraction FromPartsPerBillion(QuantityValue partsperbillion) + { + double value = (double) partsperbillion; + return new MassFraction(value, MassFractionUnit.PartPerBillion); + } + /// + /// Get MassFraction from PartsPerMillion. + /// + /// If value is NaN or Infinity. + public static MassFraction FromPartsPerMillion(QuantityValue partspermillion) + { + double value = (double) partspermillion; + return new MassFraction(value, MassFractionUnit.PartPerMillion); + } + /// + /// Get MassFraction from PartsPerThousand. + /// + /// If value is NaN or Infinity. + public static MassFraction FromPartsPerThousand(QuantityValue partsperthousand) + { + double value = (double) partsperthousand; + return new MassFraction(value, MassFractionUnit.PartPerThousand); + } + /// + /// Get MassFraction from PartsPerTrillion. + /// + /// If value is NaN or Infinity. + public static MassFraction FromPartsPerTrillion(QuantityValue partspertrillion) + { + double value = (double) partspertrillion; + return new MassFraction(value, MassFractionUnit.PartPerTrillion); + } + /// + /// Get MassFraction from Percent. + /// + /// If value is NaN or Infinity. + public static MassFraction FromPercent(QuantityValue percent) + { + double value = (double) percent; + return new MassFraction(value, MassFractionUnit.Percent); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassFraction unit value. + public static MassFraction From(QuantityValue value, MassFractionUnit fromUnit) + { + return new MassFraction((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static MassFraction Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static MassFraction Parse(string str, [CanBeNull] IFormatProvider provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out MassFraction result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out MassFraction result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassFractionUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Format to use when parsing number and unit. Defaults to if null. + public static MassFractionUnit ParseUnit(string str, IFormatProvider provider = null) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out MassFractionUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider provider, out MassFractionUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static MassFraction operator -(MassFraction right) + { + return new MassFraction(-right.Value, right.Unit); + } + + /// Get from adding two . + public static MassFraction operator +(MassFraction left, MassFraction right) + { + return new MassFraction(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static MassFraction operator -(MassFraction left, MassFraction right) + { + return new MassFraction(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static MassFraction operator *(double left, MassFraction right) + { + return new MassFraction(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static MassFraction operator *(MassFraction left, double right) + { + return new MassFraction(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static MassFraction operator /(MassFraction left, double right) + { + return new MassFraction(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(MassFraction left, MassFraction right) + { + return left.DecimalFractions / right.DecimalFractions; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(MassFraction left, MassFraction right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(MassFraction left, MassFraction right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(MassFraction left, MassFraction right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(MassFraction left, MassFraction right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(MassFraction left, MassFraction right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(MassFraction left, MassFraction right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is MassFraction objMassFraction)) throw new ArgumentException("Expected type MassFraction.", nameof(obj)); + + return CompareTo(objMassFraction); + } + + /// + public int CompareTo(MassFraction other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if(obj is null || !(obj is MassFraction objMassFraction)) + return false; + + return Equals(objMassFraction); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(MassFraction other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another MassFraction within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(MassFraction other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current MassFraction. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(MassFractionUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassFractionUnit unitAsMassFractionUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFractionUnit)} is supported.", nameof(unit)); + + return As(unitAsMassFractionUnit); + } + + /// + /// Converts this MassFraction to another MassFraction with the unit representation . + /// + /// A MassFraction with the specified unit. + public MassFraction ToUnit(MassFractionUnit unit) + { + var convertedValue = GetValueAs(unit); + return new MassFraction(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MassFractionUnit unitAsMassFractionUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFractionUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsMassFractionUnit); + } + + /// + public MassFraction ToUnit(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(MassFractionUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case MassFractionUnit.CentigramPerGram: return (_value) * 1e-2d; + case MassFractionUnit.CentigramPerKiloGram: return (_value/1e3) * 1e-2d; + case MassFractionUnit.DecagramPerGram: return (_value) * 1e1d; + case MassFractionUnit.DecagramPerKiloGram: return (_value/1e3) * 1e1d; + case MassFractionUnit.DecigramPerGram: return (_value) * 1e-1d; + case MassFractionUnit.DecigramPerKiloGram: return (_value/1e3) * 1e-1d; + case MassFractionUnit.DecimalFraction: return _value; + case MassFractionUnit.GramPerGram: return _value; + case MassFractionUnit.GramPerKiloGram: return _value/1e3; + case MassFractionUnit.HectogramPerGram: return (_value) * 1e2d; + case MassFractionUnit.HectogramPerKiloGram: return (_value/1e3) * 1e2d; + case MassFractionUnit.KilogramPerGram: return (_value) * 1e3d; + case MassFractionUnit.KilogramPerKiloGram: return (_value/1e3) * 1e3d; + case MassFractionUnit.MicrogramPerGram: return (_value) * 1e-6d; + case MassFractionUnit.MicrogramPerKiloGram: return (_value/1e3) * 1e-6d; + case MassFractionUnit.MilligramPerGram: return (_value) * 1e-3d; + case MassFractionUnit.MilligramPerKiloGram: return (_value/1e3) * 1e-3d; + case MassFractionUnit.NanogramPerGram: return (_value) * 1e-9d; + case MassFractionUnit.NanogramPerKiloGram: return (_value/1e3) * 1e-9d; + case MassFractionUnit.PartPerBillion: return _value/1e9; + case MassFractionUnit.PartPerMillion: return _value/1e6; + case MassFractionUnit.PartPerThousand: return _value/1e3; + case MassFractionUnit.PartPerTrillion: return _value/1e12; + case MassFractionUnit.Percent: return _value/1e2; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double GetValueAs(MassFractionUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case MassFractionUnit.CentigramPerGram: return (baseUnitValue) / 1e-2d; + case MassFractionUnit.CentigramPerKiloGram: return (baseUnitValue*1e3) / 1e-2d; + case MassFractionUnit.DecagramPerGram: return (baseUnitValue) / 1e1d; + case MassFractionUnit.DecagramPerKiloGram: return (baseUnitValue*1e3) / 1e1d; + case MassFractionUnit.DecigramPerGram: return (baseUnitValue) / 1e-1d; + case MassFractionUnit.DecigramPerKiloGram: return (baseUnitValue*1e3) / 1e-1d; + case MassFractionUnit.DecimalFraction: return baseUnitValue; + case MassFractionUnit.GramPerGram: return baseUnitValue; + case MassFractionUnit.GramPerKiloGram: return baseUnitValue*1e3; + case MassFractionUnit.HectogramPerGram: return (baseUnitValue) / 1e2d; + case MassFractionUnit.HectogramPerKiloGram: return (baseUnitValue*1e3) / 1e2d; + case MassFractionUnit.KilogramPerGram: return (baseUnitValue) / 1e3d; + case MassFractionUnit.KilogramPerKiloGram: return (baseUnitValue*1e3) / 1e3d; + case MassFractionUnit.MicrogramPerGram: return (baseUnitValue) / 1e-6d; + case MassFractionUnit.MicrogramPerKiloGram: return (baseUnitValue*1e3) / 1e-6d; + case MassFractionUnit.MilligramPerGram: return (baseUnitValue) / 1e-3d; + case MassFractionUnit.MilligramPerKiloGram: return (baseUnitValue*1e3) / 1e-3d; + case MassFractionUnit.NanogramPerGram: return (baseUnitValue) / 1e-9d; + case MassFractionUnit.NanogramPerKiloGram: return (baseUnitValue*1e3) / 1e-9d; + case MassFractionUnit.PartPerBillion: return baseUnitValue*1e9; + case MassFractionUnit.PartPerMillion: return baseUnitValue*1e6; + case MassFractionUnit.PartPerThousand: return baseUnitValue*1e3; + case MassFractionUnit.PartPerTrillion: return baseUnitValue*1e12; + case MassFractionUnit.Percent: return baseUnitValue*1e2; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] IFormatProvider provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider formatProvider) + { + return QuantityFormatter.Format(this, format, formatProvider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(MassFraction)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(MassFraction)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(MassFraction)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if(conversionType == typeof(MassFraction)) + return this; + else if(conversionType == typeof(MassFractionUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return MassFraction.QuantityType; + else if(conversionType == typeof(BaseDimensions)) + return MassFraction.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(MassFraction)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs index 88aab15de4..3b1d3c2129 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs @@ -55,11 +55,16 @@ static Molarity() new UnitInfo[] { new UnitInfo(MolarityUnit.CentimolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.DecimolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.Micromolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MicromolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.Millimolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MillimolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.Molar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MolesPerCubicMeter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.Nanomolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.NanomolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.Picomolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.PicomolesPerLiter, BaseUnits.Undefined), }, BaseUnit, Zero, BaseDimensions); @@ -183,16 +188,31 @@ public Molarity(double numericValue, UnitSystem unitSystem) /// public double DecimolesPerLiter => As(MolarityUnit.DecimolesPerLiter); + /// + /// Get Molarity in Micromolar. + /// + public double Micromolar => As(MolarityUnit.Micromolar); + /// /// Get Molarity in MicromolesPerLiter. /// public double MicromolesPerLiter => As(MolarityUnit.MicromolesPerLiter); + /// + /// Get Molarity in Millimolar. + /// + public double Millimolar => As(MolarityUnit.Millimolar); + /// /// Get Molarity in MillimolesPerLiter. /// public double MillimolesPerLiter => As(MolarityUnit.MillimolesPerLiter); + /// + /// Get Molarity in Molar. + /// + public double Molar => As(MolarityUnit.Molar); + /// /// Get Molarity in MolesPerCubicMeter. /// @@ -203,11 +223,21 @@ public Molarity(double numericValue, UnitSystem unitSystem) /// public double MolesPerLiter => As(MolarityUnit.MolesPerLiter); + /// + /// Get Molarity in Nanomolar. + /// + public double Nanomolar => As(MolarityUnit.Nanomolar); + /// /// Get Molarity in NanomolesPerLiter. /// public double NanomolesPerLiter => As(MolarityUnit.NanomolesPerLiter); + /// + /// Get Molarity in Picomolar. + /// + public double Picomolar => As(MolarityUnit.Picomolar); + /// /// Get Molarity in PicomolesPerLiter. /// @@ -261,6 +291,15 @@ public static Molarity FromDecimolesPerLiter(QuantityValue decimolesperliter) return new Molarity(value, MolarityUnit.DecimolesPerLiter); } /// + /// Get Molarity from Micromolar. + /// + /// If value is NaN or Infinity. + public static Molarity FromMicromolar(QuantityValue micromolar) + { + double value = (double) micromolar; + return new Molarity(value, MolarityUnit.Micromolar); + } + /// /// Get Molarity from MicromolesPerLiter. /// /// If value is NaN or Infinity. @@ -270,6 +309,15 @@ public static Molarity FromMicromolesPerLiter(QuantityValue micromolesperliter) return new Molarity(value, MolarityUnit.MicromolesPerLiter); } /// + /// Get Molarity from Millimolar. + /// + /// If value is NaN or Infinity. + public static Molarity FromMillimolar(QuantityValue millimolar) + { + double value = (double) millimolar; + return new Molarity(value, MolarityUnit.Millimolar); + } + /// /// Get Molarity from MillimolesPerLiter. /// /// If value is NaN or Infinity. @@ -279,6 +327,15 @@ public static Molarity FromMillimolesPerLiter(QuantityValue millimolesperliter) return new Molarity(value, MolarityUnit.MillimolesPerLiter); } /// + /// Get Molarity from Molar. + /// + /// If value is NaN or Infinity. + public static Molarity FromMolar(QuantityValue molar) + { + double value = (double) molar; + return new Molarity(value, MolarityUnit.Molar); + } + /// /// Get Molarity from MolesPerCubicMeter. /// /// If value is NaN or Infinity. @@ -297,6 +354,15 @@ public static Molarity FromMolesPerLiter(QuantityValue molesperliter) return new Molarity(value, MolarityUnit.MolesPerLiter); } /// + /// Get Molarity from Nanomolar. + /// + /// If value is NaN or Infinity. + public static Molarity FromNanomolar(QuantityValue nanomolar) + { + double value = (double) nanomolar; + return new Molarity(value, MolarityUnit.Nanomolar); + } + /// /// Get Molarity from NanomolesPerLiter. /// /// If value is NaN or Infinity. @@ -306,6 +372,15 @@ public static Molarity FromNanomolesPerLiter(QuantityValue nanomolesperliter) return new Molarity(value, MolarityUnit.NanomolesPerLiter); } /// + /// Get Molarity from Picomolar. + /// + /// If value is NaN or Infinity. + public static Molarity FromPicomolar(QuantityValue picomolar) + { + double value = (double) picomolar; + return new Molarity(value, MolarityUnit.Picomolar); + } + /// /// Get Molarity from PicomolesPerLiter. /// /// If value is NaN or Infinity. @@ -745,11 +820,16 @@ private double GetValueInBaseUnit() { case MolarityUnit.CentimolesPerLiter: return (_value/1e-3) * 1e-2d; case MolarityUnit.DecimolesPerLiter: return (_value/1e-3) * 1e-1d; + case MolarityUnit.Micromolar: return (_value/1e-3) * 1e-6d; case MolarityUnit.MicromolesPerLiter: return (_value/1e-3) * 1e-6d; + case MolarityUnit.Millimolar: return (_value/1e-3) * 1e-3d; case MolarityUnit.MillimolesPerLiter: return (_value/1e-3) * 1e-3d; + case MolarityUnit.Molar: return _value/1e-3; case MolarityUnit.MolesPerCubicMeter: return _value; case MolarityUnit.MolesPerLiter: return _value/1e-3; + case MolarityUnit.Nanomolar: return (_value/1e-3) * 1e-9d; case MolarityUnit.NanomolesPerLiter: return (_value/1e-3) * 1e-9d; + case MolarityUnit.Picomolar: return (_value/1e-3) * 1e-12d; case MolarityUnit.PicomolesPerLiter: return (_value/1e-3) * 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to base units."); @@ -767,11 +847,16 @@ private double GetValueAs(MolarityUnit unit) { case MolarityUnit.CentimolesPerLiter: return (baseUnitValue*1e-3) / 1e-2d; case MolarityUnit.DecimolesPerLiter: return (baseUnitValue*1e-3) / 1e-1d; + case MolarityUnit.Micromolar: return (baseUnitValue*1e-3) / 1e-6d; case MolarityUnit.MicromolesPerLiter: return (baseUnitValue*1e-3) / 1e-6d; + case MolarityUnit.Millimolar: return (baseUnitValue*1e-3) / 1e-3d; case MolarityUnit.MillimolesPerLiter: return (baseUnitValue*1e-3) / 1e-3d; + case MolarityUnit.Molar: return baseUnitValue*1e-3; case MolarityUnit.MolesPerCubicMeter: return baseUnitValue; case MolarityUnit.MolesPerLiter: return baseUnitValue*1e-3; + case MolarityUnit.Nanomolar: return (baseUnitValue*1e-3) / 1e-9d; case MolarityUnit.NanomolesPerLiter: return (baseUnitValue*1e-3) / 1e-9d; + case MolarityUnit.Picomolar: return (baseUnitValue*1e-3) / 1e-12d; case MolarityUnit.PicomolesPerLiter: return (baseUnitValue*1e-3) / 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.NetFramework.g.cs new file mode 100644 index 0000000000..a355ef6fce --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.NetFramework.g.cs @@ -0,0 +1,1165 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// The volume concentration (not to be confused with volume fraction) is defined as the volume of a constituent divided by the total volume of the mixture. + /// + /// + /// https://en.wikipedia.org/wiki/Concentration#Volume_concentration + /// + public partial struct VolumeConcentration : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly VolumeConcentrationUnit? _unit; + + static VolumeConcentration() + { + BaseDimensions = BaseDimensions.Dimensionless; + + Info = new QuantityInfo(QuantityType.VolumeConcentration, + new UnitInfo[] { + new UnitInfo(VolumeConcentrationUnit.CentilitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.CentilitersPerMililiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.DecilitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.DecilitersPerMililiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.DecimalFraction, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.LitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.LitersPerMililiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.MicrolitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.MicrolitersPerMililiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.MillilitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.MillilitersPerMililiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.NanolitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.NanolitersPerMililiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.PartPerBillion, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.PartPerMillion, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.PartPerThousand, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.PartPerTrillion, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.Percent, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.PicolitersPerLiter, BaseUnits.Undefined), + new UnitInfo(VolumeConcentrationUnit.PicolitersPerMililiter, BaseUnits.Undefined), + }, + BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// If value is NaN or Infinity. + public VolumeConcentration(double numericValue, VolumeConcentrationUnit unit) + { + if(unit == VolumeConcentrationUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to contruct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public VolumeConcentration(double numericValue, UnitSystem unitSystem) + { + if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of VolumeConcentration, which is DecimalFraction. All conversions go via this value. + /// + public static VolumeConcentrationUnit BaseUnit { get; } = VolumeConcentrationUnit.DecimalFraction; + + /// + /// Represents the largest possible value of VolumeConcentration + /// + public static VolumeConcentration MaxValue { get; } = new VolumeConcentration(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of VolumeConcentration + /// + public static VolumeConcentration MinValue { get; } = new VolumeConcentration(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.VolumeConcentration; + + /// + /// All units of measurement for the VolumeConcentration quantity. + /// + public static VolumeConcentrationUnit[] Units { get; } = Enum.GetValues(typeof(VolumeConcentrationUnit)).Cast().Except(new VolumeConcentrationUnit[]{ VolumeConcentrationUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. + /// + public static VolumeConcentration Zero { get; } = new VolumeConcentration(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public VolumeConcentrationUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => VolumeConcentration.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => VolumeConcentration.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get VolumeConcentration in CentilitersPerLiter. + /// + public double CentilitersPerLiter => As(VolumeConcentrationUnit.CentilitersPerLiter); + + /// + /// Get VolumeConcentration in CentilitersPerMililiter. + /// + public double CentilitersPerMililiter => As(VolumeConcentrationUnit.CentilitersPerMililiter); + + /// + /// Get VolumeConcentration in DecilitersPerLiter. + /// + public double DecilitersPerLiter => As(VolumeConcentrationUnit.DecilitersPerLiter); + + /// + /// Get VolumeConcentration in DecilitersPerMililiter. + /// + public double DecilitersPerMililiter => As(VolumeConcentrationUnit.DecilitersPerMililiter); + + /// + /// Get VolumeConcentration in DecimalFractions. + /// + public double DecimalFractions => As(VolumeConcentrationUnit.DecimalFraction); + + /// + /// Get VolumeConcentration in LitersPerLiter. + /// + public double LitersPerLiter => As(VolumeConcentrationUnit.LitersPerLiter); + + /// + /// Get VolumeConcentration in LitersPerMililiter. + /// + public double LitersPerMililiter => As(VolumeConcentrationUnit.LitersPerMililiter); + + /// + /// Get VolumeConcentration in MicrolitersPerLiter. + /// + public double MicrolitersPerLiter => As(VolumeConcentrationUnit.MicrolitersPerLiter); + + /// + /// Get VolumeConcentration in MicrolitersPerMililiter. + /// + public double MicrolitersPerMililiter => As(VolumeConcentrationUnit.MicrolitersPerMililiter); + + /// + /// Get VolumeConcentration in MillilitersPerLiter. + /// + public double MillilitersPerLiter => As(VolumeConcentrationUnit.MillilitersPerLiter); + + /// + /// Get VolumeConcentration in MillilitersPerMililiter. + /// + public double MillilitersPerMililiter => As(VolumeConcentrationUnit.MillilitersPerMililiter); + + /// + /// Get VolumeConcentration in NanolitersPerLiter. + /// + public double NanolitersPerLiter => As(VolumeConcentrationUnit.NanolitersPerLiter); + + /// + /// Get VolumeConcentration in NanolitersPerMililiter. + /// + public double NanolitersPerMililiter => As(VolumeConcentrationUnit.NanolitersPerMililiter); + + /// + /// Get VolumeConcentration in PartsPerBillion. + /// + public double PartsPerBillion => As(VolumeConcentrationUnit.PartPerBillion); + + /// + /// Get VolumeConcentration in PartsPerMillion. + /// + public double PartsPerMillion => As(VolumeConcentrationUnit.PartPerMillion); + + /// + /// Get VolumeConcentration in PartsPerThousand. + /// + public double PartsPerThousand => As(VolumeConcentrationUnit.PartPerThousand); + + /// + /// Get VolumeConcentration in PartsPerTrillion. + /// + public double PartsPerTrillion => As(VolumeConcentrationUnit.PartPerTrillion); + + /// + /// Get VolumeConcentration in Percent. + /// + public double Percent => As(VolumeConcentrationUnit.Percent); + + /// + /// Get VolumeConcentration in PicolitersPerLiter. + /// + public double PicolitersPerLiter => As(VolumeConcentrationUnit.PicolitersPerLiter); + + /// + /// Get VolumeConcentration in PicolitersPerMililiter. + /// + public double PicolitersPerMililiter => As(VolumeConcentrationUnit.PicolitersPerMililiter); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(VolumeConcentrationUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(VolumeConcentrationUnit unit, [CanBeNull] IFormatProvider provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get VolumeConcentration from CentilitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromCentilitersPerLiter(QuantityValue centilitersperliter) + { + double value = (double) centilitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.CentilitersPerLiter); + } + /// + /// Get VolumeConcentration from CentilitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromCentilitersPerMililiter(QuantityValue centiliterspermililiter) + { + double value = (double) centiliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.CentilitersPerMililiter); + } + /// + /// Get VolumeConcentration from DecilitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromDecilitersPerLiter(QuantityValue decilitersperliter) + { + double value = (double) decilitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.DecilitersPerLiter); + } + /// + /// Get VolumeConcentration from DecilitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromDecilitersPerMililiter(QuantityValue deciliterspermililiter) + { + double value = (double) deciliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.DecilitersPerMililiter); + } + /// + /// Get VolumeConcentration from DecimalFractions. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromDecimalFractions(QuantityValue decimalfractions) + { + double value = (double) decimalfractions; + return new VolumeConcentration(value, VolumeConcentrationUnit.DecimalFraction); + } + /// + /// Get VolumeConcentration from LitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromLitersPerLiter(QuantityValue litersperliter) + { + double value = (double) litersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.LitersPerLiter); + } + /// + /// Get VolumeConcentration from LitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromLitersPerMililiter(QuantityValue literspermililiter) + { + double value = (double) literspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.LitersPerMililiter); + } + /// + /// Get VolumeConcentration from MicrolitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromMicrolitersPerLiter(QuantityValue microlitersperliter) + { + double value = (double) microlitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MicrolitersPerLiter); + } + /// + /// Get VolumeConcentration from MicrolitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromMicrolitersPerMililiter(QuantityValue microliterspermililiter) + { + double value = (double) microliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MicrolitersPerMililiter); + } + /// + /// Get VolumeConcentration from MillilitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromMillilitersPerLiter(QuantityValue millilitersperliter) + { + double value = (double) millilitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MillilitersPerLiter); + } + /// + /// Get VolumeConcentration from MillilitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromMillilitersPerMililiter(QuantityValue milliliterspermililiter) + { + double value = (double) milliliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.MillilitersPerMililiter); + } + /// + /// Get VolumeConcentration from NanolitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromNanolitersPerLiter(QuantityValue nanolitersperliter) + { + double value = (double) nanolitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.NanolitersPerLiter); + } + /// + /// Get VolumeConcentration from NanolitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromNanolitersPerMililiter(QuantityValue nanoliterspermililiter) + { + double value = (double) nanoliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.NanolitersPerMililiter); + } + /// + /// Get VolumeConcentration from PartsPerBillion. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPartsPerBillion(QuantityValue partsperbillion) + { + double value = (double) partsperbillion; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerBillion); + } + /// + /// Get VolumeConcentration from PartsPerMillion. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPartsPerMillion(QuantityValue partspermillion) + { + double value = (double) partspermillion; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerMillion); + } + /// + /// Get VolumeConcentration from PartsPerThousand. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPartsPerThousand(QuantityValue partsperthousand) + { + double value = (double) partsperthousand; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerThousand); + } + /// + /// Get VolumeConcentration from PartsPerTrillion. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPartsPerTrillion(QuantityValue partspertrillion) + { + double value = (double) partspertrillion; + return new VolumeConcentration(value, VolumeConcentrationUnit.PartPerTrillion); + } + /// + /// Get VolumeConcentration from Percent. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPercent(QuantityValue percent) + { + double value = (double) percent; + return new VolumeConcentration(value, VolumeConcentrationUnit.Percent); + } + /// + /// Get VolumeConcentration from PicolitersPerLiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPicolitersPerLiter(QuantityValue picolitersperliter) + { + double value = (double) picolitersperliter; + return new VolumeConcentration(value, VolumeConcentrationUnit.PicolitersPerLiter); + } + /// + /// Get VolumeConcentration from PicolitersPerMililiter. + /// + /// If value is NaN or Infinity. + public static VolumeConcentration FromPicolitersPerMililiter(QuantityValue picoliterspermililiter) + { + double value = (double) picoliterspermililiter; + return new VolumeConcentration(value, VolumeConcentrationUnit.PicolitersPerMililiter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// VolumeConcentration unit value. + public static VolumeConcentration From(QuantityValue value, VolumeConcentrationUnit fromUnit) + { + return new VolumeConcentration((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static VolumeConcentration Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static VolumeConcentration Parse(string str, [CanBeNull] IFormatProvider provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out VolumeConcentration result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out VolumeConcentration result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static VolumeConcentrationUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Format to use when parsing number and unit. Defaults to if null. + public static VolumeConcentrationUnit ParseUnit(string str, IFormatProvider provider = null) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out VolumeConcentrationUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider provider, out VolumeConcentrationUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static VolumeConcentration operator -(VolumeConcentration right) + { + return new VolumeConcentration(-right.Value, right.Unit); + } + + /// Get from adding two . + public static VolumeConcentration operator +(VolumeConcentration left, VolumeConcentration right) + { + return new VolumeConcentration(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static VolumeConcentration operator -(VolumeConcentration left, VolumeConcentration right) + { + return new VolumeConcentration(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static VolumeConcentration operator *(double left, VolumeConcentration right) + { + return new VolumeConcentration(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static VolumeConcentration operator *(VolumeConcentration left, double right) + { + return new VolumeConcentration(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static VolumeConcentration operator /(VolumeConcentration left, double right) + { + return new VolumeConcentration(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(VolumeConcentration left, VolumeConcentration right) + { + return left.DecimalFractions / right.DecimalFractions; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(VolumeConcentration left, VolumeConcentration right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(VolumeConcentration left, VolumeConcentration right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(VolumeConcentration left, VolumeConcentration right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(VolumeConcentration left, VolumeConcentration right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(VolumeConcentration left, VolumeConcentration right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(VolumeConcentration left, VolumeConcentration right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is VolumeConcentration objVolumeConcentration)) throw new ArgumentException("Expected type VolumeConcentration.", nameof(obj)); + + return CompareTo(objVolumeConcentration); + } + + /// + public int CompareTo(VolumeConcentration other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if(obj is null || !(obj is VolumeConcentration objVolumeConcentration)) + return false; + + return Equals(objVolumeConcentration); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(VolumeConcentration other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another VolumeConcentration within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(VolumeConcentration other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current VolumeConcentration. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(VolumeConcentrationUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VolumeConcentrationUnit unitAsVolumeConcentrationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeConcentrationUnit)} is supported.", nameof(unit)); + + return As(unitAsVolumeConcentrationUnit); + } + + /// + /// Converts this VolumeConcentration to another VolumeConcentration with the unit representation . + /// + /// A VolumeConcentration with the specified unit. + public VolumeConcentration ToUnit(VolumeConcentrationUnit unit) + { + var convertedValue = GetValueAs(unit); + return new VolumeConcentration(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is VolumeConcentrationUnit unitAsVolumeConcentrationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeConcentrationUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsVolumeConcentrationUnit); + } + + /// + public VolumeConcentration ToUnit(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(VolumeConcentrationUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case VolumeConcentrationUnit.CentilitersPerLiter: return (_value) * 1e-2d; + case VolumeConcentrationUnit.CentilitersPerMililiter: return (_value/1e-3) * 1e-2d; + case VolumeConcentrationUnit.DecilitersPerLiter: return (_value) * 1e-1d; + case VolumeConcentrationUnit.DecilitersPerMililiter: return (_value/1e-3) * 1e-1d; + case VolumeConcentrationUnit.DecimalFraction: return _value; + case VolumeConcentrationUnit.LitersPerLiter: return _value; + case VolumeConcentrationUnit.LitersPerMililiter: return _value/1e-3; + case VolumeConcentrationUnit.MicrolitersPerLiter: return (_value) * 1e-6d; + case VolumeConcentrationUnit.MicrolitersPerMililiter: return (_value/1e-3) * 1e-6d; + case VolumeConcentrationUnit.MillilitersPerLiter: return (_value) * 1e-3d; + case VolumeConcentrationUnit.MillilitersPerMililiter: return (_value/1e-3) * 1e-3d; + case VolumeConcentrationUnit.NanolitersPerLiter: return (_value) * 1e-9d; + case VolumeConcentrationUnit.NanolitersPerMililiter: return (_value/1e-3) * 1e-9d; + case VolumeConcentrationUnit.PartPerBillion: return _value/1e9; + case VolumeConcentrationUnit.PartPerMillion: return _value/1e6; + case VolumeConcentrationUnit.PartPerThousand: return _value/1e3; + case VolumeConcentrationUnit.PartPerTrillion: return _value/1e12; + case VolumeConcentrationUnit.Percent: return _value/1e2; + case VolumeConcentrationUnit.PicolitersPerLiter: return (_value) * 1e-12d; + case VolumeConcentrationUnit.PicolitersPerMililiter: return (_value/1e-3) * 1e-12d; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double GetValueAs(VolumeConcentrationUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case VolumeConcentrationUnit.CentilitersPerLiter: return (baseUnitValue) / 1e-2d; + case VolumeConcentrationUnit.CentilitersPerMililiter: return (baseUnitValue*1e-3) / 1e-2d; + case VolumeConcentrationUnit.DecilitersPerLiter: return (baseUnitValue) / 1e-1d; + case VolumeConcentrationUnit.DecilitersPerMililiter: return (baseUnitValue*1e-3) / 1e-1d; + case VolumeConcentrationUnit.DecimalFraction: return baseUnitValue; + case VolumeConcentrationUnit.LitersPerLiter: return baseUnitValue; + case VolumeConcentrationUnit.LitersPerMililiter: return baseUnitValue*1e-3; + case VolumeConcentrationUnit.MicrolitersPerLiter: return (baseUnitValue) / 1e-6d; + case VolumeConcentrationUnit.MicrolitersPerMililiter: return (baseUnitValue*1e-3) / 1e-6d; + case VolumeConcentrationUnit.MillilitersPerLiter: return (baseUnitValue) / 1e-3d; + case VolumeConcentrationUnit.MillilitersPerMililiter: return (baseUnitValue*1e-3) / 1e-3d; + case VolumeConcentrationUnit.NanolitersPerLiter: return (baseUnitValue) / 1e-9d; + case VolumeConcentrationUnit.NanolitersPerMililiter: return (baseUnitValue*1e-3) / 1e-9d; + case VolumeConcentrationUnit.PartPerBillion: return baseUnitValue*1e9; + case VolumeConcentrationUnit.PartPerMillion: return baseUnitValue*1e6; + case VolumeConcentrationUnit.PartPerThousand: return baseUnitValue*1e3; + case VolumeConcentrationUnit.PartPerTrillion: return baseUnitValue*1e12; + case VolumeConcentrationUnit.Percent: return baseUnitValue*1e2; + case VolumeConcentrationUnit.PicolitersPerLiter: return (baseUnitValue) / 1e-12d; + case VolumeConcentrationUnit.PicolitersPerMililiter: return (baseUnitValue*1e-3) / 1e-12d; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] IFormatProvider provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider formatProvider) + { + return QuantityFormatter.Format(this, format, formatProvider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(VolumeConcentration)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(VolumeConcentration)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(VolumeConcentration)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if(conversionType == typeof(VolumeConcentration)) + return this; + else if(conversionType == typeof(VolumeConcentrationUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return VolumeConcentration.QuantityType; + else if(conversionType == typeof(BaseDimensions)) + return VolumeConcentration.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(VolumeConcentration)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 56550d7324..79310d3e0e 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -150,10 +150,14 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu return Magnetization.From(value, Magnetization.BaseUnit); case QuantityType.Mass: return Mass.From(value, Mass.BaseUnit); + case QuantityType.MassConcentration: + return MassConcentration.From(value, MassConcentration.BaseUnit); case QuantityType.MassFlow: return MassFlow.From(value, MassFlow.BaseUnit); case QuantityType.MassFlux: return MassFlux.From(value, MassFlux.BaseUnit); + case QuantityType.MassFraction: + return MassFraction.From(value, MassFraction.BaseUnit); case QuantityType.MassMomentOfInertia: return MassMomentOfInertia.From(value, MassMomentOfInertia.BaseUnit); case QuantityType.MolarEnergy: @@ -220,6 +224,8 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu return VitaminA.From(value, VitaminA.BaseUnit); case QuantityType.Volume: return Volume.From(value, Volume.BaseUnit); + case QuantityType.VolumeConcentration: + return VolumeConcentration.From(value, VolumeConcentration.BaseUnit); case QuantityType.VolumeFlow: return VolumeFlow.From(value, VolumeFlow.BaseUnit); case QuantityType.VolumePerLength: @@ -405,12 +411,18 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit case MassUnit massUnit: quantity = Mass.From(value, massUnit); return true; + case MassConcentrationUnit massConcentrationUnit: + quantity = MassConcentration.From(value, massConcentrationUnit); + return true; case MassFlowUnit massFlowUnit: quantity = MassFlow.From(value, massFlowUnit); return true; case MassFluxUnit massFluxUnit: quantity = MassFlux.From(value, massFluxUnit); return true; + case MassFractionUnit massFractionUnit: + quantity = MassFraction.From(value, massFractionUnit); + return true; case MassMomentOfInertiaUnit massMomentOfInertiaUnit: quantity = MassMomentOfInertia.From(value, massMomentOfInertiaUnit); return true; @@ -510,6 +522,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit case VolumeUnit volumeUnit: quantity = Volume.From(value, volumeUnit); return true; + case VolumeConcentrationUnit volumeConcentrationUnit: + quantity = VolumeConcentration.From(value, volumeConcentrationUnit); + return true; case VolumeFlowUnit volumeFlowUnit: quantity = VolumeFlow.From(value, volumeFlowUnit); return true; @@ -653,10 +668,14 @@ public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type qua return parser.TryParse(quantityString, formatProvider, Magnetization.From, out quantity); case Type _ when quantityType == typeof(Mass): return parser.TryParse(quantityString, formatProvider, Mass.From, out quantity); + case Type _ when quantityType == typeof(MassConcentration): + return parser.TryParse(quantityString, formatProvider, MassConcentration.From, out quantity); case Type _ when quantityType == typeof(MassFlow): return parser.TryParse(quantityString, formatProvider, MassFlow.From, out quantity); case Type _ when quantityType == typeof(MassFlux): return parser.TryParse(quantityString, formatProvider, MassFlux.From, out quantity); + case Type _ when quantityType == typeof(MassFraction): + return parser.TryParse(quantityString, formatProvider, MassFraction.From, out quantity); case Type _ when quantityType == typeof(MassMomentOfInertia): return parser.TryParse(quantityString, formatProvider, MassMomentOfInertia.From, out quantity); case Type _ when quantityType == typeof(MolarEnergy): @@ -723,6 +742,8 @@ public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type qua return parser.TryParse(quantityString, formatProvider, VitaminA.From, out quantity); case Type _ when quantityType == typeof(Volume): return parser.TryParse(quantityString, formatProvider, Volume.From, out quantity); + case Type _ when quantityType == typeof(VolumeConcentration): + return parser.TryParse(quantityString, formatProvider, VolumeConcentration.From, out quantity); case Type _ when quantityType == typeof(VolumeFlow): return parser.TryParse(quantityString, formatProvider, VolumeFlow.From, out quantity); case Type _ when quantityType == typeof(VolumePerLength): diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 4cb5ef6973..13ee0f034c 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -86,8 +86,10 @@ public enum QuantityType MagneticFlux, Magnetization, Mass, + MassConcentration, MassFlow, MassFlux, + MassFraction, MassMomentOfInertia, MolarEnergy, MolarEntropy, @@ -121,6 +123,7 @@ public enum QuantityType Torque, VitaminA, Volume, + VolumeConcentration, VolumeFlow, VolumePerLength, // Missing XML comment for public type or member diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index 5154520fd6..51713265a4 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -582,6 +582,50 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassUnit), (int)MassUnit.Stone, new string[]{"st"}), ("en-US", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"t"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"т"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerDeciliter, new string[]{"cg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerLiter, new string[]{"cg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerMilliliter, new string[]{"cg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerDeciliter, new string[]{"dg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerLiter, new string[]{"dg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerMilliliter, new string[]{"dg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicCentimeter, new string[]{"g/cm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"g/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"г/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMillimeter, new string[]{"g/mm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerDeciliter, new string[]{"g/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerLiter, new string[]{"g/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerMilliliter, new string[]{"g/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicCentimeter, new string[]{"kg/cm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kg/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kг/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMillimeter, new string[]{"kg/mm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerLiter, new string[]{"kg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicFoot, new string[]{"kip/ft³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicInch, new string[]{"kip/in³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µg/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µг/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerDeciliter, new string[]{"µg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerLiter, new string[]{"µg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerMilliliter, new string[]{"µg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mg/m³"}), + ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mг/м³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerDeciliter, new string[]{"mg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerLiter, new string[]{"mg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerMilliliter, new string[]{"mg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerDeciliter, new string[]{"ng/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerLiter, new string[]{"ng/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerMilliliter, new string[]{"ng/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerDeciliter, new string[]{"pg/dl"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerLiter, new string[]{"pg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerMilliliter, new string[]{"pg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicFoot, new string[]{"lb/ft³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicInch, new string[]{"lb/in³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerImperialGallon, new string[]{"ppg (imp.)"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerUSGallon, new string[]{"ppg (U.S.)"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.SlugPerCubicFoot, new string[]{"slug/ft³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.TonnePerCubicCentimeter, new string[]{"t/cm³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.TonnePerCubicMeter, new string[]{"t/m³"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.TonnePerCubicMillimeter, new string[]{"t/mm³"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.CentigramPerDay, new string[]{"cg/d"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.CentigramPerSecond, new string[]{"cg/S"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.DecagramPerDay, new string[]{"dag/d"}), @@ -617,6 +661,30 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.TonnePerHour, new string[]{"t/h"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMeter, new string[]{"g·s⁻¹·m⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMeter, new string[]{"kg·s⁻¹·m⁻²"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerGram, new string[]{"cg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKiloGram, new string[]{"cg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerGram, new string[]{"dag/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerKiloGram, new string[]{"dag/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerGram, new string[]{"dg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerKiloGram, new string[]{"dg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecimalFraction, new string[]{""}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerGram, new string[]{"g/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerKiloGram, new string[]{"g/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerGram, new string[]{"hg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerKiloGram, new string[]{"hg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerGram, new string[]{"kg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerKiloGram, new string[]{"kg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerGram, new string[]{"µg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerKiloGram, new string[]{"µg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerGram, new string[]{"mg/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerKiloGram, new string[]{"mg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerGram, new string[]{"ng/g"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerKiloGram, new string[]{"ng/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerBillion, new string[]{"ppb"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerMillion, new string[]{"ppm"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerThousand, new string[]{"‰"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerTrillion, new string[]{"ppt"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.Percent, new string[]{"%", "% (w/w)"}), ("en-US", typeof(MassMomentOfInertiaUnit), (int)MassMomentOfInertiaUnit.GramSquareCentimeter, new string[]{"g·cm²"}), ("en-US", typeof(MassMomentOfInertiaUnit), (int)MassMomentOfInertiaUnit.GramSquareDecimeter, new string[]{"g·dm²"}), ("en-US", typeof(MassMomentOfInertiaUnit), (int)MassMomentOfInertiaUnit.GramSquareMeter, new string[]{"g·m²"}), @@ -653,11 +721,16 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MolarEntropyUnit), (int)MolarEntropyUnit.MegajoulePerMoleKelvin, new string[]{"MJ/(mol*K)"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.CentimolesPerLiter, new string[]{"cmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.DecimolesPerLiter, new string[]{"dmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Micromolar, new string[]{"µM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MicromolesPerLiter, new string[]{"µmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Millimolar, new string[]{"mM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MillimolesPerLiter, new string[]{"mmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Molar, new string[]{"M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerCubicMeter, new string[]{"mol/m³"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerLiter, new string[]{"mol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Nanomolar, new string[]{"nM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.NanomolesPerLiter, new string[]{"nmol/L"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Picomolar, new string[]{"pM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.PicomolesPerLiter, new string[]{"pmol/L"}), ("en-US", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"cg/mol"}), ("ru-RU", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"сг/моль"}), @@ -1100,6 +1173,26 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("ru-RU", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("nb-NO", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerLiter, new string[]{"cl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerMililiter, new string[]{"cl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerLiter, new string[]{"dl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerMililiter, new string[]{"dl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecimalFraction, new string[]{""}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerLiter, new string[]{"l/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerMililiter, new string[]{"l/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerLiter, new string[]{"µl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerMililiter, new string[]{"µl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerLiter, new string[]{"ml/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerMililiter, new string[]{"ml/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerLiter, new string[]{"nl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerMililiter, new string[]{"nl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerBillion, new string[]{"ppb"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerMillion, new string[]{"ppm"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerThousand, new string[]{"‰"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerTrillion, new string[]{"ppt"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.Percent, new string[]{"%", "% (v/v)"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerLiter, new string[]{"pl/l"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerMililiter, new string[]{"pl/ml"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerDay, new string[]{"af/d"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerHour, new string[]{"af/h"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerMinute, new string[]{"af/m"}), diff --git a/UnitsNet/GeneratedCode/Units/MassConcentrationUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassConcentrationUnit.g.cs new file mode 100644 index 0000000000..8e869541f3 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/MassConcentrationUnit.g.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum MassConcentrationUnit + { + Undefined = 0, + CentigramPerDeciliter, + CentigramPerLiter, + CentigramPerMilliliter, + DecigramPerDeciliter, + DecigramPerLiter, + DecigramPerMilliliter, + GramPerCubicCentimeter, + GramPerCubicMeter, + GramPerCubicMillimeter, + GramPerDeciliter, + GramPerLiter, + GramPerMilliliter, + KilogramPerCubicCentimeter, + KilogramPerCubicMeter, + KilogramPerCubicMillimeter, + KilogramPerLiter, + KilopoundPerCubicFoot, + KilopoundPerCubicInch, + MicrogramPerCubicMeter, + MicrogramPerDeciliter, + MicrogramPerLiter, + MicrogramPerMilliliter, + MilligramPerCubicMeter, + MilligramPerDeciliter, + MilligramPerLiter, + MilligramPerMilliliter, + NanogramPerDeciliter, + NanogramPerLiter, + NanogramPerMilliliter, + PicogramPerDeciliter, + PicogramPerLiter, + PicogramPerMilliliter, + PoundPerCubicFoot, + PoundPerCubicInch, + PoundPerImperialGallon, + PoundPerUSGallon, + SlugPerCubicFoot, + TonnePerCubicCentimeter, + TonnePerCubicMeter, + TonnePerCubicMillimeter, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs new file mode 100644 index 0000000000..fe7f622126 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum MassFractionUnit + { + Undefined = 0, + CentigramPerGram, + CentigramPerKiloGram, + DecagramPerGram, + DecagramPerKiloGram, + DecigramPerGram, + DecigramPerKiloGram, + DecimalFraction, + GramPerGram, + GramPerKiloGram, + HectogramPerGram, + HectogramPerKiloGram, + KilogramPerGram, + KilogramPerKiloGram, + MicrogramPerGram, + MicrogramPerKiloGram, + MilligramPerGram, + MilligramPerKiloGram, + NanogramPerGram, + NanogramPerKiloGram, + PartPerBillion, + PartPerMillion, + PartPerThousand, + PartPerTrillion, + Percent, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs index be257aec48..089593b8ec 100644 --- a/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs @@ -28,11 +28,16 @@ public enum MolarityUnit Undefined = 0, CentimolesPerLiter, DecimolesPerLiter, + Micromolar, MicromolesPerLiter, + Millimolar, MillimolesPerLiter, + Molar, MolesPerCubicMeter, MolesPerLiter, + Nanomolar, NanomolesPerLiter, + Picomolar, PicomolesPerLiter, } diff --git a/UnitsNet/GeneratedCode/Units/VolumeConcentrationUnit.g.cs b/UnitsNet/GeneratedCode/Units/VolumeConcentrationUnit.g.cs new file mode 100644 index 0000000000..6431bc77c0 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/VolumeConcentrationUnit.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum VolumeConcentrationUnit + { + Undefined = 0, + CentilitersPerLiter, + CentilitersPerMililiter, + DecilitersPerLiter, + DecilitersPerMililiter, + DecimalFraction, + LitersPerLiter, + LitersPerMililiter, + MicrolitersPerLiter, + MicrolitersPerMililiter, + MillilitersPerLiter, + MillilitersPerMililiter, + NanolitersPerLiter, + NanolitersPerMililiter, + PartPerBillion, + PartPerMillion, + PartPerThousand, + PartPerTrillion, + Percent, + PicolitersPerLiter, + PicolitersPerMililiter, + } + + #pragma warning restore 1591 +} From cb8da0afe4bca8a26077bfdc660b7a860e732cea Mon Sep 17 00:00:00 2001 From: lipchev Date: Sat, 13 Apr 2019 10:21:32 +0300 Subject: [PATCH 2/8] updated uppercase 'L' & BaseUnits in json - updated liter abbreviations for g/l, g/dl, g/ml & kg/l to uppercase 'L' (TODO Density?) - added base units to all units in MassConcentration & Molarity (TODO Density?) --- Common/UnitDefinitions/MassConcentration.json | 52 +++++++++++++------ Common/UnitDefinitions/Molarity.json | 12 +++++ ...Concentration.WindowsRuntimeComponent.g.cs | 28 +++++----- .../GeneratedCode/UnitAbbreviationsCache.g.cs | 44 ++++++++-------- .../MassConcentration.NetFramework.g.cs | 44 ++++++++-------- .../Quantities/Molarity.NetFramework.g.cs | 6 +-- .../GeneratedCode/UnitAbbreviationsCache.g.cs | 44 ++++++++-------- 7 files changed, 131 insertions(+), 99 deletions(-) diff --git a/Common/UnitDefinitions/MassConcentration.json b/Common/UnitDefinitions/MassConcentration.json index ed9bdb01e9..03e7bbf461 100644 --- a/Common/UnitDefinitions/MassConcentration.json +++ b/Common/UnitDefinitions/MassConcentration.json @@ -12,8 +12,8 @@ "SingularName": "GramPerCubicMillimeter", "PluralName": "GramsPerCubicMillimeter", "BaseUnits": { - "L": "Millimeter", - "M": "Gram" + "L": "Meter", + "M": "Kilogram" }, "FromUnitToBaseFunc": "x/1e-6", "FromBaseToUnitFunc": "x*1e-6", @@ -29,8 +29,8 @@ "SingularName": "GramPerCubicCentimeter", "PluralName": "GramsPerCubicCentimeter", "BaseUnits": { - "L": "Centimeter", - "M": "Gram" + "L": "Meter", + "M": "Kilogram" }, "FromUnitToBaseFunc": "x/1e-3", "FromBaseToUnitFunc": "x*1e-3", @@ -47,7 +47,7 @@ "PluralName": "GramsPerCubicMeter", "BaseUnits": { "L": "Meter", - "M": "Gram" + "M": "Kilogram" }, "FromUnitToBaseFunc": "x/1e3", "FromBaseToUnitFunc": "x*1e3", @@ -165,46 +165,62 @@ }, { "SingularName": "GramPerLiter", - "PluralName": "GramsPerLiter", - "FromUnitToBaseFunc": "x/1", - "FromBaseToUnitFunc": "x*1", + "PluralName": "GramsPerLiter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram" + }, + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/l"] + "Abbreviations": [ "g/L"] } ] }, { "SingularName": "GramPerDeciliter", - "PluralName": "GramsPerDeciLiter", + "PluralName": "GramsPerDeciLiter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram" + }, "FromUnitToBaseFunc": "x/1e-1", "FromBaseToUnitFunc": "x*1e-1", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/dl" ] + "Abbreviations": [ "g/dL" ] } ] }, { "SingularName": "GramPerMilliliter", - "PluralName": "GramsPerMilliliter", + "PluralName": "GramsPerMilliliter", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram" + }, "FromUnitToBaseFunc": "x/1e-3", "FromBaseToUnitFunc": "x*1e-3", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/ml" ] + "Abbreviations": [ "g/mL" ] } ] }, { "SingularName": "PoundPerUSGallon", - "PluralName": "PoundsPerUSGallon", + "PluralName": "PoundsPerUSGallon", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram" + }, "FromUnitToBaseFunc": "x*1.19826427e2", "FromBaseToUnitFunc": "x/1.19826427e2", "Localization": [ @@ -216,7 +232,11 @@ }, { "SingularName": "PoundPerImperialGallon", - "PluralName": "PoundsPerImperialGallon", + "PluralName": "PoundsPerImperialGallon", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram" + }, "FromUnitToBaseFunc": "x*9.9776398e1", "FromBaseToUnitFunc": "x/9.9776398e1", "Localization": [ @@ -238,7 +258,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "kg/l" ] + "Abbreviations": [ "kg/L" ] } ] } diff --git a/Common/UnitDefinitions/Molarity.json b/Common/UnitDefinitions/Molarity.json index c4584a1ef7..7fcd7afcc1 100644 --- a/Common/UnitDefinitions/Molarity.json +++ b/Common/UnitDefinitions/Molarity.json @@ -11,6 +11,10 @@ { "SingularName": "MolesPerCubicMeter", "PluralName": "MolesPerCubicMeter", + "BaseUnits": { + "L": "Meter", + "N": "Mole" + }, "FromUnitToBaseFunc": "x", "FromBaseToUnitFunc": "x", "Prefixes": [], @@ -24,6 +28,10 @@ { "SingularName": "MolesPerLiter", "PluralName": "MolesPerLiter", + "BaseUnits": { + "L": "Meter", + "N": "Mole" + }, "FromUnitToBaseFunc": "x/1e-3", "FromBaseToUnitFunc": "x*1e-3", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], @@ -37,6 +45,10 @@ { "SingularName": "Molar", "PluralName": "Molar", + "BaseUnits": { + "L": "Meter", + "N": "Mole" + }, "FromUnitToBaseFunc": "x/1e-3", "FromBaseToUnitFunc": "x*1e-3", "Prefixes": [ "Pico", "Nano", "Micro", "Milli"], diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs index 04aa891b8b..73873cc907 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs @@ -1080,16 +1080,16 @@ private double AsBaseUnit() switch(Unit) { case MassConcentrationUnit.CentigramPerDeciliter: return (_value/1e-1) * 1e-2d; - case MassConcentrationUnit.CentigramPerLiter: return (_value/1) * 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (_value) * 1e-2d; case MassConcentrationUnit.CentigramPerMilliliter: return (_value/1e-3) * 1e-2d; case MassConcentrationUnit.DecigramPerDeciliter: return (_value/1e-1) * 1e-1d; - case MassConcentrationUnit.DecigramPerLiter: return (_value/1) * 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (_value) * 1e-1d; case MassConcentrationUnit.DecigramPerMilliliter: return (_value/1e-3) * 1e-1d; case MassConcentrationUnit.GramPerCubicCentimeter: return _value/1e-3; case MassConcentrationUnit.GramPerCubicMeter: return _value/1e3; case MassConcentrationUnit.GramPerCubicMillimeter: return _value/1e-6; case MassConcentrationUnit.GramPerDeciliter: return _value/1e-1; - case MassConcentrationUnit.GramPerLiter: return _value/1; + case MassConcentrationUnit.GramPerLiter: return _value; case MassConcentrationUnit.GramPerMilliliter: return _value/1e-3; case MassConcentrationUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d; @@ -1099,17 +1099,17 @@ private double AsBaseUnit() case MassConcentrationUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (_value/1e3) * 1e-6d; case MassConcentrationUnit.MicrogramPerDeciliter: return (_value/1e-1) * 1e-6d; - case MassConcentrationUnit.MicrogramPerLiter: return (_value/1) * 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (_value) * 1e-6d; case MassConcentrationUnit.MicrogramPerMilliliter: return (_value/1e-3) * 1e-6d; case MassConcentrationUnit.MilligramPerCubicMeter: return (_value/1e3) * 1e-3d; case MassConcentrationUnit.MilligramPerDeciliter: return (_value/1e-1) * 1e-3d; - case MassConcentrationUnit.MilligramPerLiter: return (_value/1) * 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (_value) * 1e-3d; case MassConcentrationUnit.MilligramPerMilliliter: return (_value/1e-3) * 1e-3d; case MassConcentrationUnit.NanogramPerDeciliter: return (_value/1e-1) * 1e-9d; - case MassConcentrationUnit.NanogramPerLiter: return (_value/1) * 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (_value) * 1e-9d; case MassConcentrationUnit.NanogramPerMilliliter: return (_value/1e-3) * 1e-9d; case MassConcentrationUnit.PicogramPerDeciliter: return (_value/1e-1) * 1e-12d; - case MassConcentrationUnit.PicogramPerLiter: return (_value/1) * 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (_value) * 1e-12d; case MassConcentrationUnit.PicogramPerMilliliter: return (_value/1e-3) * 1e-12d; case MassConcentrationUnit.PoundPerCubicFoot: return _value/0.062427961; case MassConcentrationUnit.PoundPerCubicInch: return _value/3.6127298147753e-5; @@ -1134,16 +1134,16 @@ private double AsBaseNumericType(MassConcentrationUnit unit) switch(unit) { case MassConcentrationUnit.CentigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-2d; - case MassConcentrationUnit.CentigramPerLiter: return (baseUnitValue*1) / 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (baseUnitValue) / 1e-2d; case MassConcentrationUnit.CentigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-2d; case MassConcentrationUnit.DecigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-1d; - case MassConcentrationUnit.DecigramPerLiter: return (baseUnitValue*1) / 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (baseUnitValue) / 1e-1d; case MassConcentrationUnit.DecigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-1d; case MassConcentrationUnit.GramPerCubicCentimeter: return baseUnitValue*1e-3; case MassConcentrationUnit.GramPerCubicMeter: return baseUnitValue*1e3; case MassConcentrationUnit.GramPerCubicMillimeter: return baseUnitValue*1e-6; case MassConcentrationUnit.GramPerDeciliter: return baseUnitValue*1e-1; - case MassConcentrationUnit.GramPerLiter: return baseUnitValue*1; + case MassConcentrationUnit.GramPerLiter: return baseUnitValue; case MassConcentrationUnit.GramPerMilliliter: return baseUnitValue*1e-3; case MassConcentrationUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d; @@ -1153,17 +1153,17 @@ private double AsBaseNumericType(MassConcentrationUnit unit) case MassConcentrationUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (baseUnitValue*1e3) / 1e-6d; case MassConcentrationUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-6d; - case MassConcentrationUnit.MicrogramPerLiter: return (baseUnitValue*1) / 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (baseUnitValue) / 1e-6d; case MassConcentrationUnit.MicrogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-6d; case MassConcentrationUnit.MilligramPerCubicMeter: return (baseUnitValue*1e3) / 1e-3d; case MassConcentrationUnit.MilligramPerDeciliter: return (baseUnitValue*1e-1) / 1e-3d; - case MassConcentrationUnit.MilligramPerLiter: return (baseUnitValue*1) / 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (baseUnitValue) / 1e-3d; case MassConcentrationUnit.MilligramPerMilliliter: return (baseUnitValue*1e-3) / 1e-3d; case MassConcentrationUnit.NanogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-9d; - case MassConcentrationUnit.NanogramPerLiter: return (baseUnitValue*1) / 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (baseUnitValue) / 1e-9d; case MassConcentrationUnit.NanogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-9d; case MassConcentrationUnit.PicogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-12d; - case MassConcentrationUnit.PicogramPerLiter: return (baseUnitValue*1) / 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (baseUnitValue) / 1e-12d; case MassConcentrationUnit.PicogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-12d; case MassConcentrationUnit.PoundPerCubicFoot: return baseUnitValue*0.062427961; case MassConcentrationUnit.PoundPerCubicInch: return baseUnitValue*3.6127298147753e-5; diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index 196016444f..e26494652b 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -583,42 +583,42 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassUnit), (int)MassUnit.Stone, new string[]{"st"}), ("en-US", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"t"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"т"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerDeciliter, new string[]{"cg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerLiter, new string[]{"cg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerMilliliter, new string[]{"cg/ml"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerDeciliter, new string[]{"dg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerLiter, new string[]{"dg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerMilliliter, new string[]{"dg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerDeciliter, new string[]{"cg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerLiter, new string[]{"cg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerMilliliter, new string[]{"cg/mL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerDeciliter, new string[]{"dg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerLiter, new string[]{"dg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerMilliliter, new string[]{"dg/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicCentimeter, new string[]{"g/cm³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"g/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"г/м³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMillimeter, new string[]{"g/mm³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerDeciliter, new string[]{"g/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerLiter, new string[]{"g/l", "g/L"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerMilliliter, new string[]{"g/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerDeciliter, new string[]{"g/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerLiter, new string[]{"g/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerMilliliter, new string[]{"g/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicCentimeter, new string[]{"kg/cm³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kg/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kг/м³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMillimeter, new string[]{"kg/mm³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerLiter, new string[]{"kg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerLiter, new string[]{"kg/L"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicFoot, new string[]{"kip/ft³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicInch, new string[]{"kip/in³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µg/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µг/м³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerDeciliter, new string[]{"µg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerLiter, new string[]{"µg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerMilliliter, new string[]{"µg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerDeciliter, new string[]{"µg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerLiter, new string[]{"µg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerMilliliter, new string[]{"µg/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mg/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mг/м³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerDeciliter, new string[]{"mg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerLiter, new string[]{"mg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerMilliliter, new string[]{"mg/ml"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerDeciliter, new string[]{"ng/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerLiter, new string[]{"ng/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerMilliliter, new string[]{"ng/ml"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerDeciliter, new string[]{"pg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerLiter, new string[]{"pg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerMilliliter, new string[]{"pg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerDeciliter, new string[]{"mg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerLiter, new string[]{"mg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerMilliliter, new string[]{"mg/mL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerDeciliter, new string[]{"ng/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerLiter, new string[]{"ng/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerMilliliter, new string[]{"ng/mL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerDeciliter, new string[]{"pg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerLiter, new string[]{"pg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerMilliliter, new string[]{"pg/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicFoot, new string[]{"lb/ft³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicInch, new string[]{"lb/in³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerImperialGallon, new string[]{"ppg (imp.)"}), diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs index ee111448a7..ec8280fe72 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs @@ -59,12 +59,12 @@ static MassConcentration() new UnitInfo(MassConcentrationUnit.DecigramPerDeciliter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.DecigramPerLiter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.DecigramPerMilliliter, BaseUnits.Undefined), - new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)), - new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)), - new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)), - new UnitInfo(MassConcentrationUnit.GramPerDeciliter, BaseUnits.Undefined), - new UnitInfo(MassConcentrationUnit.GramPerLiter, BaseUnits.Undefined), - new UnitInfo(MassConcentrationUnit.GramPerMilliliter, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.GramPerDeciliter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.GramPerLiter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.GramPerMilliliter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), new UnitInfo(MassConcentrationUnit.KilogramPerCubicCentimeter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMeter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMillimeter, BaseUnits.Undefined), @@ -87,8 +87,8 @@ static MassConcentration() new UnitInfo(MassConcentrationUnit.PicogramPerMilliliter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.PoundPerCubicFoot, new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)), new UnitInfo(MassConcentrationUnit.PoundPerCubicInch, new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)), - new UnitInfo(MassConcentrationUnit.PoundPerImperialGallon, BaseUnits.Undefined), - new UnitInfo(MassConcentrationUnit.PoundPerUSGallon, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PoundPerImperialGallon, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.PoundPerUSGallon, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), new UnitInfo(MassConcentrationUnit.SlugPerCubicFoot, new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug)), new UnitInfo(MassConcentrationUnit.TonnePerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne)), new UnitInfo(MassConcentrationUnit.TonnePerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne)), @@ -1224,16 +1224,16 @@ private double GetValueInBaseUnit() switch(Unit) { case MassConcentrationUnit.CentigramPerDeciliter: return (_value/1e-1) * 1e-2d; - case MassConcentrationUnit.CentigramPerLiter: return (_value/1) * 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (_value) * 1e-2d; case MassConcentrationUnit.CentigramPerMilliliter: return (_value/1e-3) * 1e-2d; case MassConcentrationUnit.DecigramPerDeciliter: return (_value/1e-1) * 1e-1d; - case MassConcentrationUnit.DecigramPerLiter: return (_value/1) * 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (_value) * 1e-1d; case MassConcentrationUnit.DecigramPerMilliliter: return (_value/1e-3) * 1e-1d; case MassConcentrationUnit.GramPerCubicCentimeter: return _value/1e-3; case MassConcentrationUnit.GramPerCubicMeter: return _value/1e3; case MassConcentrationUnit.GramPerCubicMillimeter: return _value/1e-6; case MassConcentrationUnit.GramPerDeciliter: return _value/1e-1; - case MassConcentrationUnit.GramPerLiter: return _value/1; + case MassConcentrationUnit.GramPerLiter: return _value; case MassConcentrationUnit.GramPerMilliliter: return _value/1e-3; case MassConcentrationUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d; @@ -1243,17 +1243,17 @@ private double GetValueInBaseUnit() case MassConcentrationUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (_value/1e3) * 1e-6d; case MassConcentrationUnit.MicrogramPerDeciliter: return (_value/1e-1) * 1e-6d; - case MassConcentrationUnit.MicrogramPerLiter: return (_value/1) * 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (_value) * 1e-6d; case MassConcentrationUnit.MicrogramPerMilliliter: return (_value/1e-3) * 1e-6d; case MassConcentrationUnit.MilligramPerCubicMeter: return (_value/1e3) * 1e-3d; case MassConcentrationUnit.MilligramPerDeciliter: return (_value/1e-1) * 1e-3d; - case MassConcentrationUnit.MilligramPerLiter: return (_value/1) * 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (_value) * 1e-3d; case MassConcentrationUnit.MilligramPerMilliliter: return (_value/1e-3) * 1e-3d; case MassConcentrationUnit.NanogramPerDeciliter: return (_value/1e-1) * 1e-9d; - case MassConcentrationUnit.NanogramPerLiter: return (_value/1) * 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (_value) * 1e-9d; case MassConcentrationUnit.NanogramPerMilliliter: return (_value/1e-3) * 1e-9d; case MassConcentrationUnit.PicogramPerDeciliter: return (_value/1e-1) * 1e-12d; - case MassConcentrationUnit.PicogramPerLiter: return (_value/1) * 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (_value) * 1e-12d; case MassConcentrationUnit.PicogramPerMilliliter: return (_value/1e-3) * 1e-12d; case MassConcentrationUnit.PoundPerCubicFoot: return _value/0.062427961; case MassConcentrationUnit.PoundPerCubicInch: return _value/3.6127298147753e-5; @@ -1278,16 +1278,16 @@ private double GetValueAs(MassConcentrationUnit unit) switch(unit) { case MassConcentrationUnit.CentigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-2d; - case MassConcentrationUnit.CentigramPerLiter: return (baseUnitValue*1) / 1e-2d; + case MassConcentrationUnit.CentigramPerLiter: return (baseUnitValue) / 1e-2d; case MassConcentrationUnit.CentigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-2d; case MassConcentrationUnit.DecigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-1d; - case MassConcentrationUnit.DecigramPerLiter: return (baseUnitValue*1) / 1e-1d; + case MassConcentrationUnit.DecigramPerLiter: return (baseUnitValue) / 1e-1d; case MassConcentrationUnit.DecigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-1d; case MassConcentrationUnit.GramPerCubicCentimeter: return baseUnitValue*1e-3; case MassConcentrationUnit.GramPerCubicMeter: return baseUnitValue*1e3; case MassConcentrationUnit.GramPerCubicMillimeter: return baseUnitValue*1e-6; case MassConcentrationUnit.GramPerDeciliter: return baseUnitValue*1e-1; - case MassConcentrationUnit.GramPerLiter: return baseUnitValue*1; + case MassConcentrationUnit.GramPerLiter: return baseUnitValue; case MassConcentrationUnit.GramPerMilliliter: return baseUnitValue*1e-3; case MassConcentrationUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d; @@ -1297,17 +1297,17 @@ private double GetValueAs(MassConcentrationUnit unit) case MassConcentrationUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (baseUnitValue*1e3) / 1e-6d; case MassConcentrationUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-6d; - case MassConcentrationUnit.MicrogramPerLiter: return (baseUnitValue*1) / 1e-6d; + case MassConcentrationUnit.MicrogramPerLiter: return (baseUnitValue) / 1e-6d; case MassConcentrationUnit.MicrogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-6d; case MassConcentrationUnit.MilligramPerCubicMeter: return (baseUnitValue*1e3) / 1e-3d; case MassConcentrationUnit.MilligramPerDeciliter: return (baseUnitValue*1e-1) / 1e-3d; - case MassConcentrationUnit.MilligramPerLiter: return (baseUnitValue*1) / 1e-3d; + case MassConcentrationUnit.MilligramPerLiter: return (baseUnitValue) / 1e-3d; case MassConcentrationUnit.MilligramPerMilliliter: return (baseUnitValue*1e-3) / 1e-3d; case MassConcentrationUnit.NanogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-9d; - case MassConcentrationUnit.NanogramPerLiter: return (baseUnitValue*1) / 1e-9d; + case MassConcentrationUnit.NanogramPerLiter: return (baseUnitValue) / 1e-9d; case MassConcentrationUnit.NanogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-9d; case MassConcentrationUnit.PicogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-12d; - case MassConcentrationUnit.PicogramPerLiter: return (baseUnitValue*1) / 1e-12d; + case MassConcentrationUnit.PicogramPerLiter: return (baseUnitValue) / 1e-12d; case MassConcentrationUnit.PicogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-12d; case MassConcentrationUnit.PoundPerCubicFoot: return baseUnitValue*0.062427961; case MassConcentrationUnit.PoundPerCubicInch: return baseUnitValue*3.6127298147753e-5; diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs index 3b1d3c2129..da2980b2ae 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs @@ -59,9 +59,9 @@ static Molarity() new UnitInfo(MolarityUnit.MicromolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.Millimolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MillimolesPerLiter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.Molar, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.MolesPerCubicMeter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.MolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.Molar, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), + new UnitInfo(MolarityUnit.MolesPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), + new UnitInfo(MolarityUnit.MolesPerLiter, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), new UnitInfo(MolarityUnit.Nanomolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.NanomolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.Picomolar, BaseUnits.Undefined), diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index 7fe347ec25..bb5b890854 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -583,42 +583,42 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassUnit), (int)MassUnit.Stone, new string[]{"st"}), ("en-US", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"t"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"т"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerDeciliter, new string[]{"cg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerLiter, new string[]{"cg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerMilliliter, new string[]{"cg/ml"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerDeciliter, new string[]{"dg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerLiter, new string[]{"dg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerMilliliter, new string[]{"dg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerDeciliter, new string[]{"cg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerLiter, new string[]{"cg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.CentigramPerMilliliter, new string[]{"cg/mL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerDeciliter, new string[]{"dg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerLiter, new string[]{"dg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.DecigramPerMilliliter, new string[]{"dg/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicCentimeter, new string[]{"g/cm³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"g/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMeter, new string[]{"г/м³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerCubicMillimeter, new string[]{"g/mm³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerDeciliter, new string[]{"g/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerLiter, new string[]{"g/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerMilliliter, new string[]{"g/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerDeciliter, new string[]{"g/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerLiter, new string[]{"g/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.GramPerMilliliter, new string[]{"g/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicCentimeter, new string[]{"kg/cm³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kg/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMeter, new string[]{"kг/м³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerCubicMillimeter, new string[]{"kg/mm³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerLiter, new string[]{"kg/l"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilogramPerLiter, new string[]{"kg/L"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicFoot, new string[]{"kip/ft³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.KilopoundPerCubicInch, new string[]{"kip/in³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µg/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerCubicMeter, new string[]{"µг/м³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerDeciliter, new string[]{"µg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerLiter, new string[]{"µg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerMilliliter, new string[]{"µg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerDeciliter, new string[]{"µg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerLiter, new string[]{"µg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MicrogramPerMilliliter, new string[]{"µg/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mg/m³"}), ("ru-RU", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerCubicMeter, new string[]{"mг/м³"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerDeciliter, new string[]{"mg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerLiter, new string[]{"mg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerMilliliter, new string[]{"mg/ml"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerDeciliter, new string[]{"ng/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerLiter, new string[]{"ng/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerMilliliter, new string[]{"ng/ml"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerDeciliter, new string[]{"pg/dl"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerLiter, new string[]{"pg/l"}), - ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerMilliliter, new string[]{"pg/ml"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerDeciliter, new string[]{"mg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerLiter, new string[]{"mg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.MilligramPerMilliliter, new string[]{"mg/mL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerDeciliter, new string[]{"ng/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerLiter, new string[]{"ng/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.NanogramPerMilliliter, new string[]{"ng/mL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerDeciliter, new string[]{"pg/dL"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerLiter, new string[]{"pg/L"}), + ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PicogramPerMilliliter, new string[]{"pg/mL"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicFoot, new string[]{"lb/ft³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerCubicInch, new string[]{"lb/in³"}), ("en-US", typeof(MassConcentrationUnit), (int)MassConcentrationUnit.PoundPerImperialGallon, new string[]{"ppg (imp.)"}), From bfeaf7b481f5c11282b67c293247ff23a262efad Mon Sep 17 00:00:00 2001 From: lipchev Date: Mon, 15 Apr 2019 00:15:56 +0300 Subject: [PATCH 3/8] BaseUnits, Obsolete methods & cosmetics - corrected the BaseUnits for MassConcentration - marked the invalid methods from Molarity/Density as Obsolete (were previously omitted) - some cosmetic changes to the Unit Tests --- Common/UnitDefinitions/MassConcentration.json | 188 +++++++++--------- .../CustomCode/MassConcentrationTests.cs | 41 +++- .../CustomCode/MassFractionTests.cs | 20 +- UnitsNet.Tests/CustomCode/MolarMassTests.cs | 4 +- UnitsNet.Tests/CustomCode/MolarityTests.cs | 21 +- .../CustomCode/VolumeConcentrationTests.cs | 23 +-- ...Concentration.WindowsRuntimeComponent.g.cs | 56 +++--- .../CustomCode/Quantities/Density.extra.cs | 32 +++ .../CustomCode/Quantities/Molarity.extra.cs | 34 +++- .../MassConcentration.NetFramework.g.cs | 72 +++---- 10 files changed, 282 insertions(+), 209 deletions(-) diff --git a/Common/UnitDefinitions/MassConcentration.json b/Common/UnitDefinitions/MassConcentration.json index 03e7bbf461..296229b229 100644 --- a/Common/UnitDefinitions/MassConcentration.json +++ b/Common/UnitDefinitions/MassConcentration.json @@ -4,16 +4,16 @@ "XmlDoc": "In chemistry, the mass concentration ρi (or γi) is defined as the mass of a constituent mi divided by the volume of the mixture V", "XmlDocRemarks": "https://en.wikipedia.org/wiki/Mass_concentration_(chemistry)", "BaseDimensions": { - "L": -3, - "M": 1 + "M": 1, + "L": -3 }, "Units": [ { "SingularName": "GramPerCubicMillimeter", "PluralName": "GramsPerCubicMillimeter", "BaseUnits": { - "L": "Meter", - "M": "Kilogram" + "M": "Gram", + "L": "Millimeter" }, "FromUnitToBaseFunc": "x/1e-6", "FromBaseToUnitFunc": "x*1e-6", @@ -29,8 +29,8 @@ "SingularName": "GramPerCubicCentimeter", "PluralName": "GramsPerCubicCentimeter", "BaseUnits": { - "L": "Meter", - "M": "Kilogram" + "M": "Gram", + "L": "Centimeter" }, "FromUnitToBaseFunc": "x/1e-3", "FromBaseToUnitFunc": "x*1e-3", @@ -46,8 +46,8 @@ "SingularName": "GramPerCubicMeter", "PluralName": "GramsPerCubicMeter", "BaseUnits": { - "L": "Meter", - "M": "Kilogram" + "M": "Gram", + "L": "Meter" }, "FromUnitToBaseFunc": "x/1e3", "FromBaseToUnitFunc": "x*1e3", @@ -64,38 +64,69 @@ ] }, { - "SingularName": "PoundPerCubicInch", - "PluralName": "PoundsPerCubicInch", + "SingularName": "GramPerMilliliter", + "PluralName": "GramsPerMilliliter", "BaseUnits": { - "L": "Inch", - "M": "Pound" + "M": "Gram", + "L": "Centimeter" }, - "FromUnitToBaseFunc": "x/3.6127298147753e-5", - "FromBaseToUnitFunc": "x*3.6127298147753e-5", - "Prefixes": [ "Kilo" ], + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "lb/in³" ], - "AbbreviationsWithPrefixes": [ "kip/in³" ] + "Abbreviations": [ "g/mL" ] } ] }, { - "SingularName": "PoundPerCubicFoot", - "PluralName": "PoundsPerCubicFoot", + "SingularName": "GramPerDeciliter", + "PluralName": "GramsPerDeciliter", "BaseUnits": { - "L": "Foot", - "M": "Pound" + "M": "Gram", + "L": "Decimeter" }, - "FromUnitToBaseFunc": "x/0.062427961", - "FromBaseToUnitFunc": "x*0.062427961", - "Prefixes": [ "Kilo" ], + "FromUnitToBaseFunc": "x/1e-1", + "FromBaseToUnitFunc": "x*1e-1", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "lb/ft³" ], - "AbbreviationsWithPrefixes": [ "kip/ft³" ] + "Abbreviations": [ "g/dL" ] + } + ] + }, + { + "SingularName": "GramPerLiter", + "PluralName": "GramsPerLiter", + "BaseUnits": { + "M": "Gram", + "L": "Decimeter" + }, + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/L"] + } + ] + }, + { + "SingularName": "KilogramPerLiter", + "PluralName": "KilogramsPerLiter", + "BaseUnits": { + "M": "Kilogram", + "L": "Decimeter" + }, + "FromUnitToBaseFunc": "x*1e3", + "FromBaseToUnitFunc": "x/1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kg/L" ] } ] }, @@ -103,8 +134,8 @@ "SingularName": "TonnePerCubicMillimeter", "PluralName": "TonnesPerCubicMillimeter", "BaseUnits": { - "L": "Millimeter", - "M": "Tonne" + "M": "Tonne", + "L": "Millimeter" }, "FromUnitToBaseFunc": "x/1e-12", "FromBaseToUnitFunc": "x*1e-12", @@ -119,8 +150,8 @@ "SingularName": "TonnePerCubicCentimeter", "PluralName": "TonnesPerCubicCentimeter", "BaseUnits": { - "L": "Centimeter", - "M": "Tonne" + "M": "Tonne", + "L": "Centimeter" }, "FromUnitToBaseFunc": "x/1e-9", "FromBaseToUnitFunc": "x*1e-9", @@ -135,8 +166,8 @@ "SingularName": "TonnePerCubicMeter", "PluralName": "TonnesPerCubicMeter", "BaseUnits": { - "L": "Meter", - "M": "Tonne" + "M": "Tonne", + "L": "Meter" }, "FromUnitToBaseFunc": "x/0.001", "FromBaseToUnitFunc": "x*0.001", @@ -148,79 +179,60 @@ ] }, { - "SingularName": "SlugPerCubicFoot", - "PluralName": "SlugsPerCubicFoot", - "BaseUnits": { - "L": "Foot", - "M": "Slug" - }, - "FromUnitToBaseFunc": "x*515.378818", - "FromBaseToUnitFunc": "x*0.00194032033", - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "slug/ft³" ] - } - ] - }, - { - "SingularName": "GramPerLiter", - "PluralName": "GramsPerLiter", + "SingularName": "PoundPerCubicInch", + "PluralName": "PoundsPerCubicInch", "BaseUnits": { - "L": "Meter", - "M": "Kilogram" + "M": "Pound", + "L": "Inch" }, - "FromUnitToBaseFunc": "x", - "FromBaseToUnitFunc": "x", - "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "FromUnitToBaseFunc": "x/3.6127298147753e-5", + "FromBaseToUnitFunc": "x*3.6127298147753e-5", + "Prefixes": [ "Kilo" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/L"] + "Abbreviations": [ "lb/in³" ], + "AbbreviationsWithPrefixes": [ "kip/in³" ] } ] }, { - "SingularName": "GramPerDeciliter", - "PluralName": "GramsPerDeciLiter", + "SingularName": "PoundPerCubicFoot", + "PluralName": "PoundsPerCubicFoot", "BaseUnits": { - "L": "Meter", - "M": "Kilogram" + "M": "Pound", + "L": "Foot" }, - "FromUnitToBaseFunc": "x/1e-1", - "FromBaseToUnitFunc": "x*1e-1", - "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "FromUnitToBaseFunc": "x/0.062427961", + "FromBaseToUnitFunc": "x*0.062427961", + "Prefixes": [ "Kilo" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/dL" ] + "Abbreviations": [ "lb/ft³" ], + "AbbreviationsWithPrefixes": [ "kip/ft³" ] } ] }, { - "SingularName": "GramPerMilliliter", - "PluralName": "GramsPerMilliliter", + "SingularName": "SlugPerCubicFoot", + "PluralName": "SlugsPerCubicFoot", "BaseUnits": { - "L": "Meter", - "M": "Kilogram" + "M": "Slug", + "L": "Foot" }, - "FromUnitToBaseFunc": "x/1e-3", - "FromBaseToUnitFunc": "x*1e-3", - "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "FromUnitToBaseFunc": "x*515.378818", + "FromBaseToUnitFunc": "x*0.00194032033", "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/mL" ] + "Abbreviations": [ "slug/ft³" ] } ] }, { "SingularName": "PoundPerUSGallon", - "PluralName": "PoundsPerUSGallon", - "BaseUnits": { - "L": "Meter", - "M": "Kilogram" - }, + "PluralName": "PoundsPerUSGallon", "FromUnitToBaseFunc": "x*1.19826427e2", "FromBaseToUnitFunc": "x/1.19826427e2", "Localization": [ @@ -232,11 +244,7 @@ }, { "SingularName": "PoundPerImperialGallon", - "PluralName": "PoundsPerImperialGallon", - "BaseUnits": { - "L": "Meter", - "M": "Kilogram" - }, + "PluralName": "PoundsPerImperialGallon", "FromUnitToBaseFunc": "x*9.9776398e1", "FromBaseToUnitFunc": "x/9.9776398e1", "Localization": [ @@ -245,22 +253,6 @@ "Abbreviations": [ "ppg (imp.)" ] } ] - }, - { - "SingularName": "KilogramPerLiter", - "PluralName": "KilogramsPerLiter", - "BaseUnits": { - "L": "Decimeter", - "M": "Kilogram" - }, - "FromUnitToBaseFunc": "x*1e3", - "FromBaseToUnitFunc": "x/1e3", - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "kg/L" ] - } - ] } ] } diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs index 3aacc9c8e4..db7fb96b12 100644 --- a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -28,29 +28,30 @@ namespace UnitsNet.Tests.CustomCode { public class MassConcentrationTests : MassConcentrationTestsBase { + #region Unit Conversion Coefficients protected override double PicogramsPerLiterInOneKilogramPerCubicMeter => 1e12; - protected override double PicogramsPerDeciLiterInOneKilogramPerCubicMeter => 1e11; + protected override double PicogramsPerDeciliterInOneKilogramPerCubicMeter => 1e11; protected override double NanogramsPerLiterInOneKilogramPerCubicMeter => 1e9; protected override double PicogramsPerMilliliterInOneKilogramPerCubicMeter => 1e9; protected override double MicrogramsPerCubicMeterInOneKilogramPerCubicMeter => 1e9; - protected override double NanogramsPerDeciLiterInOneKilogramPerCubicMeter => 1e8; + protected override double NanogramsPerDeciliterInOneKilogramPerCubicMeter => 1e8; protected override double NanogramsPerMilliliterInOneKilogramPerCubicMeter => 1e6; protected override double MicrogramsPerLiterInOneKilogramPerCubicMeter => 1e6; protected override double MilligramsPerCubicMeterInOneKilogramPerCubicMeter => 1e6; - protected override double MicrogramsPerDeciLiterInOneKilogramPerCubicMeter => 1e5; + protected override double MicrogramsPerDeciliterInOneKilogramPerCubicMeter => 1e5; protected override double MicrogramsPerMilliliterInOneKilogramPerCubicMeter => 1e3; protected override double GramsPerCubicMeterInOneKilogramPerCubicMeter => 1e3; protected override double MilligramsPerLiterInOneKilogramPerCubicMeter => 1e3; protected override double CentigramsPerLiterInOneKilogramPerCubicMeter => 1e2; - protected override double MilligramsPerDeciLiterInOneKilogramPerCubicMeter => 1e2; + protected override double MilligramsPerDeciliterInOneKilogramPerCubicMeter => 1e2; protected override double MilligramsPerMilliliterInOneKilogramPerCubicMeter => 1; protected override double GramsPerLiterInOneKilogramPerCubicMeter => 1; protected override double KilogramsPerCubicMeterInOneKilogramPerCubicMeter => 1; - protected override double CentigramsPerDeciLiterInOneKilogramPerCubicMeter => 1e1; - protected override double DecigramsPerDeciLiterInOneKilogramPerCubicMeter => 1; + protected override double CentigramsPerDeciliterInOneKilogramPerCubicMeter => 1e1; + protected override double DecigramsPerDeciliterInOneKilogramPerCubicMeter => 1; protected override double DecigramsPerLiterInOneKilogramPerCubicMeter => 1e1; protected override double CentigramsPerMilliliterInOneKilogramPerCubicMeter => 1e-1; - protected override double GramsPerDeciLiterInOneKilogramPerCubicMeter => 1e-1; + protected override double GramsPerDeciliterInOneKilogramPerCubicMeter => 1e-1; protected override double DecigramsPerMilliliterInOneKilogramPerCubicMeter => 1e-2; protected override double KilogramsPerLiterInOneKilogramPerCubicMeter => 1e-3; protected override double GramsPerMilliliterInOneKilogramPerCubicMeter => 1e-3; @@ -68,11 +69,10 @@ public class MassConcentrationTests : MassConcentrationTestsBase protected override double PoundsPerCubicFootInOneKilogramPerCubicMeter => 6.242796e-2; protected override double PoundsPerCubicInchInOneKilogramPerCubicMeter => 3.61272923e-5; protected override double PoundsPerUSGallonInOneKilogramPerCubicMeter => 8.3454045e-3; - protected override double SlugsPerCubicFootInOneKilogramPerCubicMeter => 0.00194032; + protected override double SlugsPerCubicFootInOneKilogramPerCubicMeter => 0.00194032; + #endregion -// private static double MolarMassOfEthanolInGramsPerMole = 46.06844; - private static double DensityOfEthanolInKgPerCubicMeter = 789; - private static double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; + private const double DensityOfEthanolInKgPerCubicMeter = 789; [Fact] public static void MassConcentrationTimesVolumeEqualsMass() @@ -121,11 +121,30 @@ public void MassConcentrationFromVolumeConcentrationAndDensity() [Fact] public void MassConcentrationFromVolumeConcentrationEthanol() { + const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); AssertEx.EqualTolerance(23.03422, massConcentration.GramsPerLiter, GramsPerCubicMeterTolerance); } + +// [Fact] +// public void DefaultSIUnitIsKgPerCubicMeter() +// { +// var massConcentration = new MassConcentration(1, UnitSystem.SI); +// Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, massConcentration.Unit); // MassConcentration.BaseUnit = KilogramPerCubicMeter +// } + + [Fact] + public void DefaultUnitTypeRespectedForCustomUnitSystem() + { + UnitSystem customSystem = new UnitSystem(new BaseUnits(LengthUnit.Millimeter, MassUnit.Gram, DurationUnit.Millisecond, + ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeCelsius, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela)); + + var massConcentration = new MassConcentration(1, customSystem); + Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, massConcentration.Unit); + } + } } diff --git a/UnitsNet.Tests/CustomCode/MassFractionTests.cs b/UnitsNet.Tests/CustomCode/MassFractionTests.cs index 33fd53957c..3b9ed89b92 100644 --- a/UnitsNet.Tests/CustomCode/MassFractionTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFractionTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class MassFractionTests : MassFractionTestsBase { + #region Unit Conversion Coefficients protected override double KilogramsPerKiloGramInOneDecimalFraction => 1; protected override double HectogramsPerKiloGramInOneDecimalFraction => 10; protected override double DecagramsPerKiloGramInOneDecimalFraction => 1E2; @@ -47,21 +48,17 @@ public class MassFractionTests : MassFractionTestsBase protected override double MicrogramsPerGramInOneDecimalFraction => 1E6; protected override double NanogramsPerGramInOneDecimalFraction => 1E9; - - protected override double DecimalFractionsInOneDecimalFraction => 1; - - protected override double PercentInOneDecimalFraction => 100; - - protected override double PartsPerBillionInOneDecimalFraction => 1e9; - - protected override double PartsPerMillionInOneDecimalFraction => 1e6; - protected override double PartsPerThousandInOneDecimalFraction => 1e3; - + protected override double PartsPerMillionInOneDecimalFraction => 1e6; + protected override double PartsPerBillionInOneDecimalFraction => 1e9; protected override double PartsPerTrillionInOneDecimalFraction => 1e12; + protected override double DecimalFractionsInOneDecimalFraction => 1; + protected override double PercentInOneDecimalFraction => 100; + #endregion + [Fact] - public void MassFractionFromMassesConsturctedCorrectly() + public void MassFractionFromMassesConstructedCorrectly() { var one_kg = Mass.FromKilograms(1); var two_kg = Mass.FromKilograms(2); @@ -79,6 +76,7 @@ public void TotalMassFromMassFraction() var totalMass = massFraction.GetTotalMass(componentMass); AssertEx.EqualTolerance(2, totalMass.Kilograms, KilogramsPerKiloGramTolerance); } + [Fact] public void ComponentMassFromMassFraction() { diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs index fdb1bb0d2b..488d144edb 100644 --- a/UnitsNet.Tests/CustomCode/MolarMassTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs @@ -42,8 +42,8 @@ public class MolarMassTests : MolarMassTestsBase protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12; protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; - private static double MolarMassOfOxygen = 15.999; - private static double MolesInTenGramsOfOxygen = 0.6250390649415588; + private const double MolarMassOfOxygen = 15.999; + private const double MolesInTenGramsOfOxygen = 0.6250390649415588; [Fact] public void TenGramsOfOxygenContainExpectedNumberOfMoles() diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 599c686e2e..9248b948db 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -28,6 +28,7 @@ namespace UnitsNet.Tests.CustomCode { public class MolarityTests : MolarityTestsBase { + #region Unit Conversion Coefficients protected override double CentimolesPerLiterInOneMolesPerCubicMeter => 1e-1; protected override double DecimolesPerLiterInOneMolesPerCubicMeter => 1e-2; protected override double MolesPerLiterInOneMolesPerCubicMeter => 1e-3; @@ -42,17 +43,12 @@ public class MolarityTests : MolarityTestsBase protected override double MicromolarInOneMolesPerCubicMeter => 1E3; protected override double NanomolarInOneMolesPerCubicMeter => 1E6; protected override double PicomolarInOneMolesPerCubicMeter => 1E9; + #endregion - private static double MolarMassHClInGramsPerMole = 36.46; - private static double MassOfSubstanceInGrams = 5; - private static double VolumeOfSolutionInLiters = 1.2; - - private static double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M - private static double ExpectedConcentrationInKgPerCubicMeter = 4.16667; + private const double MolarMassHClInGramsPerMole = 36.46; - private static double MolarMassOfEthanolInGramsPerMole = 46.06844; - private static double DensityOfEthanolInKgPerCubicMeter = 789; - private static double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; + private const double MolarMassOfEthanolInGramsPerMole = 46.06844; + private const double DensityOfEthanolInKgPerCubicMeter = 789; [Fact] public void ExpectMassConcentrationConvertedToMolarityCorrectly() @@ -77,6 +73,9 @@ public void ExpectMolarityConvertedToMassConcentrationCorrectly() [Fact] public void HClSolutionMolarityIsEqualToExpected() { + const double MassOfSubstanceInGrams = 5; + const double VolumeOfSolutionInLiters = 1.2; + const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M // same test is performed in AmountOfSubstanceTests var molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); var substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); @@ -90,6 +89,8 @@ public void HClSolutionMolarityIsEqualToExpected() [Fact] public void HClSolutionConcentrationIsEqualToExpected() { + const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M + const double ExpectedConcentrationInKgPerCubicMeter = 4.16667; var molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); var molarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); @@ -100,6 +101,7 @@ public void HClSolutionConcentrationIsEqualToExpected() [Fact] public void TenPercentHClSolutionMolarityIsEqualToExpected() { + const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M var originalMolarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); Molarity tenPercentMolarity = originalMolarity * VolumeConcentration.FromPercent(10); @@ -109,6 +111,7 @@ public void TenPercentHClSolutionMolarityIsEqualToExpected() [Fact] public void MolarityFromVolumeConcentrationEthanol() { + const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); var molarMass = MolarMass.FromGramsPerMole(MolarMassOfEthanolInGramsPerMole); var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); diff --git a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs index 81ef12e658..329517284d 100644 --- a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs @@ -27,6 +27,7 @@ namespace UnitsNet.Tests.CustomCode { public class VolumeConcentrationTests : VolumeConcentrationTestsBase { + #region Unit Conversion Coefficients protected override double LitersPerMililiterInOneDecimalFraction => 1E-3; protected override double DecilitersPerMililiterInOneDecimalFraction => 1E-2; protected override double CentilitersPerMililiterInOneDecimalFraction => 1E-1; @@ -42,23 +43,18 @@ public class VolumeConcentrationTests : VolumeConcentrationTestsBase protected override double MicrolitersPerLiterInOneDecimalFraction => 1E6; protected override double NanolitersPerLiterInOneDecimalFraction => 1E9; protected override double PicolitersPerLiterInOneDecimalFraction => 1E12; - - protected override double DecimalFractionsInOneDecimalFraction => 1; - - protected override double PercentInOneDecimalFraction => 100; - - protected override double PartsPerBillionInOneDecimalFraction => 1e9; - - protected override double PartsPerMillionInOneDecimalFraction => 1e6; - + protected override double PartsPerThousandInOneDecimalFraction => 1e3; - + protected override double PartsPerMillionInOneDecimalFraction => 1e6; + protected override double PartsPerBillionInOneDecimalFraction => 1e9; protected override double PartsPerTrillionInOneDecimalFraction => 1e12; - private static double MolarMassOfEthanolInGramsPerMole = 46.06844; - private static double DensityOfEthanolInKgPerCubicMeter = 789; - private static double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; + protected override double DecimalFractionsInOneDecimalFraction => 1; + protected override double PercentInOneDecimalFraction => 100; + #endregion + private const double MolarMassOfEthanolInGramsPerMole = 46.06844; + private const double DensityOfEthanolInKgPerCubicMeter = 789; [Fact] public void MassConcentrationFromVolumeConcentrationAndDensity() @@ -83,6 +79,7 @@ public void VolumeConcentrationFromMassConcentrationAndDensity() [Fact] public void VolumeConcentrationFromMolarityOfEthanol() { + const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; var molarity = Molarity.FromMolesPerLiter(0.5); var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); var molarMass = MolarMass.FromGramsPerMole(MolarMassOfEthanolInGramsPerMole); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs index 73873cc907..d95c353678 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs @@ -159,9 +159,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) #region Conversion Properties /// - /// Get MassConcentration in CentigramsPerDeciLiter. + /// Get MassConcentration in CentigramsPerDeciliter. /// - public double CentigramsPerDeciLiter => As(MassConcentrationUnit.CentigramPerDeciliter); + public double CentigramsPerDeciliter => As(MassConcentrationUnit.CentigramPerDeciliter); /// /// Get MassConcentration in CentigramsPerLiter. @@ -174,9 +174,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) public double CentigramsPerMilliliter => As(MassConcentrationUnit.CentigramPerMilliliter); /// - /// Get MassConcentration in DecigramsPerDeciLiter. + /// Get MassConcentration in DecigramsPerDeciliter. /// - public double DecigramsPerDeciLiter => As(MassConcentrationUnit.DecigramPerDeciliter); + public double DecigramsPerDeciliter => As(MassConcentrationUnit.DecigramPerDeciliter); /// /// Get MassConcentration in DecigramsPerLiter. @@ -204,9 +204,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) public double GramsPerCubicMillimeter => As(MassConcentrationUnit.GramPerCubicMillimeter); /// - /// Get MassConcentration in GramsPerDeciLiter. + /// Get MassConcentration in GramsPerDeciliter. /// - public double GramsPerDeciLiter => As(MassConcentrationUnit.GramPerDeciliter); + public double GramsPerDeciliter => As(MassConcentrationUnit.GramPerDeciliter); /// /// Get MassConcentration in GramsPerLiter. @@ -254,9 +254,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) public double MicrogramsPerCubicMeter => As(MassConcentrationUnit.MicrogramPerCubicMeter); /// - /// Get MassConcentration in MicrogramsPerDeciLiter. + /// Get MassConcentration in MicrogramsPerDeciliter. /// - public double MicrogramsPerDeciLiter => As(MassConcentrationUnit.MicrogramPerDeciliter); + public double MicrogramsPerDeciliter => As(MassConcentrationUnit.MicrogramPerDeciliter); /// /// Get MassConcentration in MicrogramsPerLiter. @@ -274,9 +274,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) public double MilligramsPerCubicMeter => As(MassConcentrationUnit.MilligramPerCubicMeter); /// - /// Get MassConcentration in MilligramsPerDeciLiter. + /// Get MassConcentration in MilligramsPerDeciliter. /// - public double MilligramsPerDeciLiter => As(MassConcentrationUnit.MilligramPerDeciliter); + public double MilligramsPerDeciliter => As(MassConcentrationUnit.MilligramPerDeciliter); /// /// Get MassConcentration in MilligramsPerLiter. @@ -289,9 +289,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) public double MilligramsPerMilliliter => As(MassConcentrationUnit.MilligramPerMilliliter); /// - /// Get MassConcentration in NanogramsPerDeciLiter. + /// Get MassConcentration in NanogramsPerDeciliter. /// - public double NanogramsPerDeciLiter => As(MassConcentrationUnit.NanogramPerDeciliter); + public double NanogramsPerDeciliter => As(MassConcentrationUnit.NanogramPerDeciliter); /// /// Get MassConcentration in NanogramsPerLiter. @@ -304,9 +304,9 @@ private MassConcentration(double numericValue, MassConcentrationUnit unit) public double NanogramsPerMilliliter => As(MassConcentrationUnit.NanogramPerMilliliter); /// - /// Get MassConcentration in PicogramsPerDeciLiter. + /// Get MassConcentration in PicogramsPerDeciliter. /// - public double PicogramsPerDeciLiter => As(MassConcentrationUnit.PicogramPerDeciliter); + public double PicogramsPerDeciliter => As(MassConcentrationUnit.PicogramPerDeciliter); /// /// Get MassConcentration in PicogramsPerLiter. @@ -389,11 +389,11 @@ public static string GetAbbreviation(MassConcentrationUnit unit, [CanBeNull] str #region Static Factory Methods /// - /// Get MassConcentration from CentigramsPerDeciLiter. + /// Get MassConcentration from CentigramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromCentigramsPerDeciLiter(double centigramsperdeciliter) + public static MassConcentration FromCentigramsPerDeciliter(double centigramsperdeciliter) { double value = (double) centigramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.CentigramPerDeciliter); @@ -419,11 +419,11 @@ public static MassConcentration FromCentigramsPerMilliliter(double centigramsper return new MassConcentration(value, MassConcentrationUnit.CentigramPerMilliliter); } /// - /// Get MassConcentration from DecigramsPerDeciLiter. + /// Get MassConcentration from DecigramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromDecigramsPerDeciLiter(double decigramsperdeciliter) + public static MassConcentration FromDecigramsPerDeciliter(double decigramsperdeciliter) { double value = (double) decigramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.DecigramPerDeciliter); @@ -479,11 +479,11 @@ public static MassConcentration FromGramsPerCubicMillimeter(double gramspercubic return new MassConcentration(value, MassConcentrationUnit.GramPerCubicMillimeter); } /// - /// Get MassConcentration from GramsPerDeciLiter. + /// Get MassConcentration from GramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromGramsPerDeciLiter(double gramsperdeciliter) + public static MassConcentration FromGramsPerDeciliter(double gramsperdeciliter) { double value = (double) gramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.GramPerDeciliter); @@ -579,11 +579,11 @@ public static MassConcentration FromMicrogramsPerCubicMeter(double microgramsper return new MassConcentration(value, MassConcentrationUnit.MicrogramPerCubicMeter); } /// - /// Get MassConcentration from MicrogramsPerDeciLiter. + /// Get MassConcentration from MicrogramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromMicrogramsPerDeciLiter(double microgramsperdeciliter) + public static MassConcentration FromMicrogramsPerDeciliter(double microgramsperdeciliter) { double value = (double) microgramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.MicrogramPerDeciliter); @@ -619,11 +619,11 @@ public static MassConcentration FromMilligramsPerCubicMeter(double milligramsper return new MassConcentration(value, MassConcentrationUnit.MilligramPerCubicMeter); } /// - /// Get MassConcentration from MilligramsPerDeciLiter. + /// Get MassConcentration from MilligramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromMilligramsPerDeciLiter(double milligramsperdeciliter) + public static MassConcentration FromMilligramsPerDeciliter(double milligramsperdeciliter) { double value = (double) milligramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.MilligramPerDeciliter); @@ -649,11 +649,11 @@ public static MassConcentration FromMilligramsPerMilliliter(double milligramsper return new MassConcentration(value, MassConcentrationUnit.MilligramPerMilliliter); } /// - /// Get MassConcentration from NanogramsPerDeciLiter. + /// Get MassConcentration from NanogramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromNanogramsPerDeciLiter(double nanogramsperdeciliter) + public static MassConcentration FromNanogramsPerDeciliter(double nanogramsperdeciliter) { double value = (double) nanogramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.NanogramPerDeciliter); @@ -679,11 +679,11 @@ public static MassConcentration FromNanogramsPerMilliliter(double nanogramspermi return new MassConcentration(value, MassConcentrationUnit.NanogramPerMilliliter); } /// - /// Get MassConcentration from PicogramsPerDeciLiter. + /// Get MassConcentration from PicogramsPerDeciliter. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassConcentration FromPicogramsPerDeciLiter(double picogramsperdeciliter) + public static MassConcentration FromPicogramsPerDeciliter(double picogramsperdeciliter) { double value = (double) picogramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.PicogramPerDeciliter); diff --git a/UnitsNet/CustomCode/Quantities/Density.extra.cs b/UnitsNet/CustomCode/Quantities/Density.extra.cs index 4a98f59f70..e569cefac5 100644 --- a/UnitsNet/CustomCode/Quantities/Density.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Density.extra.cs @@ -1,12 +1,37 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. +using System; using UnitsNet.Units; namespace UnitsNet { public partial struct Density { + /// + /// Gets from this . + /// + /// + /// + [Obsolete("This method is deprecated in favor of MassConcentration.ToMolarity(MolarMass).")] + public Molarity ToMolarity(Mass molecularWeight) + { + return Molarity.FromMolesPerCubicMeter(KilogramsPerCubicMeter / molecularWeight.Kilograms); + } + + #region Static Methods + + /// + /// Get from . + /// + /// + [Obsolete("This method is deprecated in favor of MassConcentration.FromMolarity(Molarity, MolarMass).")] + public static Density FromMolarity(Molarity molarity, Mass molecularWeight) + { + return new Density(molarity.MolesPerCubicMeter * molecularWeight.Kilograms, DensityUnit.KilogramPerCubicMeter); + } + + #endregion /// Get from times . public static Mass operator *(Density density, Volume volume) @@ -38,5 +63,12 @@ public partial struct Density return new SpecificWeight(density.KilogramsPerCubicMeter * acceleration.MetersPerSecondSquared, SpecificWeightUnit.NewtonPerCubicMeter); } + /// Get from divided by . + /// + [Obsolete("This operator is deprecated in favor of MassConcentration.op_Division(MassConcentration, MolarMass).")] + public static Molarity operator /(Density density, Mass molecularWeight) + { + return new Molarity(density.KilogramsPerCubicMeter / molecularWeight.Kilograms, MolarityUnit.MolesPerCubicMeter); + } } } diff --git a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs index 372fa12817..53af6eeb15 100644 --- a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs @@ -5,6 +5,28 @@ namespace UnitsNet { public partial struct Molarity { + /// + /// Construct from divided by . + /// + /// + [Obsolete("This constructor will be removed in favor of operator overload MassConcentration.op_Division(MassConcentration,MolarMass).")] + public Molarity(Density density, Mass molecularWeight) + : this() + { + _value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms; + _unit = MolarityUnit.MolesPerCubicMeter; + } + + /// + /// Get a from this . + /// + /// + /// + [Obsolete("This method will be removed in favor of ToMassConcentration(MolarMass)")] + public Density ToDensity(Mass molecularWeight) + { + return Density.FromKilogramsPerCubicMeter(MolesPerCubicMeter * molecularWeight.Kilograms); + } /// /// Get a from this . @@ -27,7 +49,17 @@ public VolumeConcentration ToVolumeConcentration(Density componentDensity, Molar #region Static Methods - + /// + /// Get from . + /// + /// + /// + [Obsolete("Use MassConcentration / MolarMass operator overload instead.")] + public static Molarity FromDensity(Density density, Mass molecularWeight) + { + return density / molecularWeight; + } + /// /// Get from and known component and . /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs index ec8280fe72..dae56520ee 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs @@ -59,12 +59,12 @@ static MassConcentration() new UnitInfo(MassConcentrationUnit.DecigramPerDeciliter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.DecigramPerLiter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.DecigramPerMilliliter, BaseUnits.Undefined), - new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), - new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), - new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), - new UnitInfo(MassConcentrationUnit.GramPerDeciliter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), - new UnitInfo(MassConcentrationUnit.GramPerLiter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), - new UnitInfo(MassConcentrationUnit.GramPerMilliliter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerDeciliter, new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerLiter, new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerMilliliter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)), new UnitInfo(MassConcentrationUnit.KilogramPerCubicCentimeter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMeter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMillimeter, BaseUnits.Undefined), @@ -87,8 +87,8 @@ static MassConcentration() new UnitInfo(MassConcentrationUnit.PicogramPerMilliliter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.PoundPerCubicFoot, new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)), new UnitInfo(MassConcentrationUnit.PoundPerCubicInch, new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)), - new UnitInfo(MassConcentrationUnit.PoundPerImperialGallon, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), - new UnitInfo(MassConcentrationUnit.PoundPerUSGallon, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.PoundPerImperialGallon, BaseUnits.Undefined), + new UnitInfo(MassConcentrationUnit.PoundPerUSGallon, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.SlugPerCubicFoot, new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug)), new UnitInfo(MassConcentrationUnit.TonnePerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne)), new UnitInfo(MassConcentrationUnit.TonnePerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne)), @@ -206,9 +206,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) #region Conversion Properties /// - /// Get MassConcentration in CentigramsPerDeciLiter. + /// Get MassConcentration in CentigramsPerDeciliter. /// - public double CentigramsPerDeciLiter => As(MassConcentrationUnit.CentigramPerDeciliter); + public double CentigramsPerDeciliter => As(MassConcentrationUnit.CentigramPerDeciliter); /// /// Get MassConcentration in CentigramsPerLiter. @@ -221,9 +221,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) public double CentigramsPerMilliliter => As(MassConcentrationUnit.CentigramPerMilliliter); /// - /// Get MassConcentration in DecigramsPerDeciLiter. + /// Get MassConcentration in DecigramsPerDeciliter. /// - public double DecigramsPerDeciLiter => As(MassConcentrationUnit.DecigramPerDeciliter); + public double DecigramsPerDeciliter => As(MassConcentrationUnit.DecigramPerDeciliter); /// /// Get MassConcentration in DecigramsPerLiter. @@ -251,9 +251,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) public double GramsPerCubicMillimeter => As(MassConcentrationUnit.GramPerCubicMillimeter); /// - /// Get MassConcentration in GramsPerDeciLiter. + /// Get MassConcentration in GramsPerDeciliter. /// - public double GramsPerDeciLiter => As(MassConcentrationUnit.GramPerDeciliter); + public double GramsPerDeciliter => As(MassConcentrationUnit.GramPerDeciliter); /// /// Get MassConcentration in GramsPerLiter. @@ -301,9 +301,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) public double MicrogramsPerCubicMeter => As(MassConcentrationUnit.MicrogramPerCubicMeter); /// - /// Get MassConcentration in MicrogramsPerDeciLiter. + /// Get MassConcentration in MicrogramsPerDeciliter. /// - public double MicrogramsPerDeciLiter => As(MassConcentrationUnit.MicrogramPerDeciliter); + public double MicrogramsPerDeciliter => As(MassConcentrationUnit.MicrogramPerDeciliter); /// /// Get MassConcentration in MicrogramsPerLiter. @@ -321,9 +321,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) public double MilligramsPerCubicMeter => As(MassConcentrationUnit.MilligramPerCubicMeter); /// - /// Get MassConcentration in MilligramsPerDeciLiter. + /// Get MassConcentration in MilligramsPerDeciliter. /// - public double MilligramsPerDeciLiter => As(MassConcentrationUnit.MilligramPerDeciliter); + public double MilligramsPerDeciliter => As(MassConcentrationUnit.MilligramPerDeciliter); /// /// Get MassConcentration in MilligramsPerLiter. @@ -336,9 +336,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) public double MilligramsPerMilliliter => As(MassConcentrationUnit.MilligramPerMilliliter); /// - /// Get MassConcentration in NanogramsPerDeciLiter. + /// Get MassConcentration in NanogramsPerDeciliter. /// - public double NanogramsPerDeciLiter => As(MassConcentrationUnit.NanogramPerDeciliter); + public double NanogramsPerDeciliter => As(MassConcentrationUnit.NanogramPerDeciliter); /// /// Get MassConcentration in NanogramsPerLiter. @@ -351,9 +351,9 @@ public MassConcentration(double numericValue, UnitSystem unitSystem) public double NanogramsPerMilliliter => As(MassConcentrationUnit.NanogramPerMilliliter); /// - /// Get MassConcentration in PicogramsPerDeciLiter. + /// Get MassConcentration in PicogramsPerDeciliter. /// - public double PicogramsPerDeciLiter => As(MassConcentrationUnit.PicogramPerDeciliter); + public double PicogramsPerDeciliter => As(MassConcentrationUnit.PicogramPerDeciliter); /// /// Get MassConcentration in PicogramsPerLiter. @@ -435,10 +435,10 @@ public static string GetAbbreviation(MassConcentrationUnit unit, [CanBeNull] IFo #region Static Factory Methods /// - /// Get MassConcentration from CentigramsPerDeciLiter. + /// Get MassConcentration from CentigramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromCentigramsPerDeciLiter(QuantityValue centigramsperdeciliter) + public static MassConcentration FromCentigramsPerDeciliter(QuantityValue centigramsperdeciliter) { double value = (double) centigramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.CentigramPerDeciliter); @@ -462,10 +462,10 @@ public static MassConcentration FromCentigramsPerMilliliter(QuantityValue centig return new MassConcentration(value, MassConcentrationUnit.CentigramPerMilliliter); } /// - /// Get MassConcentration from DecigramsPerDeciLiter. + /// Get MassConcentration from DecigramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromDecigramsPerDeciLiter(QuantityValue decigramsperdeciliter) + public static MassConcentration FromDecigramsPerDeciliter(QuantityValue decigramsperdeciliter) { double value = (double) decigramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.DecigramPerDeciliter); @@ -516,10 +516,10 @@ public static MassConcentration FromGramsPerCubicMillimeter(QuantityValue gramsp return new MassConcentration(value, MassConcentrationUnit.GramPerCubicMillimeter); } /// - /// Get MassConcentration from GramsPerDeciLiter. + /// Get MassConcentration from GramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromGramsPerDeciLiter(QuantityValue gramsperdeciliter) + public static MassConcentration FromGramsPerDeciliter(QuantityValue gramsperdeciliter) { double value = (double) gramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.GramPerDeciliter); @@ -606,10 +606,10 @@ public static MassConcentration FromMicrogramsPerCubicMeter(QuantityValue microg return new MassConcentration(value, MassConcentrationUnit.MicrogramPerCubicMeter); } /// - /// Get MassConcentration from MicrogramsPerDeciLiter. + /// Get MassConcentration from MicrogramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromMicrogramsPerDeciLiter(QuantityValue microgramsperdeciliter) + public static MassConcentration FromMicrogramsPerDeciliter(QuantityValue microgramsperdeciliter) { double value = (double) microgramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.MicrogramPerDeciliter); @@ -642,10 +642,10 @@ public static MassConcentration FromMilligramsPerCubicMeter(QuantityValue millig return new MassConcentration(value, MassConcentrationUnit.MilligramPerCubicMeter); } /// - /// Get MassConcentration from MilligramsPerDeciLiter. + /// Get MassConcentration from MilligramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromMilligramsPerDeciLiter(QuantityValue milligramsperdeciliter) + public static MassConcentration FromMilligramsPerDeciliter(QuantityValue milligramsperdeciliter) { double value = (double) milligramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.MilligramPerDeciliter); @@ -669,10 +669,10 @@ public static MassConcentration FromMilligramsPerMilliliter(QuantityValue millig return new MassConcentration(value, MassConcentrationUnit.MilligramPerMilliliter); } /// - /// Get MassConcentration from NanogramsPerDeciLiter. + /// Get MassConcentration from NanogramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromNanogramsPerDeciLiter(QuantityValue nanogramsperdeciliter) + public static MassConcentration FromNanogramsPerDeciliter(QuantityValue nanogramsperdeciliter) { double value = (double) nanogramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.NanogramPerDeciliter); @@ -696,10 +696,10 @@ public static MassConcentration FromNanogramsPerMilliliter(QuantityValue nanogra return new MassConcentration(value, MassConcentrationUnit.NanogramPerMilliliter); } /// - /// Get MassConcentration from PicogramsPerDeciLiter. + /// Get MassConcentration from PicogramsPerDeciliter. /// /// If value is NaN or Infinity. - public static MassConcentration FromPicogramsPerDeciLiter(QuantityValue picogramsperdeciliter) + public static MassConcentration FromPicogramsPerDeciliter(QuantityValue picogramsperdeciliter) { double value = (double) picogramsperdeciliter; return new MassConcentration(value, MassConcentrationUnit.PicogramPerDeciliter); From 40c16380a88a6802baac23bcbc9c759f4a8efe06 Mon Sep 17 00:00:00 2001 From: lipchev Date: Mon, 15 Apr 2019 23:41:13 +0300 Subject: [PATCH 4/8] Removed Molarity.Molar as redundant (added abbreviation instead) - MolesPerLiter: fixed the BaseUnits (default) to Deimeter/Mole - Molar: removed in favor of using the alternative abbreviation 'M" - MolarityTests - OneMilliMolarFromStringParsedCorrectly skipped while awaiting fix for #344 --- Common/UnitDefinitions/Molarity.json | 21 +---- UnitsNet.Tests/CustomCode/MolarityTests.cs | 8 +- .../Molarity.WindowsRuntimeComponent.g.cs | 85 ------------------ .../GeneratedCode/UnitAbbreviationsCache.g.cs | 7 +- .../GeneratedCode/Units/MolarityUnit.g.cs | 5 -- .../Quantities/Molarity.NetFramework.g.cs | 87 +------------------ .../GeneratedCode/UnitAbbreviationsCache.g.cs | 7 +- .../GeneratedCode/Units/MolarityUnit.g.cs | 5 -- 8 files changed, 6 insertions(+), 219 deletions(-) diff --git a/Common/UnitDefinitions/Molarity.json b/Common/UnitDefinitions/Molarity.json index 7fcd7afcc1..30a55110e0 100644 --- a/Common/UnitDefinitions/Molarity.json +++ b/Common/UnitDefinitions/Molarity.json @@ -29,7 +29,7 @@ "SingularName": "MolesPerLiter", "PluralName": "MolesPerLiter", "BaseUnits": { - "L": "Meter", + "L": "Decimeter", "N": "Mole" }, "FromUnitToBaseFunc": "x/1e-3", @@ -38,24 +38,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "mol/L"] - } - ] - }, - { - "SingularName": "Molar", - "PluralName": "Molar", - "BaseUnits": { - "L": "Meter", - "N": "Mole" - }, - "FromUnitToBaseFunc": "x/1e-3", - "FromBaseToUnitFunc": "x*1e-3", - "Prefixes": [ "Pico", "Nano", "Micro", "Milli"], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "M"] + "Abbreviations": [ "mol/L", "M"] } ] } diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 9248b948db..3bb38a2f53 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -37,12 +37,6 @@ public class MolarityTests : MolarityTestsBase protected override double MicromolesPerLiterInOneMolesPerCubicMeter => 1e3; protected override double NanomolesPerLiterInOneMolesPerCubicMeter => 1e6; protected override double PicomolesPerLiterInOneMolesPerCubicMeter => 1e9; - - protected override double MolarInOneMolesPerCubicMeter => 1E-3; - protected override double MillimolarInOneMolesPerCubicMeter => 1; - protected override double MicromolarInOneMolesPerCubicMeter => 1E3; - protected override double NanomolarInOneMolesPerCubicMeter => 1E6; - protected override double PicomolarInOneMolesPerCubicMeter => 1E9; #endregion private const double MolarMassHClInGramsPerMole = 36.46; @@ -126,7 +120,7 @@ public void OneMolarFromStringParsedCorrectly() Assert.Equal(Molarity.Parse("1M"), Molarity.Parse("1 mol/L")); } - [Fact] + [Fact(Skip = "Awaiting fix for https://github.com/angularsen/UnitsNet/issues/344")] public void OneMilliMolarFromStringParsedCorrectly() { var one_mM = Molarity.Parse("1000 mM"); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs index 95383777c4..3fa75e3c27 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Molarity.WindowsRuntimeComponent.g.cs @@ -168,31 +168,16 @@ private Molarity(double numericValue, MolarityUnit unit) /// public double DecimolesPerLiter => As(MolarityUnit.DecimolesPerLiter); - /// - /// Get Molarity in Micromolar. - /// - public double Micromolar => As(MolarityUnit.Micromolar); - /// /// Get Molarity in MicromolesPerLiter. /// public double MicromolesPerLiter => As(MolarityUnit.MicromolesPerLiter); - /// - /// Get Molarity in Millimolar. - /// - public double Millimolar => As(MolarityUnit.Millimolar); - /// /// Get Molarity in MillimolesPerLiter. /// public double MillimolesPerLiter => As(MolarityUnit.MillimolesPerLiter); - /// - /// Get Molarity in Molar. - /// - public double Molar => As(MolarityUnit.Molar); - /// /// Get Molarity in MolesPerCubicMeter. /// @@ -203,21 +188,11 @@ private Molarity(double numericValue, MolarityUnit unit) /// public double MolesPerLiter => As(MolarityUnit.MolesPerLiter); - /// - /// Get Molarity in Nanomolar. - /// - public double Nanomolar => As(MolarityUnit.Nanomolar); - /// /// Get Molarity in NanomolesPerLiter. /// public double NanomolesPerLiter => As(MolarityUnit.NanomolesPerLiter); - /// - /// Get Molarity in Picomolar. - /// - public double Picomolar => As(MolarityUnit.Picomolar); - /// /// Get Molarity in PicomolesPerLiter. /// @@ -274,16 +249,6 @@ public static Molarity FromDecimolesPerLiter(double decimolesperliter) return new Molarity(value, MolarityUnit.DecimolesPerLiter); } /// - /// Get Molarity from Micromolar. - /// - /// If value is NaN or Infinity. - [Windows.Foundation.Metadata.DefaultOverload] - public static Molarity FromMicromolar(double micromolar) - { - double value = (double) micromolar; - return new Molarity(value, MolarityUnit.Micromolar); - } - /// /// Get Molarity from MicromolesPerLiter. /// /// If value is NaN or Infinity. @@ -294,16 +259,6 @@ public static Molarity FromMicromolesPerLiter(double micromolesperliter) return new Molarity(value, MolarityUnit.MicromolesPerLiter); } /// - /// Get Molarity from Millimolar. - /// - /// If value is NaN or Infinity. - [Windows.Foundation.Metadata.DefaultOverload] - public static Molarity FromMillimolar(double millimolar) - { - double value = (double) millimolar; - return new Molarity(value, MolarityUnit.Millimolar); - } - /// /// Get Molarity from MillimolesPerLiter. /// /// If value is NaN or Infinity. @@ -314,16 +269,6 @@ public static Molarity FromMillimolesPerLiter(double millimolesperliter) return new Molarity(value, MolarityUnit.MillimolesPerLiter); } /// - /// Get Molarity from Molar. - /// - /// If value is NaN or Infinity. - [Windows.Foundation.Metadata.DefaultOverload] - public static Molarity FromMolar(double molar) - { - double value = (double) molar; - return new Molarity(value, MolarityUnit.Molar); - } - /// /// Get Molarity from MolesPerCubicMeter. /// /// If value is NaN or Infinity. @@ -344,16 +289,6 @@ public static Molarity FromMolesPerLiter(double molesperliter) return new Molarity(value, MolarityUnit.MolesPerLiter); } /// - /// Get Molarity from Nanomolar. - /// - /// If value is NaN or Infinity. - [Windows.Foundation.Metadata.DefaultOverload] - public static Molarity FromNanomolar(double nanomolar) - { - double value = (double) nanomolar; - return new Molarity(value, MolarityUnit.Nanomolar); - } - /// /// Get Molarity from NanomolesPerLiter. /// /// If value is NaN or Infinity. @@ -364,16 +299,6 @@ public static Molarity FromNanomolesPerLiter(double nanomolesperliter) return new Molarity(value, MolarityUnit.NanomolesPerLiter); } /// - /// Get Molarity from Picomolar. - /// - /// If value is NaN or Infinity. - [Windows.Foundation.Metadata.DefaultOverload] - public static Molarity FromPicomolar(double picomolar) - { - double value = (double) picomolar; - return new Molarity(value, MolarityUnit.Picomolar); - } - /// /// Get Molarity from PicomolesPerLiter. /// /// If value is NaN or Infinity. @@ -676,16 +601,11 @@ private double AsBaseUnit() { case MolarityUnit.CentimolesPerLiter: return (_value/1e-3) * 1e-2d; case MolarityUnit.DecimolesPerLiter: return (_value/1e-3) * 1e-1d; - case MolarityUnit.Micromolar: return (_value/1e-3) * 1e-6d; case MolarityUnit.MicromolesPerLiter: return (_value/1e-3) * 1e-6d; - case MolarityUnit.Millimolar: return (_value/1e-3) * 1e-3d; case MolarityUnit.MillimolesPerLiter: return (_value/1e-3) * 1e-3d; - case MolarityUnit.Molar: return _value/1e-3; case MolarityUnit.MolesPerCubicMeter: return _value; case MolarityUnit.MolesPerLiter: return _value/1e-3; - case MolarityUnit.Nanomolar: return (_value/1e-3) * 1e-9d; case MolarityUnit.NanomolesPerLiter: return (_value/1e-3) * 1e-9d; - case MolarityUnit.Picomolar: return (_value/1e-3) * 1e-12d; case MolarityUnit.PicomolesPerLiter: return (_value/1e-3) * 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to base units."); @@ -703,16 +623,11 @@ private double AsBaseNumericType(MolarityUnit unit) { case MolarityUnit.CentimolesPerLiter: return (baseUnitValue*1e-3) / 1e-2d; case MolarityUnit.DecimolesPerLiter: return (baseUnitValue*1e-3) / 1e-1d; - case MolarityUnit.Micromolar: return (baseUnitValue*1e-3) / 1e-6d; case MolarityUnit.MicromolesPerLiter: return (baseUnitValue*1e-3) / 1e-6d; - case MolarityUnit.Millimolar: return (baseUnitValue*1e-3) / 1e-3d; case MolarityUnit.MillimolesPerLiter: return (baseUnitValue*1e-3) / 1e-3d; - case MolarityUnit.Molar: return baseUnitValue*1e-3; case MolarityUnit.MolesPerCubicMeter: return baseUnitValue; case MolarityUnit.MolesPerLiter: return baseUnitValue*1e-3; - case MolarityUnit.Nanomolar: return (baseUnitValue*1e-3) / 1e-9d; case MolarityUnit.NanomolesPerLiter: return (baseUnitValue*1e-3) / 1e-9d; - case MolarityUnit.Picomolar: return (baseUnitValue*1e-3) / 1e-12d; case MolarityUnit.PicomolesPerLiter: return (baseUnitValue*1e-3) / 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index e26494652b..bfc7571a23 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -722,16 +722,11 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MolarEntropyUnit), (int)MolarEntropyUnit.MegajoulePerMoleKelvin, new string[]{"MJ/(mol*K)"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.CentimolesPerLiter, new string[]{"cmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.DecimolesPerLiter, new string[]{"dmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Micromolar, new string[]{"µM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MicromolesPerLiter, new string[]{"µmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Millimolar, new string[]{"mM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MillimolesPerLiter, new string[]{"mmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Molar, new string[]{"M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerCubicMeter, new string[]{"mol/m³"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerLiter, new string[]{"mol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Nanomolar, new string[]{"nM"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerLiter, new string[]{"mol/L", "M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.NanomolesPerLiter, new string[]{"nmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Picomolar, new string[]{"pM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.PicomolesPerLiter, new string[]{"pmol/L"}), ("en-US", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"cg/mol"}), ("ru-RU", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"сг/моль"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs index 089593b8ec..be257aec48 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MolarityUnit.g.cs @@ -28,16 +28,11 @@ public enum MolarityUnit Undefined = 0, CentimolesPerLiter, DecimolesPerLiter, - Micromolar, MicromolesPerLiter, - Millimolar, MillimolesPerLiter, - Molar, MolesPerCubicMeter, MolesPerLiter, - Nanomolar, NanomolesPerLiter, - Picomolar, PicomolesPerLiter, } diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs index da2980b2ae..ecd13c4733 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs @@ -55,16 +55,11 @@ static Molarity() new UnitInfo[] { new UnitInfo(MolarityUnit.CentimolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.DecimolesPerLiter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.Micromolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MicromolesPerLiter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.Millimolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MillimolesPerLiter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.Molar, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), new UnitInfo(MolarityUnit.MolesPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), - new UnitInfo(MolarityUnit.MolesPerLiter, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), - new UnitInfo(MolarityUnit.Nanomolar, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.MolesPerLiter, new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Mole)), new UnitInfo(MolarityUnit.NanomolesPerLiter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.Picomolar, BaseUnits.Undefined), new UnitInfo(MolarityUnit.PicomolesPerLiter, BaseUnits.Undefined), }, BaseUnit, Zero, BaseDimensions); @@ -188,31 +183,16 @@ public Molarity(double numericValue, UnitSystem unitSystem) /// public double DecimolesPerLiter => As(MolarityUnit.DecimolesPerLiter); - /// - /// Get Molarity in Micromolar. - /// - public double Micromolar => As(MolarityUnit.Micromolar); - /// /// Get Molarity in MicromolesPerLiter. /// public double MicromolesPerLiter => As(MolarityUnit.MicromolesPerLiter); - /// - /// Get Molarity in Millimolar. - /// - public double Millimolar => As(MolarityUnit.Millimolar); - /// /// Get Molarity in MillimolesPerLiter. /// public double MillimolesPerLiter => As(MolarityUnit.MillimolesPerLiter); - /// - /// Get Molarity in Molar. - /// - public double Molar => As(MolarityUnit.Molar); - /// /// Get Molarity in MolesPerCubicMeter. /// @@ -223,21 +203,11 @@ public Molarity(double numericValue, UnitSystem unitSystem) /// public double MolesPerLiter => As(MolarityUnit.MolesPerLiter); - /// - /// Get Molarity in Nanomolar. - /// - public double Nanomolar => As(MolarityUnit.Nanomolar); - /// /// Get Molarity in NanomolesPerLiter. /// public double NanomolesPerLiter => As(MolarityUnit.NanomolesPerLiter); - /// - /// Get Molarity in Picomolar. - /// - public double Picomolar => As(MolarityUnit.Picomolar); - /// /// Get Molarity in PicomolesPerLiter. /// @@ -291,15 +261,6 @@ public static Molarity FromDecimolesPerLiter(QuantityValue decimolesperliter) return new Molarity(value, MolarityUnit.DecimolesPerLiter); } /// - /// Get Molarity from Micromolar. - /// - /// If value is NaN or Infinity. - public static Molarity FromMicromolar(QuantityValue micromolar) - { - double value = (double) micromolar; - return new Molarity(value, MolarityUnit.Micromolar); - } - /// /// Get Molarity from MicromolesPerLiter. /// /// If value is NaN or Infinity. @@ -309,15 +270,6 @@ public static Molarity FromMicromolesPerLiter(QuantityValue micromolesperliter) return new Molarity(value, MolarityUnit.MicromolesPerLiter); } /// - /// Get Molarity from Millimolar. - /// - /// If value is NaN or Infinity. - public static Molarity FromMillimolar(QuantityValue millimolar) - { - double value = (double) millimolar; - return new Molarity(value, MolarityUnit.Millimolar); - } - /// /// Get Molarity from MillimolesPerLiter. /// /// If value is NaN or Infinity. @@ -327,15 +279,6 @@ public static Molarity FromMillimolesPerLiter(QuantityValue millimolesperliter) return new Molarity(value, MolarityUnit.MillimolesPerLiter); } /// - /// Get Molarity from Molar. - /// - /// If value is NaN or Infinity. - public static Molarity FromMolar(QuantityValue molar) - { - double value = (double) molar; - return new Molarity(value, MolarityUnit.Molar); - } - /// /// Get Molarity from MolesPerCubicMeter. /// /// If value is NaN or Infinity. @@ -354,15 +297,6 @@ public static Molarity FromMolesPerLiter(QuantityValue molesperliter) return new Molarity(value, MolarityUnit.MolesPerLiter); } /// - /// Get Molarity from Nanomolar. - /// - /// If value is NaN or Infinity. - public static Molarity FromNanomolar(QuantityValue nanomolar) - { - double value = (double) nanomolar; - return new Molarity(value, MolarityUnit.Nanomolar); - } - /// /// Get Molarity from NanomolesPerLiter. /// /// If value is NaN or Infinity. @@ -372,15 +306,6 @@ public static Molarity FromNanomolesPerLiter(QuantityValue nanomolesperliter) return new Molarity(value, MolarityUnit.NanomolesPerLiter); } /// - /// Get Molarity from Picomolar. - /// - /// If value is NaN or Infinity. - public static Molarity FromPicomolar(QuantityValue picomolar) - { - double value = (double) picomolar; - return new Molarity(value, MolarityUnit.Picomolar); - } - /// /// Get Molarity from PicomolesPerLiter. /// /// If value is NaN or Infinity. @@ -820,16 +745,11 @@ private double GetValueInBaseUnit() { case MolarityUnit.CentimolesPerLiter: return (_value/1e-3) * 1e-2d; case MolarityUnit.DecimolesPerLiter: return (_value/1e-3) * 1e-1d; - case MolarityUnit.Micromolar: return (_value/1e-3) * 1e-6d; case MolarityUnit.MicromolesPerLiter: return (_value/1e-3) * 1e-6d; - case MolarityUnit.Millimolar: return (_value/1e-3) * 1e-3d; case MolarityUnit.MillimolesPerLiter: return (_value/1e-3) * 1e-3d; - case MolarityUnit.Molar: return _value/1e-3; case MolarityUnit.MolesPerCubicMeter: return _value; case MolarityUnit.MolesPerLiter: return _value/1e-3; - case MolarityUnit.Nanomolar: return (_value/1e-3) * 1e-9d; case MolarityUnit.NanomolesPerLiter: return (_value/1e-3) * 1e-9d; - case MolarityUnit.Picomolar: return (_value/1e-3) * 1e-12d; case MolarityUnit.PicomolesPerLiter: return (_value/1e-3) * 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to base units."); @@ -847,16 +767,11 @@ private double GetValueAs(MolarityUnit unit) { case MolarityUnit.CentimolesPerLiter: return (baseUnitValue*1e-3) / 1e-2d; case MolarityUnit.DecimolesPerLiter: return (baseUnitValue*1e-3) / 1e-1d; - case MolarityUnit.Micromolar: return (baseUnitValue*1e-3) / 1e-6d; case MolarityUnit.MicromolesPerLiter: return (baseUnitValue*1e-3) / 1e-6d; - case MolarityUnit.Millimolar: return (baseUnitValue*1e-3) / 1e-3d; case MolarityUnit.MillimolesPerLiter: return (baseUnitValue*1e-3) / 1e-3d; - case MolarityUnit.Molar: return baseUnitValue*1e-3; case MolarityUnit.MolesPerCubicMeter: return baseUnitValue; case MolarityUnit.MolesPerLiter: return baseUnitValue*1e-3; - case MolarityUnit.Nanomolar: return (baseUnitValue*1e-3) / 1e-9d; case MolarityUnit.NanomolesPerLiter: return (baseUnitValue*1e-3) / 1e-9d; - case MolarityUnit.Picomolar: return (baseUnitValue*1e-3) / 1e-12d; case MolarityUnit.PicomolesPerLiter: return (baseUnitValue*1e-3) / 1e-12d; default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index bb5b890854..e48b72bb82 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -722,16 +722,11 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MolarEntropyUnit), (int)MolarEntropyUnit.MegajoulePerMoleKelvin, new string[]{"MJ/(mol*K)"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.CentimolesPerLiter, new string[]{"cmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.DecimolesPerLiter, new string[]{"dmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Micromolar, new string[]{"µM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MicromolesPerLiter, new string[]{"µmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Millimolar, new string[]{"mM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MillimolesPerLiter, new string[]{"mmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Molar, new string[]{"M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerCubicMeter, new string[]{"mol/m³"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerLiter, new string[]{"mol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Nanomolar, new string[]{"nM"}), + ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MolesPerLiter, new string[]{"mol/L", "M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.NanomolesPerLiter, new string[]{"nmol/L"}), - ("en-US", typeof(MolarityUnit), (int)MolarityUnit.Picomolar, new string[]{"pM"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.PicomolesPerLiter, new string[]{"pmol/L"}), ("en-US", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"cg/mol"}), ("ru-RU", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"сг/моль"}), diff --git a/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs index 089593b8ec..be257aec48 100644 --- a/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MolarityUnit.g.cs @@ -28,16 +28,11 @@ public enum MolarityUnit Undefined = 0, CentimolesPerLiter, DecimolesPerLiter, - Micromolar, MicromolesPerLiter, - Millimolar, MillimolesPerLiter, - Molar, MolesPerCubicMeter, MolesPerLiter, - Nanomolar, NanomolesPerLiter, - Picomolar, PicomolesPerLiter, } From 0171b0ac4c81dd4d32d993169f4360d6cdd6ef1c Mon Sep 17 00:00:00 2001 From: lipchev Date: Tue, 16 Apr 2019 00:55:35 +0300 Subject: [PATCH 5/8] Added a KnownQuantities class - added a KnownQuantities class with a few constants that were used in multiple tests - replaced the usages in MassConcentrationTests MolarityTests * VolumeConcentrationTests --- UnitsNet.Tests/CustomCode/KnownQuantities.cs | 10 ++++++++++ .../CustomCode/MassConcentrationTests.cs | 16 +++++++--------- UnitsNet.Tests/CustomCode/MolarityTests.cs | 12 ++++-------- .../CustomCode/VolumeConcentrationTests.cs | 9 +++------ 4 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 UnitsNet.Tests/CustomCode/KnownQuantities.cs diff --git a/UnitsNet.Tests/CustomCode/KnownQuantities.cs b/UnitsNet.Tests/CustomCode/KnownQuantities.cs new file mode 100644 index 0000000000..f8843535a8 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/KnownQuantities.cs @@ -0,0 +1,10 @@ +namespace UnitsNet.Tests.CustomCode +{ + public static class KnownQuantities + { + public const double DensityOfEthanolInKgPerCubicMeter = 789; + public const double MolarMassOfEthanolInGramsPerMole = 46.06844; + + public const double MolarMassHClInGramsPerMole = 36.46; + } +} diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs index db7fb96b12..1e669dbb6c 100644 --- a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -72,8 +72,6 @@ public class MassConcentrationTests : MassConcentrationTestsBase protected override double SlugsPerCubicFootInOneKilogramPerCubicMeter => 0.00194032; #endregion - private const double DensityOfEthanolInKgPerCubicMeter = 789; - [Fact] public static void MassConcentrationTimesVolumeEqualsMass() { @@ -122,19 +120,19 @@ public void MassConcentrationFromVolumeConcentrationAndDensity() public void MassConcentrationFromVolumeConcentrationEthanol() { const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; - var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); + var density = Density.FromKilogramsPerCubicMeter(KnownQuantities.DensityOfEthanolInKgPerCubicMeter); var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); AssertEx.EqualTolerance(23.03422, massConcentration.GramsPerLiter, GramsPerCubicMeterTolerance); } -// [Fact] -// public void DefaultSIUnitIsKgPerCubicMeter() -// { -// var massConcentration = new MassConcentration(1, UnitSystem.SI); -// Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, massConcentration.Unit); // MassConcentration.BaseUnit = KilogramPerCubicMeter -// } + [Fact(Skip = "No BaseUnit defined: see https://github.com/angularsen/UnitsNet/issues/651")] + public void DefaultSIUnitIsKgPerCubicMeter() + { + var massConcentration = new MassConcentration(1, UnitSystem.SI); + Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, massConcentration.Unit); // MassConcentration.BaseUnit = KilogramPerCubicMeter + } [Fact] public void DefaultUnitTypeRespectedForCustomUnitSystem() diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 3bb38a2f53..0065462401 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -39,10 +39,6 @@ public class MolarityTests : MolarityTestsBase protected override double PicomolesPerLiterInOneMolesPerCubicMeter => 1e9; #endregion - private const double MolarMassHClInGramsPerMole = 36.46; - - private const double MolarMassOfEthanolInGramsPerMole = 46.06844; - private const double DensityOfEthanolInKgPerCubicMeter = 789; [Fact] public void ExpectMassConcentrationConvertedToMolarityCorrectly() @@ -71,7 +67,7 @@ public void HClSolutionMolarityIsEqualToExpected() const double VolumeOfSolutionInLiters = 1.2; const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M // same test is performed in AmountOfSubstanceTests - var molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); + var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassHClInGramsPerMole); var substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); var volumeSolution = Volume.FromLiters(VolumeOfSolutionInLiters); AmountOfSubstance amountOfSubstance = substanceMass / molarMass; @@ -85,7 +81,7 @@ public void HClSolutionConcentrationIsEqualToExpected() { const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M const double ExpectedConcentrationInKgPerCubicMeter = 4.16667; - var molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); + var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassHClInGramsPerMole); var molarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); MassConcentration concentration = molarity * molarMass; @@ -106,8 +102,8 @@ public void TenPercentHClSolutionMolarityIsEqualToExpected() public void MolarityFromVolumeConcentrationEthanol() { const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; - var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); - var molarMass = MolarMass.FromGramsPerMole(MolarMassOfEthanolInGramsPerMole); + var density = Density.FromKilogramsPerCubicMeter(KnownQuantities.DensityOfEthanolInKgPerCubicMeter); + var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassOfEthanolInGramsPerMole); var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); Molarity molarity = volumeConcentration.ToMolarity(density, molarMass); // volumeConcentration * density / molarMass diff --git a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs index 329517284d..bad35ddffc 100644 --- a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs @@ -52,10 +52,7 @@ public class VolumeConcentrationTests : VolumeConcentrationTestsBase protected override double DecimalFractionsInOneDecimalFraction => 1; protected override double PercentInOneDecimalFraction => 100; #endregion - - private const double MolarMassOfEthanolInGramsPerMole = 46.06844; - private const double DensityOfEthanolInKgPerCubicMeter = 789; - + [Fact] public void MassConcentrationFromVolumeConcentrationAndDensity() { @@ -81,8 +78,8 @@ public void VolumeConcentrationFromMolarityOfEthanol() { const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; var molarity = Molarity.FromMolesPerLiter(0.5); - var density = Density.FromKilogramsPerCubicMeter(DensityOfEthanolInKgPerCubicMeter); - var molarMass = MolarMass.FromGramsPerMole(MolarMassOfEthanolInGramsPerMole); + var density = Density.FromKilogramsPerCubicMeter(KnownQuantities.DensityOfEthanolInKgPerCubicMeter); + var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassOfEthanolInGramsPerMole); VolumeConcentration volumeConcentration = molarity.ToVolumeConcentration(density, molarMass); AssertEx.EqualTolerance(VolumeConcentration_0_5M_Ethanol, volumeConcentration.MillilitersPerLiter, MillilitersPerLiterTolerance); From 69a0ee18f3e2a81a658d0858e5bc28bb5206f8e5 Mon Sep 17 00:00:00 2001 From: lipchev Date: Thu, 18 Apr 2019 12:07:54 +0300 Subject: [PATCH 6/8] Testing with Theory + InlineData - converted two of the MassConcentration tests to using Theory + InlineData --- .../CustomCode/MassConcentrationTests.cs | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs index 1e669dbb6c..7ae4c02012 100644 --- a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -69,14 +69,21 @@ public class MassConcentrationTests : MassConcentrationTestsBase protected override double PoundsPerCubicFootInOneKilogramPerCubicMeter => 6.242796e-2; protected override double PoundsPerCubicInchInOneKilogramPerCubicMeter => 3.61272923e-5; protected override double PoundsPerUSGallonInOneKilogramPerCubicMeter => 8.3454045e-3; - protected override double SlugsPerCubicFootInOneKilogramPerCubicMeter => 0.00194032; + protected override double SlugsPerCubicFootInOneKilogramPerCubicMeter => 0.00194032; #endregion - [Fact] - public static void MassConcentrationTimesVolumeEqualsMass() + [Theory] + [InlineData(2, MassConcentrationUnit.KilogramPerCubicMeter, 3, VolumeUnit.CubicMeter, 6, MassUnit.Kilogram)] + public static void MassConcentrationTimesVolumeEqualsMass( + double massConcValue, MassConcentrationUnit massConcUnit, + double volumeValue, VolumeUnit volumeUnit, + double expectedMassValue, MassUnit expectedMassUnit, double tolerance= 1e-5) { - Mass mass = MassConcentration.FromKilogramsPerCubicMeter(2) * Volume.FromCubicMeters(3); - Assert.Equal(mass, Mass.FromKilograms(6)); + var massConcentration = new MassConcentration(massConcValue, massConcUnit); + var volume = new Volume(volumeValue, volumeUnit); + + Mass mass = massConcentration * volume; + AssertEx.EqualTolerance(mass.As(expectedMassUnit), expectedMassValue, tolerance); } [Fact] @@ -96,14 +103,18 @@ public void ExpectMolarityConvertedToMassConcentrationCorrectly() AssertEx.EqualTolerance(60.02, concentration.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); } - [Fact] - public void ExpectMassConcentrationConvertedToMolarityCorrectly() + [Theory] + [InlineData(60.02, MassConcentrationUnit.KilogramPerCubicMeter, 58.443, MolarMassUnit.GramPerMole, 1026.98355, MolarityUnit.MolesPerCubicMeter)] + public void ExpectMassConcentrationConvertedToMolarityCorrectly( + double massConcValue, MassConcentrationUnit massConcUnit, + double molarMassValue, MolarMassUnit molarMassUnit, + double expectedMolarityValue, MolarityUnit expectedMolarityUnit, double tolerance = 1e-5) { - var concentration = MassConcentration.FromKilogramsPerCubicMeter(60.02); - var molarMass = MolarMass.FromGramsPerMole(58.443); + var massConcentration = new MassConcentration(massConcValue, massConcUnit); + var molarMass = new MolarMass(molarMassValue, molarMassUnit); - Molarity molarity = concentration.ToMolarity(molarMass); // molarity / molarMass - AssertEx.EqualTolerance(1026.98355, molarity.MolesPerCubicMeter, KilogramsPerCubicMeterTolerance); + Molarity molarity = massConcentration.ToMolarity(molarMass); // molarity / molarMass + AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerance); } [Fact] @@ -115,7 +126,7 @@ public void MassConcentrationFromVolumeConcentrationAndDensity() MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); // volumeConcentration * density AssertEx.EqualTolerance(5, massConcentration.GramsPerCubicMeter, GramsPerCubicMeterTolerance); } - + [Fact] public void MassConcentrationFromVolumeConcentrationEthanol() { @@ -143,6 +154,6 @@ public void DefaultUnitTypeRespectedForCustomUnitSystem() var massConcentration = new MassConcentration(1, customSystem); Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, massConcentration.Unit); } - + } } From 0f6e251804a32320b78d0204a09cd6199678ef56 Mon Sep 17 00:00:00 2001 From: lipchev Date: Thu, 18 Apr 2019 22:58:27 +0300 Subject: [PATCH 7/8] Tests refactoring (Theory + InlineData) - removed BaseUnits from GramPerDeciliter(not exact + overlap), kept it in GramPerLiter (as exact & non-overlapping), also kept it for GramPerMilliliter(exact + overlapping) because I thought it would be useful to have at least one such case for future testing - moved the Mass/MolarMass operator to the Mass class (removing the MolarMass.extra) - all tests refactored using Theory + Inline Data - moved one or two tests to the appropriate .Test file - removed a few redundant tests --- Common/UnitDefinitions/MassConcentration.json | 24 +-- Common/UnitDefinitions/MassFraction.json | 4 +- .../UnitDefinitions/VolumeConcentration.json | 4 +- .../CustomCode/AmountOfSubstanceTests.cs | 88 ++++++----- UnitsNet.Tests/CustomCode/KnownQuantities.cs | 2 + .../CustomCode/MassConcentrationTests.cs | 80 +++++----- .../CustomCode/MassFractionTests.cs | 25 +-- UnitsNet.Tests/CustomCode/MassTests.cs | 17 +++ UnitsNet.Tests/CustomCode/MolarMassTests.cs | 13 +- UnitsNet.Tests/CustomCode/MolarityTests.cs | 102 ++++++------- .../CustomCode/VolumeConcentrationTests.cs | 58 ++++--- ...Concentration.WindowsRuntimeComponent.g.cs | 4 +- .../MassFraction.WindowsRuntimeComponent.g.cs | 126 +++++++-------- .../GeneratedCode/UnitAbbreviationsCache.g.cs | 46 +++--- .../GeneratedCode/Units/MassFractionUnit.g.cs | 18 +-- UnitsNet/CustomCode/Quantities/Mass.extra.cs | 6 + .../CustomCode/Quantities/MolarMass.extra.cs | 15 -- .../MassConcentration.NetFramework.g.cs | 8 +- .../Quantities/MassFraction.NetFramework.g.cs | 144 +++++++++--------- .../GeneratedCode/UnitAbbreviationsCache.g.cs | 46 +++--- .../GeneratedCode/Units/MassFractionUnit.g.cs | 18 +-- 21 files changed, 412 insertions(+), 436 deletions(-) delete mode 100644 UnitsNet/CustomCode/Quantities/MolarMass.extra.cs diff --git a/Common/UnitDefinitions/MassConcentration.json b/Common/UnitDefinitions/MassConcentration.json index 296229b229..062645ff69 100644 --- a/Common/UnitDefinitions/MassConcentration.json +++ b/Common/UnitDefinitions/MassConcentration.json @@ -82,11 +82,7 @@ }, { "SingularName": "GramPerDeciliter", - "PluralName": "GramsPerDeciliter", - "BaseUnits": { - "M": "Gram", - "L": "Decimeter" - }, + "PluralName": "GramsPerDeciliter", "FromUnitToBaseFunc": "x/1e-1", "FromBaseToUnitFunc": "x*1e-1", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], @@ -106,7 +102,7 @@ }, "FromUnitToBaseFunc": "x", "FromBaseToUnitFunc": "x", - "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci", "Kilo" ], "Localization": [ { "Culture": "en-US", @@ -114,22 +110,6 @@ } ] }, - { - "SingularName": "KilogramPerLiter", - "PluralName": "KilogramsPerLiter", - "BaseUnits": { - "M": "Kilogram", - "L": "Decimeter" - }, - "FromUnitToBaseFunc": "x*1e3", - "FromBaseToUnitFunc": "x/1e3", - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "kg/L" ] - } - ] - }, { "SingularName": "TonnePerCubicMillimeter", "PluralName": "TonnesPerCubicMillimeter", diff --git a/Common/UnitDefinitions/MassFraction.json b/Common/UnitDefinitions/MassFraction.json index 53f741eb66..fdfc016073 100644 --- a/Common/UnitDefinitions/MassFraction.json +++ b/Common/UnitDefinitions/MassFraction.json @@ -30,8 +30,8 @@ ] }, { - "SingularName": "GramPerKiloGram", - "PluralName": "GramsPerKiloGram", + "SingularName": "GramPerKilogram", + "PluralName": "GramsPerKilogram", "FromUnitToBaseFunc": "x/1e3", "FromBaseToUnitFunc": "x*1e3", "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ], diff --git a/Common/UnitDefinitions/VolumeConcentration.json b/Common/UnitDefinitions/VolumeConcentration.json index 6983544d4b..de56f8491f 100644 --- a/Common/UnitDefinitions/VolumeConcentration.json +++ b/Common/UnitDefinitions/VolumeConcentration.json @@ -25,7 +25,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "l/l" ] + "Abbreviations": [ "L/L" ] } ] }, @@ -38,7 +38,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "l/ml" ] + "Abbreviations": [ "L/mL" ] } ] }, diff --git a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs index f11d0f9a9a..6b4494a0a6 100644 --- a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs +++ b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs @@ -21,6 +21,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using UnitsNet.Units; using Xunit; namespace UnitsNet.Tests.CustomCode @@ -43,17 +44,6 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase protected override double PoundMolesInOneMole => 0.002204622621848776; protected override double MegamolesInOneMole => 1e-6; - private static double MolarMassOfOxygen = 15.999; - private static double MolesInTenGramsOfOxygen = 0.6250390649415588; - - - private static double MolarMassHClInGramsPerMole = 36.46; - private static double MassOfSubstanceInGrams = 5; - private static double VolumeOfSolutionInLiters = 1.2; - - private static double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M - - [Fact] public void NumberOfParticlesInOneMoleEqualsAvogadroConstant() { @@ -70,45 +60,63 @@ public void NumberOfParticlesInTwoMolesIsDoubleAvogadroConstant() Assert.Equal(AmountOfSubstance.AvogadroConstant * 2, numberOfParticles); } - [Fact] - public void TenMolesOfOxygenToMassEqualToExpected() + [Theory] + [InlineData(10, AmountOfSubstanceUnit.Mole, + KnownQuantities.MolarMassOfOxygen, MolarMassUnit.GramPerMole, + 10 * KnownQuantities.MolarMassOfOxygen, MassUnit.Gram)] // 10 Moles of Oxygen weight 10 times as much as 1 Mole of Oxygen (MolarMass) + public void MassFromAmountOfSubstanceAndMolarMass( + double amountOfSubstanceValue, AmountOfSubstanceUnit amountOfSubstanceUnit, + double molarMassValue, MolarMassUnit molarMassUnit, + double expectedMass, MassUnit expectedMassUnit, double tolerence = 1e-5) { - AmountOfSubstance tenMoles = AmountOfSubstance.FromMoles(10); - MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassOfOxygen); - AssertEx.EqualTolerance(10 * MolarMassOfOxygen, (tenMoles * molarMass).Grams, MolesTolerance); - } + AmountOfSubstance amountOfSubstance = new AmountOfSubstance(amountOfSubstanceValue, amountOfSubstanceUnit); + MolarMass molarMass = new MolarMass(molarMassValue, molarMassUnit); + + Mass mass = amountOfSubstance * molarMass; - [Fact] - public void TenGramsOfOxygenToMolesEqualToExpected() - { - Mass tenGrams = Mass.FromGrams(10); - MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassOfOxygen); - AssertEx.EqualTolerance(MolesInTenGramsOfOxygen, (tenGrams / molarMass).Moles, MolesTolerance); + AssertEx.EqualTolerance(expectedMass, mass.As(expectedMassUnit), tolerence); } - [Fact] - public void HClSolutionVolumeIsEqualToExpected() + [Theory] + [InlineData(5, MassUnit.Gram, + KnownQuantities.MolarMassHClInGramsPerMole, MolarMassUnit.GramPerMole, + 1.2, VolumeUnit.Liter, + 0.1142805, MolarityUnit.MolesPerLiter)] // molarity(HCl) = 5g / (1.2L * 36.46) = 0.114 mol/l = 0.114 M + public void MolarityFromComponentMassAndSolutionVolume( + double componentMassValue, MassUnit componentMassUnit, + double componentMolarMassValue, MolarMassUnit componentMolarMassUnit, + double solutionVolumeValue, VolumeUnit solutionVolumeUnit, + double expectedMolarityValue, MolarityUnit expectedMolarityUnit, double tolerence = 1e-5) { - MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); - Mass substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); - AmountOfSubstance amountOfSubstance = substanceMass / molarMass; - Molarity molarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); + var componentMass = new Mass(componentMassValue, componentMassUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, componentMolarMassUnit); + var volumeSolution = new Volume(solutionVolumeValue, solutionVolumeUnit); + + AmountOfSubstance amountOfSubstance = componentMass / componentMolarMass; + Molarity molarity = amountOfSubstance / volumeSolution; - Volume volumeSolution = amountOfSubstance / molarity; - AssertEx.EqualTolerance(VolumeOfSolutionInLiters, volumeSolution.Liters, MolesTolerance); + AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerence); } - [Fact] - public void HClSolutionMolarityIsEqualToExpected() + [Theory] + [InlineData(5, MassUnit.Gram, + KnownQuantities.MolarMassHClInGramsPerMole, MolarMassUnit.GramPerMole, + 0.1142805, MolarityUnit.MolesPerLiter, + 1.2, VolumeUnit.Liter)] // 1.2 L of solution required for obtaining 0.1142805 Moles/L from 5g HCl + public void VolumeSolutionFromComponentMassAndDesiredConcentration( + double componentMassValue, MassUnit componentMassUnit, + double componentMolarMassValue, MolarMassUnit componentMolarMassUnit, + double desiredMolarityValue, MolarityUnit desiredMolarityUnit, + double expectedSolutionVolumeValue, VolumeUnit expectedSolutionVolumeUnit, double tolerence = 1e-5) { - MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassHClInGramsPerMole); - Mass substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); - AmountOfSubstance amountOfSubstance = substanceMass / molarMass; - Volume volumeSolution = Volume.FromLiters(VolumeOfSolutionInLiters); + var componentMass = new Mass(componentMassValue, componentMassUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, componentMolarMassUnit); + var desiredMolarity = new Molarity(desiredMolarityValue, desiredMolarityUnit); - Molarity molarity = amountOfSubstance / volumeSolution; - AssertEx.EqualTolerance(ExpectedMolarityMolesPerLiter, molarity.MolesPerLiter, MolesTolerance); - } + AmountOfSubstance amountOfSubstance = componentMass / componentMolarMass; + Volume volumeSolution = amountOfSubstance / desiredMolarity; + AssertEx.EqualTolerance(expectedSolutionVolumeValue, volumeSolution.As(expectedSolutionVolumeUnit), tolerence); + } } } diff --git a/UnitsNet.Tests/CustomCode/KnownQuantities.cs b/UnitsNet.Tests/CustomCode/KnownQuantities.cs index f8843535a8..0a3b8a9b37 100644 --- a/UnitsNet.Tests/CustomCode/KnownQuantities.cs +++ b/UnitsNet.Tests/CustomCode/KnownQuantities.cs @@ -2,6 +2,8 @@ { public static class KnownQuantities { + public const double MolarMassOfOxygen = 15.9994; + public const double DensityOfEthanolInKgPerCubicMeter = 789; public const double MolarMassOfEthanolInGramsPerMole = 46.06844; diff --git a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs index 7ae4c02012..b4fc2cb9fd 100644 --- a/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -73,39 +73,10 @@ public class MassConcentrationTests : MassConcentrationTestsBase #endregion [Theory] - [InlineData(2, MassConcentrationUnit.KilogramPerCubicMeter, 3, VolumeUnit.CubicMeter, 6, MassUnit.Kilogram)] - public static void MassConcentrationTimesVolumeEqualsMass( - double massConcValue, MassConcentrationUnit massConcUnit, - double volumeValue, VolumeUnit volumeUnit, - double expectedMassValue, MassUnit expectedMassUnit, double tolerance= 1e-5) - { - var massConcentration = new MassConcentration(massConcValue, massConcUnit); - var volume = new Volume(volumeValue, volumeUnit); - - Mass mass = massConcentration * volume; - AssertEx.EqualTolerance(mass.As(expectedMassUnit), expectedMassValue, tolerance); - } - - [Fact] - public static void VolumeTimesMassConcentrationEqualsMass() - { - Mass mass = Volume.FromCubicMeters(3) * MassConcentration.FromKilogramsPerCubicMeter(2); - Assert.Equal(mass, Mass.FromKilograms(6)); - } - - [Fact] - public void ExpectMolarityConvertedToMassConcentrationCorrectly() - { - var molarity = Molarity.FromMolesPerLiter(1.02698355); - var molarMass = MolarMass.FromGramsPerMole(58.443); - - MassConcentration concentration = molarity.ToMassConcentration(molarMass); // molarity * molarMass - AssertEx.EqualTolerance(60.02, concentration.KilogramsPerCubicMeter, KilogramsPerCubicMeterTolerance); - } - - [Theory] - [InlineData(60.02, MassConcentrationUnit.KilogramPerCubicMeter, 58.443, MolarMassUnit.GramPerMole, 1026.98355, MolarityUnit.MolesPerCubicMeter)] - public void ExpectMassConcentrationConvertedToMolarityCorrectly( + [InlineData(60.02, MassConcentrationUnit.KilogramPerCubicMeter, + 58.443, MolarMassUnit.GramPerMole, + 1026.98355, MolarityUnit.MolesPerCubicMeter)] // test from JonathanDavies626 + public void MolarityFromMassConcentrationAndMolarMass( double massConcValue, MassConcentrationUnit massConcUnit, double molarMassValue, MolarMassUnit molarMassUnit, double expectedMolarityValue, MolarityUnit expectedMolarityUnit, double tolerance = 1e-5) @@ -114,34 +85,50 @@ public void ExpectMassConcentrationConvertedToMolarityCorrectly( var molarMass = new MolarMass(molarMassValue, molarMassUnit); Molarity molarity = massConcentration.ToMolarity(molarMass); // molarity / molarMass + AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerance); } - [Fact] - public void MassConcentrationFromVolumeConcentrationAndDensity() + [Theory] + [InlineData(10, DensityUnit.GramPerCubicMeter, + 5, MassConcentrationUnit.GramPerCubicMeter, + 0.5, VolumeConcentrationUnit.DecimalFraction)] // synthetic data + public void VolumeConcentrationFromMassConcentrationAndDensity( + double componentDensityValue, DensityUnit componentDensityUnit, + double massConcValue, MassConcentrationUnit masConcUnit, + double expectedVolumeConcValue, VolumeConcentrationUnit expectedVolumeConcUnit, double tolerence = 1e-5) { - var volumeConcentration = VolumeConcentration.FromPercent(50); - var density = Density.FromGramsPerCubicMeter(10); + var density = new Density(componentDensityValue, componentDensityUnit); + var massConcentration = new MassConcentration(massConcValue, masConcUnit); + + VolumeConcentration volumeConcentration = massConcentration.ToVolumeConcentration(density); // massConcentration / density; - MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); // volumeConcentration * density - AssertEx.EqualTolerance(5, massConcentration.GramsPerCubicMeter, GramsPerCubicMeterTolerance); + AssertEx.EqualTolerance(expectedVolumeConcValue, volumeConcentration.As(expectedVolumeConcUnit), tolerence); } - [Fact] - public void MassConcentrationFromVolumeConcentrationEthanol() + [Theory] + [InlineData(2, MassConcentrationUnit.KilogramPerCubicMeter, + 3, VolumeUnit.CubicMeter, + 6, MassUnit.Kilogram)] // synthetic data + public static void ComponentMassFromMassConcentrationAndSolutionVolume( + double massConcValue, MassConcentrationUnit massConcUnit, + double volumeValue, VolumeUnit volumeUnit, + double expectedMassValue, MassUnit expectedMassUnit, double tolerance = 1e-5) { - const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; - var density = Density.FromKilogramsPerCubicMeter(KnownQuantities.DensityOfEthanolInKgPerCubicMeter); - var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); + var massConcentration = new MassConcentration(massConcValue, massConcUnit); + var volume = new Volume(volumeValue, volumeUnit); - MassConcentration massConcentration = volumeConcentration.ToMassConcentration(density); - AssertEx.EqualTolerance(23.03422, massConcentration.GramsPerLiter, GramsPerCubicMeterTolerance); + Mass massComponent = massConcentration * volume; + + AssertEx.EqualTolerance(expectedMassValue, massComponent.As(expectedMassUnit), tolerance); } + [Fact(Skip = "No BaseUnit defined: see https://github.com/angularsen/UnitsNet/issues/651")] public void DefaultSIUnitIsKgPerCubicMeter() { var massConcentration = new MassConcentration(1, UnitSystem.SI); + Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, massConcentration.Unit); // MassConcentration.BaseUnit = KilogramPerCubicMeter } @@ -152,6 +139,7 @@ public void DefaultUnitTypeRespectedForCustomUnitSystem() ElectricCurrentUnit.Ampere, TemperatureUnit.DegreeCelsius, AmountOfSubstanceUnit.Mole, LuminousIntensityUnit.Candela)); var massConcentration = new MassConcentration(1, customSystem); + Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, massConcentration.Unit); } diff --git a/UnitsNet.Tests/CustomCode/MassFractionTests.cs b/UnitsNet.Tests/CustomCode/MassFractionTests.cs index 3b9ed89b92..4f29919a7a 100644 --- a/UnitsNet.Tests/CustomCode/MassFractionTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFractionTests.cs @@ -28,15 +28,15 @@ namespace UnitsNet.Tests.CustomCode public class MassFractionTests : MassFractionTestsBase { #region Unit Conversion Coefficients - protected override double KilogramsPerKiloGramInOneDecimalFraction => 1; - protected override double HectogramsPerKiloGramInOneDecimalFraction => 10; - protected override double DecagramsPerKiloGramInOneDecimalFraction => 1E2; - protected override double GramsPerKiloGramInOneDecimalFraction => 1E3; - protected override double DecigramsPerKiloGramInOneDecimalFraction => 1E4; - protected override double CentigramsPerKiloGramInOneDecimalFraction => 1E5; - protected override double MilligramsPerKiloGramInOneDecimalFraction => 1E6; - protected override double MicrogramsPerKiloGramInOneDecimalFraction => 1E9; - protected override double NanogramsPerKiloGramInOneDecimalFraction => 1E12; + protected override double KilogramsPerKilogramInOneDecimalFraction => 1; + protected override double HectogramsPerKilogramInOneDecimalFraction => 10; + protected override double DecagramsPerKilogramInOneDecimalFraction => 1E2; + protected override double GramsPerKilogramInOneDecimalFraction => 1E3; + protected override double DecigramsPerKilogramInOneDecimalFraction => 1E4; + protected override double CentigramsPerKilogramInOneDecimalFraction => 1E5; + protected override double MilligramsPerKilogramInOneDecimalFraction => 1E6; + protected override double MicrogramsPerKilogramInOneDecimalFraction => 1E9; + protected override double NanogramsPerKilogramInOneDecimalFraction => 1E12; protected override double KilogramsPerGramInOneDecimalFraction => 1E-3; protected override double HectogramsPerGramInOneDecimalFraction => 1E-2; @@ -64,6 +64,7 @@ public void MassFractionFromMassesConstructedCorrectly() var two_kg = Mass.FromKilograms(2); var massFraction = MassFraction.FromMasses(one_kg, two_kg); + AssertEx.EqualTolerance(50, massFraction.Percent, PercentTolerance); } @@ -74,7 +75,8 @@ public void TotalMassFromMassFraction() var massFraction = MassFraction.FromPercent(50); var totalMass = massFraction.GetTotalMass(componentMass); - AssertEx.EqualTolerance(2, totalMass.Kilograms, KilogramsPerKiloGramTolerance); + + AssertEx.EqualTolerance(2, totalMass.Kilograms, KilogramsPerKilogramTolerance); } [Fact] @@ -84,7 +86,8 @@ public void ComponentMassFromMassFraction() var massFraction = MassFraction.FromPercent(50); var componentMass = massFraction.GetComponentMass(totalMass); - AssertEx.EqualTolerance(1, componentMass.Kilograms, KilogramsPerKiloGramTolerance); + + AssertEx.EqualTolerance(1, componentMass.Kilograms, KilogramsPerKilogramTolerance); } } diff --git a/UnitsNet.Tests/CustomCode/MassTests.cs b/UnitsNet.Tests/CustomCode/MassTests.cs index f204b14946..3771c716a4 100644 --- a/UnitsNet.Tests/CustomCode/MassTests.cs +++ b/UnitsNet.Tests/CustomCode/MassTests.cs @@ -107,5 +107,22 @@ public void NegativeMassToStonePoundsReturnsCorrectValues() Assert.Equal(-1.0, stonePounds.Stone); Assert.Equal(-11.0, stonePounds.Pounds); } + + [Theory] + [InlineData(10, MassUnit.Gram, + KnownQuantities.MolarMassOfOxygen, MolarMassUnit.GramPerMole, + 0.625023438378939, AmountOfSubstanceUnit.Mole)] // 10 grams Of Oxygen contain 0.625023438378939 Moles + public void AmountOfSubstanceFromMassAndMolarMass( + double massValue, MassUnit massUnit, + double molarMassValue, MolarMassUnit molarMassUnit, + double expectedAmountOfSubstanceValue, AmountOfSubstanceUnit expectedAmountOfSubstanceUnit, double tolerence = 1e-5) + { + var mass = new Mass(massValue, massUnit); + var molarMass = new MolarMass(molarMassValue, molarMassUnit); + + AmountOfSubstance amountOfSubstance = mass / molarMass; + + AssertEx.EqualTolerance(expectedAmountOfSubstanceValue, amountOfSubstance.As(expectedAmountOfSubstanceUnit), tolerence); + } } } diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs index 488d144edb..585c4e1dfa 100644 --- a/UnitsNet.Tests/CustomCode/MolarMassTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs @@ -41,17 +41,6 @@ public class MolarMassTests : MolarMassTestsBase protected override double NanogramsPerMoleTolerance => 1e-3; protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12; protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; - - private const double MolarMassOfOxygen = 15.999; - private const double MolesInTenGramsOfOxygen = 0.6250390649415588; - - [Fact] - public void TenGramsOfOxygenContainExpectedNumberOfMoles() - { - Mass tenGrams = Mass.FromGrams(10); - MolarMass molarMass = MolarMass.FromGramsPerMole(MolarMassOfOxygen); - AssertEx.EqualTolerance(MolesInTenGramsOfOxygen, (tenGrams/ molarMass).Moles, GramsPerMoleTolerance); - } - + } } diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 0065462401..229098406e 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -23,6 +23,7 @@ using Xunit; using System; +using UnitsNet.Units; namespace UnitsNet.Tests.CustomCode { @@ -38,76 +39,62 @@ public class MolarityTests : MolarityTestsBase protected override double NanomolesPerLiterInOneMolesPerCubicMeter => 1e6; protected override double PicomolesPerLiterInOneMolesPerCubicMeter => 1e9; #endregion - - - [Fact] - public void ExpectMassConcentrationConvertedToMolarityCorrectly() + + [Theory] + [InlineData(0.5, MolarityUnit.MolesPerLiter, + KnownQuantities.DensityOfEthanolInKgPerCubicMeter, DensityUnit.KilogramPerCubicMeter, + KnownQuantities.MolarMassOfEthanolInGramsPerMole, MolarMassUnit.GramPerMole, + 29.19419518377693, VolumeConcentrationUnit.MillilitersPerLiter)] // 0.5M ethanol + public void VolumeConcentrationFromComponentDensityAndMolarity( + double molarityValue, MolarityUnit molarityUnit, + double componentDensityValue, DensityUnit componentDensityUnit, + double componentMolarMassValue, MolarMassUnit compontMolarMassUnit, + double expectedVolumeConcValue, VolumeConcentrationUnit expectedVolumeConcUnit, double tolerence = 1e-5) { - var massConcentration = MassConcentration.FromKilogramsPerCubicMeter(60.02); // used to be Density - var molarMass = MolarMass.FromGramsPerMole(58.443); // used to be Mass + var molarity = new Molarity(molarityValue, molarityUnit); + var componentDensity = new Density(componentDensityValue, componentDensityUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, compontMolarMassUnit); - Molarity molarity = massConcentration / molarMass; - AssertEx.EqualTolerance(1026.98355, molarity.MolesPerCubicMeter, MolesPerCubicMeterTolerance); - } + VolumeConcentration volumeConcentration = molarity.ToVolumeConcentration(componentDensity, componentMolarMass); - [Fact] - public void ExpectMolarityConvertedToMassConcentrationCorrectly() - { - var molarity = Molarity.FromMolesPerLiter(1.02698355); - var molarMass = MolarMass.FromGramsPerMole(58.443); - - MassConcentration concentration = molarity.ToMassConcentration(molarMass); // molarity * molarMass - AssertEx.EqualTolerance(60.02, concentration.KilogramsPerCubicMeter, MolesPerCubicMeterTolerance); + AssertEx.EqualTolerance(expectedVolumeConcValue, volumeConcentration.As(expectedVolumeConcUnit), tolerence); } - [Fact] - public void HClSolutionMolarityIsEqualToExpected() + [Theory] + [InlineData(1.02698355, MolarityUnit.MolesPerLiter, + 58.443, MolarMassUnit.GramPerMole, + 60.02, MassConcentrationUnit.KilogramPerCubicMeter)] // test from JonathanDavies626 + [InlineData(0.1142805, MolarityUnit.MolesPerLiter, + KnownQuantities.MolarMassHClInGramsPerMole, MolarMassUnit.GramPerMole, + 4.16667, MassConcentrationUnit.KilogramPerCubicMeter)] // HCL solution + public void ExpectMolarityConvertedToMassConcentrationCorrectly( + double molarityValue, MolarityUnit molarityUnit, + double componentMolarMassValue, MolarMassUnit compontMolarMassUnit, + double expectedMassConcValue, MassConcentrationUnit expectedMassConcUnit, double tolerence = 1e-5) { - const double MassOfSubstanceInGrams = 5; - const double VolumeOfSolutionInLiters = 1.2; - const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M - // same test is performed in AmountOfSubstanceTests - var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassHClInGramsPerMole); - var substanceMass = Mass.FromGrams(MassOfSubstanceInGrams); - var volumeSolution = Volume.FromLiters(VolumeOfSolutionInLiters); - AmountOfSubstance amountOfSubstance = substanceMass / molarMass; - - Molarity molarity = amountOfSubstance / volumeSolution; - AssertEx.EqualTolerance(ExpectedMolarityMolesPerLiter, molarity.MolesPerLiter, MolesPerLiterTolerance); - } + var molarity = new Molarity(molarityValue, molarityUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, compontMolarMassUnit); - [Fact] - public void HClSolutionConcentrationIsEqualToExpected() - { - const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M - const double ExpectedConcentrationInKgPerCubicMeter = 4.16667; - var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassHClInGramsPerMole); - var molarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); + MassConcentration concentration = molarity.ToMassConcentration(componentMolarMass); // molarity * molarMass - MassConcentration concentration = molarity * molarMass; - AssertEx.EqualTolerance(ExpectedConcentrationInKgPerCubicMeter, concentration.KilogramsPerCubicMeter, MolesPerLiterTolerance); + AssertEx.EqualTolerance(expectedMassConcValue, concentration.As(expectedMassConcUnit), tolerence); } - [Fact] - public void TenPercentHClSolutionMolarityIsEqualToExpected() + [Theory] + [InlineData(0.1142805, MolarityUnit.MolesPerLiter, + 10, VolumeConcentrationUnit.Percent, + 0.01142805, MolarityUnit.MolesPerLiter)] // 10 % dilution of HCL + public void MolarityFromDilutedSolution( + double startingMolarityValue, MolarityUnit startingMolarityUnit, + double newConcentration, VolumeConcentrationUnit newConcentrationUnit, + double expectedMolarityValue, MolarityUnit expectedMolarityUnit, double tolerence = 1e-5) { - const double ExpectedMolarityMolesPerLiter = 0.1142805; // molarity = 5 / (1.2 * 36.46) = 0.114 mol/l = 0.114 M - var originalMolarity = Molarity.FromMolesPerLiter(ExpectedMolarityMolesPerLiter); - - Molarity tenPercentMolarity = originalMolarity * VolumeConcentration.FromPercent(10); - AssertEx.EqualTolerance(ExpectedMolarityMolesPerLiter / 10, tenPercentMolarity.MolesPerLiter, MolesPerLiterTolerance); - } + var startingMolarity = new Molarity(startingMolarityValue, startingMolarityUnit); + var newVolumeConc = new VolumeConcentration(newConcentration, newConcentrationUnit); - [Fact] - public void MolarityFromVolumeConcentrationEthanol() - { - const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; - var density = Density.FromKilogramsPerCubicMeter(KnownQuantities.DensityOfEthanolInKgPerCubicMeter); - var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassOfEthanolInGramsPerMole); - var volumeConcentration = VolumeConcentration.FromMillilitersPerLiter(VolumeConcentration_0_5M_Ethanol); + Molarity dilutedMolarity = startingMolarity * newVolumeConc; - Molarity molarity = volumeConcentration.ToMolarity(density, molarMass); // volumeConcentration * density / molarMass - AssertEx.EqualTolerance(0.5, molarity.MolesPerLiter, MolesPerCubicMeterTolerance); + AssertEx.EqualTolerance(expectedMolarityValue, dilutedMolarity.As(expectedMolarityUnit), tolerence); } [Fact] @@ -120,6 +107,7 @@ public void OneMolarFromStringParsedCorrectly() public void OneMilliMolarFromStringParsedCorrectly() { var one_mM = Molarity.Parse("1000 mM"); + Assert.Equal(1, one_mM.MolesPerLiter); } diff --git a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs index bad35ddffc..729517d139 100644 --- a/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs +++ b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs @@ -21,6 +21,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using UnitsNet.Units; using Xunit; namespace UnitsNet.Tests.CustomCode @@ -52,37 +53,46 @@ public class VolumeConcentrationTests : VolumeConcentrationTestsBase protected override double DecimalFractionsInOneDecimalFraction => 1; protected override double PercentInOneDecimalFraction => 100; #endregion - - [Fact] - public void MassConcentrationFromVolumeConcentrationAndDensity() + + [Theory] + [InlineData(50, VolumeConcentrationUnit.Percent, + 10, DensityUnit.GramPerCubicMeter, + 5, MassConcentrationUnit.GramPerCubicMeter)] // synthetic data + [InlineData(29.19419518377693, VolumeConcentrationUnit.MillilitersPerLiter, + KnownQuantities.DensityOfEthanolInKgPerCubicMeter, DensityUnit.KilogramPerCubicMeter, + 23.03422, MassConcentrationUnit.GramPerLiter)] // 29.19419518377693 = VolumeConcentration_0_5M_Ethanol + public void MassConcentrationFromVolumeConcentrationAndComponentDensity( + double volumeConcValue, VolumeConcentrationUnit volumeConcUnit, + double componentDensityValue, DensityUnit componentDensityUnit, + double expectedMassConcValue, MassConcentrationUnit expectedMassConcUnit, + double tolerence = 1e-5) { - var density = Density.FromGramsPerCubicMeter(10); - var volumeConcentration = VolumeConcentration.FromPercent(50); + var volumeConcentration = new VolumeConcentration(volumeConcValue, volumeConcUnit); + var componentDensity = new Density(componentDensityValue, componentDensityUnit); + + MassConcentration massConcentration = volumeConcentration.ToMassConcentration(componentDensity); // volumeConcentration * density - MassConcentration massConcentration = volumeConcentration * density; - AssertEx.EqualTolerance(5, massConcentration.GramsPerCubicMeter, DecimalFractionsTolerance); + AssertEx.EqualTolerance(expectedMassConcValue, massConcentration.As(expectedMassConcUnit), tolerence); } - [Fact] - public void VolumeConcentrationFromMassConcentrationAndDensity() + [Theory] + [InlineData(29.19419518377693, VolumeConcentrationUnit.MillilitersPerLiter, + KnownQuantities.DensityOfEthanolInKgPerCubicMeter, DensityUnit.KilogramPerCubicMeter, + KnownQuantities.MolarMassOfEthanolInGramsPerMole, MolarMassUnit.GramPerMole, + 0.5, MolarityUnit.MolesPerLiter)] // 29.19419518377693 = VolumeConcentration_0_5M_Ethanol + public void MolarityFromVolumeConcentrationAndComponentDensityAndMolarMass( + double volumeConcValue, VolumeConcentrationUnit volumeConcUnit, + double componentDensityValue, DensityUnit componetDensityUnit, + double componentMolarMassValue, MolarMassUnit componentMolarMassUnit, + double expectedMolarityValue, MolarityUnit expectedMolarityUnit, double tolerence = 1e-5) { - var density = Density.FromGramsPerCubicMeter(10); - var massConcentration = MassConcentration.FromGramsPerCubicMeter(5); + var volumeConcentration = new VolumeConcentration(volumeConcValue, volumeConcUnit); + var componentDensity = new Density(componentDensityValue, componetDensityUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, componentMolarMassUnit); - VolumeConcentration volumeConcentration = massConcentration / density; - AssertEx.EqualTolerance(0.5, volumeConcentration.DecimalFractions, DecimalFractionsTolerance); - } - - [Fact] - public void VolumeConcentrationFromMolarityOfEthanol() - { - const double VolumeConcentration_0_5M_Ethanol = 29.19419518377693; - var molarity = Molarity.FromMolesPerLiter(0.5); - var density = Density.FromKilogramsPerCubicMeter(KnownQuantities.DensityOfEthanolInKgPerCubicMeter); - var molarMass = MolarMass.FromGramsPerMole(KnownQuantities.MolarMassOfEthanolInGramsPerMole); + Molarity molarity = volumeConcentration.ToMolarity(componentDensity, componentMolarMass); // volumeConcentration * density / molarMass - VolumeConcentration volumeConcentration = molarity.ToVolumeConcentration(density, molarMass); - AssertEx.EqualTolerance(VolumeConcentration_0_5M_Ethanol, volumeConcentration.MillilitersPerLiter, MillilitersPerLiterTolerance); + AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerence); } } diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs index d95c353678..b0cc59b8db 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassConcentration.WindowsRuntimeComponent.g.cs @@ -1094,7 +1094,7 @@ private double AsBaseUnit() case MassConcentrationUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d; case MassConcentrationUnit.KilogramPerCubicMillimeter: return (_value/1e-6) * 1e3d; - case MassConcentrationUnit.KilogramPerLiter: return _value*1e3; + case MassConcentrationUnit.KilogramPerLiter: return (_value) * 1e3d; case MassConcentrationUnit.KilopoundPerCubicFoot: return (_value/0.062427961) * 1e3d; case MassConcentrationUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (_value/1e3) * 1e-6d; @@ -1148,7 +1148,7 @@ private double AsBaseNumericType(MassConcentrationUnit unit) case MassConcentrationUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d; case MassConcentrationUnit.KilogramPerCubicMillimeter: return (baseUnitValue*1e-6) / 1e3d; - case MassConcentrationUnit.KilogramPerLiter: return baseUnitValue/1e3; + case MassConcentrationUnit.KilogramPerLiter: return (baseUnitValue) / 1e3d; case MassConcentrationUnit.KilopoundPerCubicFoot: return (baseUnitValue*0.062427961) / 1e3d; case MassConcentrationUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (baseUnitValue*1e3) / 1e-6d; diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs index ef6677290f..2c2665b7fe 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFraction.WindowsRuntimeComponent.g.cs @@ -164,9 +164,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double CentigramsPerGram => As(MassFractionUnit.CentigramPerGram); /// - /// Get MassFraction in CentigramsPerKiloGram. + /// Get MassFraction in CentigramsPerKilogram. /// - public double CentigramsPerKiloGram => As(MassFractionUnit.CentigramPerKiloGram); + public double CentigramsPerKilogram => As(MassFractionUnit.CentigramPerKilogram); /// /// Get MassFraction in DecagramsPerGram. @@ -174,9 +174,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double DecagramsPerGram => As(MassFractionUnit.DecagramPerGram); /// - /// Get MassFraction in DecagramsPerKiloGram. + /// Get MassFraction in DecagramsPerKilogram. /// - public double DecagramsPerKiloGram => As(MassFractionUnit.DecagramPerKiloGram); + public double DecagramsPerKilogram => As(MassFractionUnit.DecagramPerKilogram); /// /// Get MassFraction in DecigramsPerGram. @@ -184,9 +184,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double DecigramsPerGram => As(MassFractionUnit.DecigramPerGram); /// - /// Get MassFraction in DecigramsPerKiloGram. + /// Get MassFraction in DecigramsPerKilogram. /// - public double DecigramsPerKiloGram => As(MassFractionUnit.DecigramPerKiloGram); + public double DecigramsPerKilogram => As(MassFractionUnit.DecigramPerKilogram); /// /// Get MassFraction in DecimalFractions. @@ -199,9 +199,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double GramsPerGram => As(MassFractionUnit.GramPerGram); /// - /// Get MassFraction in GramsPerKiloGram. + /// Get MassFraction in GramsPerKilogram. /// - public double GramsPerKiloGram => As(MassFractionUnit.GramPerKiloGram); + public double GramsPerKilogram => As(MassFractionUnit.GramPerKilogram); /// /// Get MassFraction in HectogramsPerGram. @@ -209,9 +209,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double HectogramsPerGram => As(MassFractionUnit.HectogramPerGram); /// - /// Get MassFraction in HectogramsPerKiloGram. + /// Get MassFraction in HectogramsPerKilogram. /// - public double HectogramsPerKiloGram => As(MassFractionUnit.HectogramPerKiloGram); + public double HectogramsPerKilogram => As(MassFractionUnit.HectogramPerKilogram); /// /// Get MassFraction in KilogramsPerGram. @@ -219,9 +219,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double KilogramsPerGram => As(MassFractionUnit.KilogramPerGram); /// - /// Get MassFraction in KilogramsPerKiloGram. + /// Get MassFraction in KilogramsPerKilogram. /// - public double KilogramsPerKiloGram => As(MassFractionUnit.KilogramPerKiloGram); + public double KilogramsPerKilogram => As(MassFractionUnit.KilogramPerKilogram); /// /// Get MassFraction in MicrogramsPerGram. @@ -229,9 +229,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double MicrogramsPerGram => As(MassFractionUnit.MicrogramPerGram); /// - /// Get MassFraction in MicrogramsPerKiloGram. + /// Get MassFraction in MicrogramsPerKilogram. /// - public double MicrogramsPerKiloGram => As(MassFractionUnit.MicrogramPerKiloGram); + public double MicrogramsPerKilogram => As(MassFractionUnit.MicrogramPerKilogram); /// /// Get MassFraction in MilligramsPerGram. @@ -239,9 +239,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double MilligramsPerGram => As(MassFractionUnit.MilligramPerGram); /// - /// Get MassFraction in MilligramsPerKiloGram. + /// Get MassFraction in MilligramsPerKilogram. /// - public double MilligramsPerKiloGram => As(MassFractionUnit.MilligramPerKiloGram); + public double MilligramsPerKilogram => As(MassFractionUnit.MilligramPerKilogram); /// /// Get MassFraction in NanogramsPerGram. @@ -249,9 +249,9 @@ private MassFraction(double numericValue, MassFractionUnit unit) public double NanogramsPerGram => As(MassFractionUnit.NanogramPerGram); /// - /// Get MassFraction in NanogramsPerKiloGram. + /// Get MassFraction in NanogramsPerKilogram. /// - public double NanogramsPerKiloGram => As(MassFractionUnit.NanogramPerKiloGram); + public double NanogramsPerKilogram => As(MassFractionUnit.NanogramPerKilogram); /// /// Get MassFraction in PartsPerBillion. @@ -319,14 +319,14 @@ public static MassFraction FromCentigramsPerGram(double centigramspergram) return new MassFraction(value, MassFractionUnit.CentigramPerGram); } /// - /// Get MassFraction from CentigramsPerKiloGram. + /// Get MassFraction from CentigramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromCentigramsPerKiloGram(double centigramsperkilogram) + public static MassFraction FromCentigramsPerKilogram(double centigramsperkilogram) { double value = (double) centigramsperkilogram; - return new MassFraction(value, MassFractionUnit.CentigramPerKiloGram); + return new MassFraction(value, MassFractionUnit.CentigramPerKilogram); } /// /// Get MassFraction from DecagramsPerGram. @@ -339,14 +339,14 @@ public static MassFraction FromDecagramsPerGram(double decagramspergram) return new MassFraction(value, MassFractionUnit.DecagramPerGram); } /// - /// Get MassFraction from DecagramsPerKiloGram. + /// Get MassFraction from DecagramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromDecagramsPerKiloGram(double decagramsperkilogram) + public static MassFraction FromDecagramsPerKilogram(double decagramsperkilogram) { double value = (double) decagramsperkilogram; - return new MassFraction(value, MassFractionUnit.DecagramPerKiloGram); + return new MassFraction(value, MassFractionUnit.DecagramPerKilogram); } /// /// Get MassFraction from DecigramsPerGram. @@ -359,14 +359,14 @@ public static MassFraction FromDecigramsPerGram(double decigramspergram) return new MassFraction(value, MassFractionUnit.DecigramPerGram); } /// - /// Get MassFraction from DecigramsPerKiloGram. + /// Get MassFraction from DecigramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromDecigramsPerKiloGram(double decigramsperkilogram) + public static MassFraction FromDecigramsPerKilogram(double decigramsperkilogram) { double value = (double) decigramsperkilogram; - return new MassFraction(value, MassFractionUnit.DecigramPerKiloGram); + return new MassFraction(value, MassFractionUnit.DecigramPerKilogram); } /// /// Get MassFraction from DecimalFractions. @@ -389,14 +389,14 @@ public static MassFraction FromGramsPerGram(double gramspergram) return new MassFraction(value, MassFractionUnit.GramPerGram); } /// - /// Get MassFraction from GramsPerKiloGram. + /// Get MassFraction from GramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromGramsPerKiloGram(double gramsperkilogram) + public static MassFraction FromGramsPerKilogram(double gramsperkilogram) { double value = (double) gramsperkilogram; - return new MassFraction(value, MassFractionUnit.GramPerKiloGram); + return new MassFraction(value, MassFractionUnit.GramPerKilogram); } /// /// Get MassFraction from HectogramsPerGram. @@ -409,14 +409,14 @@ public static MassFraction FromHectogramsPerGram(double hectogramspergram) return new MassFraction(value, MassFractionUnit.HectogramPerGram); } /// - /// Get MassFraction from HectogramsPerKiloGram. + /// Get MassFraction from HectogramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromHectogramsPerKiloGram(double hectogramsperkilogram) + public static MassFraction FromHectogramsPerKilogram(double hectogramsperkilogram) { double value = (double) hectogramsperkilogram; - return new MassFraction(value, MassFractionUnit.HectogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.HectogramPerKilogram); } /// /// Get MassFraction from KilogramsPerGram. @@ -429,14 +429,14 @@ public static MassFraction FromKilogramsPerGram(double kilogramspergram) return new MassFraction(value, MassFractionUnit.KilogramPerGram); } /// - /// Get MassFraction from KilogramsPerKiloGram. + /// Get MassFraction from KilogramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromKilogramsPerKiloGram(double kilogramsperkilogram) + public static MassFraction FromKilogramsPerKilogram(double kilogramsperkilogram) { double value = (double) kilogramsperkilogram; - return new MassFraction(value, MassFractionUnit.KilogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.KilogramPerKilogram); } /// /// Get MassFraction from MicrogramsPerGram. @@ -449,14 +449,14 @@ public static MassFraction FromMicrogramsPerGram(double microgramspergram) return new MassFraction(value, MassFractionUnit.MicrogramPerGram); } /// - /// Get MassFraction from MicrogramsPerKiloGram. + /// Get MassFraction from MicrogramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromMicrogramsPerKiloGram(double microgramsperkilogram) + public static MassFraction FromMicrogramsPerKilogram(double microgramsperkilogram) { double value = (double) microgramsperkilogram; - return new MassFraction(value, MassFractionUnit.MicrogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.MicrogramPerKilogram); } /// /// Get MassFraction from MilligramsPerGram. @@ -469,14 +469,14 @@ public static MassFraction FromMilligramsPerGram(double milligramspergram) return new MassFraction(value, MassFractionUnit.MilligramPerGram); } /// - /// Get MassFraction from MilligramsPerKiloGram. + /// Get MassFraction from MilligramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromMilligramsPerKiloGram(double milligramsperkilogram) + public static MassFraction FromMilligramsPerKilogram(double milligramsperkilogram) { double value = (double) milligramsperkilogram; - return new MassFraction(value, MassFractionUnit.MilligramPerKiloGram); + return new MassFraction(value, MassFractionUnit.MilligramPerKilogram); } /// /// Get MassFraction from NanogramsPerGram. @@ -489,14 +489,14 @@ public static MassFraction FromNanogramsPerGram(double nanogramspergram) return new MassFraction(value, MassFractionUnit.NanogramPerGram); } /// - /// Get MassFraction from NanogramsPerKiloGram. + /// Get MassFraction from NanogramsPerKilogram. /// /// If value is NaN or Infinity. [Windows.Foundation.Metadata.DefaultOverload] - public static MassFraction FromNanogramsPerKiloGram(double nanogramsperkilogram) + public static MassFraction FromNanogramsPerKilogram(double nanogramsperkilogram) { double value = (double) nanogramsperkilogram; - return new MassFraction(value, MassFractionUnit.NanogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.NanogramPerKilogram); } /// /// Get MassFraction from PartsPerBillion. @@ -840,24 +840,24 @@ private double AsBaseUnit() switch(Unit) { case MassFractionUnit.CentigramPerGram: return (_value) * 1e-2d; - case MassFractionUnit.CentigramPerKiloGram: return (_value/1e3) * 1e-2d; + case MassFractionUnit.CentigramPerKilogram: return (_value/1e3) * 1e-2d; case MassFractionUnit.DecagramPerGram: return (_value) * 1e1d; - case MassFractionUnit.DecagramPerKiloGram: return (_value/1e3) * 1e1d; + case MassFractionUnit.DecagramPerKilogram: return (_value/1e3) * 1e1d; case MassFractionUnit.DecigramPerGram: return (_value) * 1e-1d; - case MassFractionUnit.DecigramPerKiloGram: return (_value/1e3) * 1e-1d; + case MassFractionUnit.DecigramPerKilogram: return (_value/1e3) * 1e-1d; case MassFractionUnit.DecimalFraction: return _value; case MassFractionUnit.GramPerGram: return _value; - case MassFractionUnit.GramPerKiloGram: return _value/1e3; + case MassFractionUnit.GramPerKilogram: return _value/1e3; case MassFractionUnit.HectogramPerGram: return (_value) * 1e2d; - case MassFractionUnit.HectogramPerKiloGram: return (_value/1e3) * 1e2d; + case MassFractionUnit.HectogramPerKilogram: return (_value/1e3) * 1e2d; case MassFractionUnit.KilogramPerGram: return (_value) * 1e3d; - case MassFractionUnit.KilogramPerKiloGram: return (_value/1e3) * 1e3d; + case MassFractionUnit.KilogramPerKilogram: return (_value/1e3) * 1e3d; case MassFractionUnit.MicrogramPerGram: return (_value) * 1e-6d; - case MassFractionUnit.MicrogramPerKiloGram: return (_value/1e3) * 1e-6d; + case MassFractionUnit.MicrogramPerKilogram: return (_value/1e3) * 1e-6d; case MassFractionUnit.MilligramPerGram: return (_value) * 1e-3d; - case MassFractionUnit.MilligramPerKiloGram: return (_value/1e3) * 1e-3d; + case MassFractionUnit.MilligramPerKilogram: return (_value/1e3) * 1e-3d; case MassFractionUnit.NanogramPerGram: return (_value) * 1e-9d; - case MassFractionUnit.NanogramPerKiloGram: return (_value/1e3) * 1e-9d; + case MassFractionUnit.NanogramPerKilogram: return (_value/1e3) * 1e-9d; case MassFractionUnit.PartPerBillion: return _value/1e9; case MassFractionUnit.PartPerMillion: return _value/1e6; case MassFractionUnit.PartPerThousand: return _value/1e3; @@ -878,24 +878,24 @@ private double AsBaseNumericType(MassFractionUnit unit) switch(unit) { case MassFractionUnit.CentigramPerGram: return (baseUnitValue) / 1e-2d; - case MassFractionUnit.CentigramPerKiloGram: return (baseUnitValue*1e3) / 1e-2d; + case MassFractionUnit.CentigramPerKilogram: return (baseUnitValue*1e3) / 1e-2d; case MassFractionUnit.DecagramPerGram: return (baseUnitValue) / 1e1d; - case MassFractionUnit.DecagramPerKiloGram: return (baseUnitValue*1e3) / 1e1d; + case MassFractionUnit.DecagramPerKilogram: return (baseUnitValue*1e3) / 1e1d; case MassFractionUnit.DecigramPerGram: return (baseUnitValue) / 1e-1d; - case MassFractionUnit.DecigramPerKiloGram: return (baseUnitValue*1e3) / 1e-1d; + case MassFractionUnit.DecigramPerKilogram: return (baseUnitValue*1e3) / 1e-1d; case MassFractionUnit.DecimalFraction: return baseUnitValue; case MassFractionUnit.GramPerGram: return baseUnitValue; - case MassFractionUnit.GramPerKiloGram: return baseUnitValue*1e3; + case MassFractionUnit.GramPerKilogram: return baseUnitValue*1e3; case MassFractionUnit.HectogramPerGram: return (baseUnitValue) / 1e2d; - case MassFractionUnit.HectogramPerKiloGram: return (baseUnitValue*1e3) / 1e2d; + case MassFractionUnit.HectogramPerKilogram: return (baseUnitValue*1e3) / 1e2d; case MassFractionUnit.KilogramPerGram: return (baseUnitValue) / 1e3d; - case MassFractionUnit.KilogramPerKiloGram: return (baseUnitValue*1e3) / 1e3d; + case MassFractionUnit.KilogramPerKilogram: return (baseUnitValue*1e3) / 1e3d; case MassFractionUnit.MicrogramPerGram: return (baseUnitValue) / 1e-6d; - case MassFractionUnit.MicrogramPerKiloGram: return (baseUnitValue*1e3) / 1e-6d; + case MassFractionUnit.MicrogramPerKilogram: return (baseUnitValue*1e3) / 1e-6d; case MassFractionUnit.MilligramPerGram: return (baseUnitValue) / 1e-3d; - case MassFractionUnit.MilligramPerKiloGram: return (baseUnitValue*1e3) / 1e-3d; + case MassFractionUnit.MilligramPerKilogram: return (baseUnitValue*1e3) / 1e-3d; case MassFractionUnit.NanogramPerGram: return (baseUnitValue) / 1e-9d; - case MassFractionUnit.NanogramPerKiloGram: return (baseUnitValue*1e3) / 1e-9d; + case MassFractionUnit.NanogramPerKilogram: return (baseUnitValue*1e3) / 1e-9d; case MassFractionUnit.PartPerBillion: return baseUnitValue*1e9; case MassFractionUnit.PartPerMillion: return baseUnitValue*1e6; case MassFractionUnit.PartPerThousand: return baseUnitValue*1e3; diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index bfc7571a23..d59eca7fa8 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -663,24 +663,24 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMeter, new string[]{"g·s⁻¹·m⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMeter, new string[]{"kg·s⁻¹·m⁻²"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerGram, new string[]{"cg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKiloGram, new string[]{"cg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKilogram, new string[]{"cg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerGram, new string[]{"dag/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerKiloGram, new string[]{"dag/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerKilogram, new string[]{"dag/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerGram, new string[]{"dg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerKiloGram, new string[]{"dg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerKilogram, new string[]{"dg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecimalFraction, new string[]{""}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerGram, new string[]{"g/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerKiloGram, new string[]{"g/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerKilogram, new string[]{"g/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerGram, new string[]{"hg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerKiloGram, new string[]{"hg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerKilogram, new string[]{"hg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerGram, new string[]{"kg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerKiloGram, new string[]{"kg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerKilogram, new string[]{"kg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerGram, new string[]{"µg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerKiloGram, new string[]{"µg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerKilogram, new string[]{"µg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerGram, new string[]{"mg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerKiloGram, new string[]{"mg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerKilogram, new string[]{"mg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerGram, new string[]{"ng/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerKiloGram, new string[]{"ng/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerKilogram, new string[]{"ng/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerBillion, new string[]{"ppb"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerMillion, new string[]{"ppm"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerThousand, new string[]{"‰"}), @@ -1169,26 +1169,26 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("ru-RU", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("nb-NO", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerLiter, new string[]{"cl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerMililiter, new string[]{"cl/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerLiter, new string[]{"dl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerMililiter, new string[]{"dl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerLiter, new string[]{"cL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerMililiter, new string[]{"cL/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerLiter, new string[]{"dL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerMililiter, new string[]{"dL/mL"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecimalFraction, new string[]{""}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerLiter, new string[]{"l/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerMililiter, new string[]{"l/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerLiter, new string[]{"µl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerMililiter, new string[]{"µl/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerLiter, new string[]{"ml/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerMililiter, new string[]{"ml/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerLiter, new string[]{"nl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerMililiter, new string[]{"nl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerLiter, new string[]{"L/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerMililiter, new string[]{"L/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerLiter, new string[]{"µL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerMililiter, new string[]{"µL/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerLiter, new string[]{"mL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerMililiter, new string[]{"mL/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerLiter, new string[]{"nL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerMililiter, new string[]{"nL/mL"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerBillion, new string[]{"ppb"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerMillion, new string[]{"ppm"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerThousand, new string[]{"‰"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerTrillion, new string[]{"ppt"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.Percent, new string[]{"%", "% (v/v)"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerLiter, new string[]{"pl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerMililiter, new string[]{"pl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerLiter, new string[]{"pL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerMililiter, new string[]{"pL/mL"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerDay, new string[]{"af/d"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerHour, new string[]{"af/h"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerMinute, new string[]{"af/m"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs index fe7f622126..122721f642 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFractionUnit.g.cs @@ -27,24 +27,24 @@ public enum MassFractionUnit { Undefined = 0, CentigramPerGram, - CentigramPerKiloGram, + CentigramPerKilogram, DecagramPerGram, - DecagramPerKiloGram, + DecagramPerKilogram, DecigramPerGram, - DecigramPerKiloGram, + DecigramPerKilogram, DecimalFraction, GramPerGram, - GramPerKiloGram, + GramPerKilogram, HectogramPerGram, - HectogramPerKiloGram, + HectogramPerKilogram, KilogramPerGram, - KilogramPerKiloGram, + KilogramPerKilogram, MicrogramPerGram, - MicrogramPerKiloGram, + MicrogramPerKilogram, MilligramPerGram, - MilligramPerKiloGram, + MilligramPerKilogram, NanogramPerGram, - NanogramPerKiloGram, + NanogramPerKilogram, PartPerBillion, PartPerMillion, PartPerThousand, diff --git a/UnitsNet/CustomCode/Quantities/Mass.extra.cs b/UnitsNet/CustomCode/Quantities/Mass.extra.cs index 9f7f546efe..418adf58f8 100644 --- a/UnitsNet/CustomCode/Quantities/Mass.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Mass.extra.cs @@ -71,6 +71,12 @@ public static Mass FromStonePounds(double stone, double pounds) return Volume.FromCubicMeters(mass.Kilograms / density.KilogramsPerCubicMeter); } + /// Get from divided by . + public static AmountOfSubstance operator /(Mass mass, MolarMass molarMass) + { + return AmountOfSubstance.FromMoles(mass.Kilograms / molarMass.KilogramsPerMole); + } + /// Get from times . public static Force operator *(Mass mass, Acceleration acceleration) { diff --git a/UnitsNet/CustomCode/Quantities/MolarMass.extra.cs b/UnitsNet/CustomCode/Quantities/MolarMass.extra.cs deleted file mode 100644 index 2a9d853e81..0000000000 --- a/UnitsNet/CustomCode/Quantities/MolarMass.extra.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -namespace UnitsNet -{ - public partial struct MolarMass - { - /// Get from divided by . - public static AmountOfSubstance operator /(Mass mass, MolarMass molarMass) - { - return AmountOfSubstance.FromMoles(mass.Kilograms / molarMass.KilogramsPerMole); - } - - } -} diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs index dae56520ee..b64ee1f7f8 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.NetFramework.g.cs @@ -62,13 +62,13 @@ static MassConcentration() new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)), new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)), new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)), - new UnitInfo(MassConcentrationUnit.GramPerDeciliter, new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)), + new UnitInfo(MassConcentrationUnit.GramPerDeciliter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.GramPerLiter, new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)), new UnitInfo(MassConcentrationUnit.GramPerMilliliter, new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)), new UnitInfo(MassConcentrationUnit.KilogramPerCubicCentimeter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMeter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilogramPerCubicMillimeter, BaseUnits.Undefined), - new UnitInfo(MassConcentrationUnit.KilogramPerLiter, new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram)), + new UnitInfo(MassConcentrationUnit.KilogramPerLiter, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilopoundPerCubicFoot, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.KilopoundPerCubicInch, BaseUnits.Undefined), new UnitInfo(MassConcentrationUnit.MicrogramPerCubicMeter, BaseUnits.Undefined), @@ -1238,7 +1238,7 @@ private double GetValueInBaseUnit() case MassConcentrationUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d; case MassConcentrationUnit.KilogramPerCubicMillimeter: return (_value/1e-6) * 1e3d; - case MassConcentrationUnit.KilogramPerLiter: return _value*1e3; + case MassConcentrationUnit.KilogramPerLiter: return (_value) * 1e3d; case MassConcentrationUnit.KilopoundPerCubicFoot: return (_value/0.062427961) * 1e3d; case MassConcentrationUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (_value/1e3) * 1e-6d; @@ -1292,7 +1292,7 @@ private double GetValueAs(MassConcentrationUnit unit) case MassConcentrationUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d; case MassConcentrationUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d; case MassConcentrationUnit.KilogramPerCubicMillimeter: return (baseUnitValue*1e-6) / 1e3d; - case MassConcentrationUnit.KilogramPerLiter: return baseUnitValue/1e3; + case MassConcentrationUnit.KilogramPerLiter: return (baseUnitValue) / 1e3d; case MassConcentrationUnit.KilopoundPerCubicFoot: return (baseUnitValue*0.062427961) / 1e3d; case MassConcentrationUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d; case MassConcentrationUnit.MicrogramPerCubicMeter: return (baseUnitValue*1e3) / 1e-6d; diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs index 0dc431006f..deffd3afb7 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.NetFramework.g.cs @@ -54,24 +54,24 @@ static MassFraction() Info = new QuantityInfo(QuantityType.MassFraction, new UnitInfo[] { new UnitInfo(MassFractionUnit.CentigramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.CentigramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.CentigramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.DecagramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.DecagramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecagramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.DecigramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.DecigramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.DecigramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.DecimalFraction, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.GramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.GramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.GramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.HectogramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.HectogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.HectogramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.KilogramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.KilogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.KilogramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.MicrogramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.MicrogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.MicrogramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.MilligramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.MilligramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.MilligramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.NanogramPerGram, BaseUnits.Undefined), - new UnitInfo(MassFractionUnit.NanogramPerKiloGram, BaseUnits.Undefined), + new UnitInfo(MassFractionUnit.NanogramPerKilogram, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.PartPerBillion, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.PartPerMillion, BaseUnits.Undefined), new UnitInfo(MassFractionUnit.PartPerThousand, BaseUnits.Undefined), @@ -195,9 +195,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double CentigramsPerGram => As(MassFractionUnit.CentigramPerGram); /// - /// Get MassFraction in CentigramsPerKiloGram. + /// Get MassFraction in CentigramsPerKilogram. /// - public double CentigramsPerKiloGram => As(MassFractionUnit.CentigramPerKiloGram); + public double CentigramsPerKilogram => As(MassFractionUnit.CentigramPerKilogram); /// /// Get MassFraction in DecagramsPerGram. @@ -205,9 +205,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double DecagramsPerGram => As(MassFractionUnit.DecagramPerGram); /// - /// Get MassFraction in DecagramsPerKiloGram. + /// Get MassFraction in DecagramsPerKilogram. /// - public double DecagramsPerKiloGram => As(MassFractionUnit.DecagramPerKiloGram); + public double DecagramsPerKilogram => As(MassFractionUnit.DecagramPerKilogram); /// /// Get MassFraction in DecigramsPerGram. @@ -215,9 +215,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double DecigramsPerGram => As(MassFractionUnit.DecigramPerGram); /// - /// Get MassFraction in DecigramsPerKiloGram. + /// Get MassFraction in DecigramsPerKilogram. /// - public double DecigramsPerKiloGram => As(MassFractionUnit.DecigramPerKiloGram); + public double DecigramsPerKilogram => As(MassFractionUnit.DecigramPerKilogram); /// /// Get MassFraction in DecimalFractions. @@ -230,9 +230,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double GramsPerGram => As(MassFractionUnit.GramPerGram); /// - /// Get MassFraction in GramsPerKiloGram. + /// Get MassFraction in GramsPerKilogram. /// - public double GramsPerKiloGram => As(MassFractionUnit.GramPerKiloGram); + public double GramsPerKilogram => As(MassFractionUnit.GramPerKilogram); /// /// Get MassFraction in HectogramsPerGram. @@ -240,9 +240,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double HectogramsPerGram => As(MassFractionUnit.HectogramPerGram); /// - /// Get MassFraction in HectogramsPerKiloGram. + /// Get MassFraction in HectogramsPerKilogram. /// - public double HectogramsPerKiloGram => As(MassFractionUnit.HectogramPerKiloGram); + public double HectogramsPerKilogram => As(MassFractionUnit.HectogramPerKilogram); /// /// Get MassFraction in KilogramsPerGram. @@ -250,9 +250,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double KilogramsPerGram => As(MassFractionUnit.KilogramPerGram); /// - /// Get MassFraction in KilogramsPerKiloGram. + /// Get MassFraction in KilogramsPerKilogram. /// - public double KilogramsPerKiloGram => As(MassFractionUnit.KilogramPerKiloGram); + public double KilogramsPerKilogram => As(MassFractionUnit.KilogramPerKilogram); /// /// Get MassFraction in MicrogramsPerGram. @@ -260,9 +260,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double MicrogramsPerGram => As(MassFractionUnit.MicrogramPerGram); /// - /// Get MassFraction in MicrogramsPerKiloGram. + /// Get MassFraction in MicrogramsPerKilogram. /// - public double MicrogramsPerKiloGram => As(MassFractionUnit.MicrogramPerKiloGram); + public double MicrogramsPerKilogram => As(MassFractionUnit.MicrogramPerKilogram); /// /// Get MassFraction in MilligramsPerGram. @@ -270,9 +270,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double MilligramsPerGram => As(MassFractionUnit.MilligramPerGram); /// - /// Get MassFraction in MilligramsPerKiloGram. + /// Get MassFraction in MilligramsPerKilogram. /// - public double MilligramsPerKiloGram => As(MassFractionUnit.MilligramPerKiloGram); + public double MilligramsPerKilogram => As(MassFractionUnit.MilligramPerKilogram); /// /// Get MassFraction in NanogramsPerGram. @@ -280,9 +280,9 @@ public MassFraction(double numericValue, UnitSystem unitSystem) public double NanogramsPerGram => As(MassFractionUnit.NanogramPerGram); /// - /// Get MassFraction in NanogramsPerKiloGram. + /// Get MassFraction in NanogramsPerKilogram. /// - public double NanogramsPerKiloGram => As(MassFractionUnit.NanogramPerKiloGram); + public double NanogramsPerKilogram => As(MassFractionUnit.NanogramPerKilogram); /// /// Get MassFraction in PartsPerBillion. @@ -348,13 +348,13 @@ public static MassFraction FromCentigramsPerGram(QuantityValue centigramspergram return new MassFraction(value, MassFractionUnit.CentigramPerGram); } /// - /// Get MassFraction from CentigramsPerKiloGram. + /// Get MassFraction from CentigramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromCentigramsPerKiloGram(QuantityValue centigramsperkilogram) + public static MassFraction FromCentigramsPerKilogram(QuantityValue centigramsperkilogram) { double value = (double) centigramsperkilogram; - return new MassFraction(value, MassFractionUnit.CentigramPerKiloGram); + return new MassFraction(value, MassFractionUnit.CentigramPerKilogram); } /// /// Get MassFraction from DecagramsPerGram. @@ -366,13 +366,13 @@ public static MassFraction FromDecagramsPerGram(QuantityValue decagramspergram) return new MassFraction(value, MassFractionUnit.DecagramPerGram); } /// - /// Get MassFraction from DecagramsPerKiloGram. + /// Get MassFraction from DecagramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromDecagramsPerKiloGram(QuantityValue decagramsperkilogram) + public static MassFraction FromDecagramsPerKilogram(QuantityValue decagramsperkilogram) { double value = (double) decagramsperkilogram; - return new MassFraction(value, MassFractionUnit.DecagramPerKiloGram); + return new MassFraction(value, MassFractionUnit.DecagramPerKilogram); } /// /// Get MassFraction from DecigramsPerGram. @@ -384,13 +384,13 @@ public static MassFraction FromDecigramsPerGram(QuantityValue decigramspergram) return new MassFraction(value, MassFractionUnit.DecigramPerGram); } /// - /// Get MassFraction from DecigramsPerKiloGram. + /// Get MassFraction from DecigramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromDecigramsPerKiloGram(QuantityValue decigramsperkilogram) + public static MassFraction FromDecigramsPerKilogram(QuantityValue decigramsperkilogram) { double value = (double) decigramsperkilogram; - return new MassFraction(value, MassFractionUnit.DecigramPerKiloGram); + return new MassFraction(value, MassFractionUnit.DecigramPerKilogram); } /// /// Get MassFraction from DecimalFractions. @@ -411,13 +411,13 @@ public static MassFraction FromGramsPerGram(QuantityValue gramspergram) return new MassFraction(value, MassFractionUnit.GramPerGram); } /// - /// Get MassFraction from GramsPerKiloGram. + /// Get MassFraction from GramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromGramsPerKiloGram(QuantityValue gramsperkilogram) + public static MassFraction FromGramsPerKilogram(QuantityValue gramsperkilogram) { double value = (double) gramsperkilogram; - return new MassFraction(value, MassFractionUnit.GramPerKiloGram); + return new MassFraction(value, MassFractionUnit.GramPerKilogram); } /// /// Get MassFraction from HectogramsPerGram. @@ -429,13 +429,13 @@ public static MassFraction FromHectogramsPerGram(QuantityValue hectogramspergram return new MassFraction(value, MassFractionUnit.HectogramPerGram); } /// - /// Get MassFraction from HectogramsPerKiloGram. + /// Get MassFraction from HectogramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromHectogramsPerKiloGram(QuantityValue hectogramsperkilogram) + public static MassFraction FromHectogramsPerKilogram(QuantityValue hectogramsperkilogram) { double value = (double) hectogramsperkilogram; - return new MassFraction(value, MassFractionUnit.HectogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.HectogramPerKilogram); } /// /// Get MassFraction from KilogramsPerGram. @@ -447,13 +447,13 @@ public static MassFraction FromKilogramsPerGram(QuantityValue kilogramspergram) return new MassFraction(value, MassFractionUnit.KilogramPerGram); } /// - /// Get MassFraction from KilogramsPerKiloGram. + /// Get MassFraction from KilogramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromKilogramsPerKiloGram(QuantityValue kilogramsperkilogram) + public static MassFraction FromKilogramsPerKilogram(QuantityValue kilogramsperkilogram) { double value = (double) kilogramsperkilogram; - return new MassFraction(value, MassFractionUnit.KilogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.KilogramPerKilogram); } /// /// Get MassFraction from MicrogramsPerGram. @@ -465,13 +465,13 @@ public static MassFraction FromMicrogramsPerGram(QuantityValue microgramspergram return new MassFraction(value, MassFractionUnit.MicrogramPerGram); } /// - /// Get MassFraction from MicrogramsPerKiloGram. + /// Get MassFraction from MicrogramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromMicrogramsPerKiloGram(QuantityValue microgramsperkilogram) + public static MassFraction FromMicrogramsPerKilogram(QuantityValue microgramsperkilogram) { double value = (double) microgramsperkilogram; - return new MassFraction(value, MassFractionUnit.MicrogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.MicrogramPerKilogram); } /// /// Get MassFraction from MilligramsPerGram. @@ -483,13 +483,13 @@ public static MassFraction FromMilligramsPerGram(QuantityValue milligramspergram return new MassFraction(value, MassFractionUnit.MilligramPerGram); } /// - /// Get MassFraction from MilligramsPerKiloGram. + /// Get MassFraction from MilligramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromMilligramsPerKiloGram(QuantityValue milligramsperkilogram) + public static MassFraction FromMilligramsPerKilogram(QuantityValue milligramsperkilogram) { double value = (double) milligramsperkilogram; - return new MassFraction(value, MassFractionUnit.MilligramPerKiloGram); + return new MassFraction(value, MassFractionUnit.MilligramPerKilogram); } /// /// Get MassFraction from NanogramsPerGram. @@ -501,13 +501,13 @@ public static MassFraction FromNanogramsPerGram(QuantityValue nanogramspergram) return new MassFraction(value, MassFractionUnit.NanogramPerGram); } /// - /// Get MassFraction from NanogramsPerKiloGram. + /// Get MassFraction from NanogramsPerKilogram. /// /// If value is NaN or Infinity. - public static MassFraction FromNanogramsPerKiloGram(QuantityValue nanogramsperkilogram) + public static MassFraction FromNanogramsPerKilogram(QuantityValue nanogramsperkilogram) { double value = (double) nanogramsperkilogram; - return new MassFraction(value, MassFractionUnit.NanogramPerKiloGram); + return new MassFraction(value, MassFractionUnit.NanogramPerKilogram); } /// /// Get MassFraction from PartsPerBillion. @@ -984,24 +984,24 @@ private double GetValueInBaseUnit() switch(Unit) { case MassFractionUnit.CentigramPerGram: return (_value) * 1e-2d; - case MassFractionUnit.CentigramPerKiloGram: return (_value/1e3) * 1e-2d; + case MassFractionUnit.CentigramPerKilogram: return (_value/1e3) * 1e-2d; case MassFractionUnit.DecagramPerGram: return (_value) * 1e1d; - case MassFractionUnit.DecagramPerKiloGram: return (_value/1e3) * 1e1d; + case MassFractionUnit.DecagramPerKilogram: return (_value/1e3) * 1e1d; case MassFractionUnit.DecigramPerGram: return (_value) * 1e-1d; - case MassFractionUnit.DecigramPerKiloGram: return (_value/1e3) * 1e-1d; + case MassFractionUnit.DecigramPerKilogram: return (_value/1e3) * 1e-1d; case MassFractionUnit.DecimalFraction: return _value; case MassFractionUnit.GramPerGram: return _value; - case MassFractionUnit.GramPerKiloGram: return _value/1e3; + case MassFractionUnit.GramPerKilogram: return _value/1e3; case MassFractionUnit.HectogramPerGram: return (_value) * 1e2d; - case MassFractionUnit.HectogramPerKiloGram: return (_value/1e3) * 1e2d; + case MassFractionUnit.HectogramPerKilogram: return (_value/1e3) * 1e2d; case MassFractionUnit.KilogramPerGram: return (_value) * 1e3d; - case MassFractionUnit.KilogramPerKiloGram: return (_value/1e3) * 1e3d; + case MassFractionUnit.KilogramPerKilogram: return (_value/1e3) * 1e3d; case MassFractionUnit.MicrogramPerGram: return (_value) * 1e-6d; - case MassFractionUnit.MicrogramPerKiloGram: return (_value/1e3) * 1e-6d; + case MassFractionUnit.MicrogramPerKilogram: return (_value/1e3) * 1e-6d; case MassFractionUnit.MilligramPerGram: return (_value) * 1e-3d; - case MassFractionUnit.MilligramPerKiloGram: return (_value/1e3) * 1e-3d; + case MassFractionUnit.MilligramPerKilogram: return (_value/1e3) * 1e-3d; case MassFractionUnit.NanogramPerGram: return (_value) * 1e-9d; - case MassFractionUnit.NanogramPerKiloGram: return (_value/1e3) * 1e-9d; + case MassFractionUnit.NanogramPerKilogram: return (_value/1e3) * 1e-9d; case MassFractionUnit.PartPerBillion: return _value/1e9; case MassFractionUnit.PartPerMillion: return _value/1e6; case MassFractionUnit.PartPerThousand: return _value/1e3; @@ -1022,24 +1022,24 @@ private double GetValueAs(MassFractionUnit unit) switch(unit) { case MassFractionUnit.CentigramPerGram: return (baseUnitValue) / 1e-2d; - case MassFractionUnit.CentigramPerKiloGram: return (baseUnitValue*1e3) / 1e-2d; + case MassFractionUnit.CentigramPerKilogram: return (baseUnitValue*1e3) / 1e-2d; case MassFractionUnit.DecagramPerGram: return (baseUnitValue) / 1e1d; - case MassFractionUnit.DecagramPerKiloGram: return (baseUnitValue*1e3) / 1e1d; + case MassFractionUnit.DecagramPerKilogram: return (baseUnitValue*1e3) / 1e1d; case MassFractionUnit.DecigramPerGram: return (baseUnitValue) / 1e-1d; - case MassFractionUnit.DecigramPerKiloGram: return (baseUnitValue*1e3) / 1e-1d; + case MassFractionUnit.DecigramPerKilogram: return (baseUnitValue*1e3) / 1e-1d; case MassFractionUnit.DecimalFraction: return baseUnitValue; case MassFractionUnit.GramPerGram: return baseUnitValue; - case MassFractionUnit.GramPerKiloGram: return baseUnitValue*1e3; + case MassFractionUnit.GramPerKilogram: return baseUnitValue*1e3; case MassFractionUnit.HectogramPerGram: return (baseUnitValue) / 1e2d; - case MassFractionUnit.HectogramPerKiloGram: return (baseUnitValue*1e3) / 1e2d; + case MassFractionUnit.HectogramPerKilogram: return (baseUnitValue*1e3) / 1e2d; case MassFractionUnit.KilogramPerGram: return (baseUnitValue) / 1e3d; - case MassFractionUnit.KilogramPerKiloGram: return (baseUnitValue*1e3) / 1e3d; + case MassFractionUnit.KilogramPerKilogram: return (baseUnitValue*1e3) / 1e3d; case MassFractionUnit.MicrogramPerGram: return (baseUnitValue) / 1e-6d; - case MassFractionUnit.MicrogramPerKiloGram: return (baseUnitValue*1e3) / 1e-6d; + case MassFractionUnit.MicrogramPerKilogram: return (baseUnitValue*1e3) / 1e-6d; case MassFractionUnit.MilligramPerGram: return (baseUnitValue) / 1e-3d; - case MassFractionUnit.MilligramPerKiloGram: return (baseUnitValue*1e3) / 1e-3d; + case MassFractionUnit.MilligramPerKilogram: return (baseUnitValue*1e3) / 1e-3d; case MassFractionUnit.NanogramPerGram: return (baseUnitValue) / 1e-9d; - case MassFractionUnit.NanogramPerKiloGram: return (baseUnitValue*1e3) / 1e-9d; + case MassFractionUnit.NanogramPerKilogram: return (baseUnitValue*1e3) / 1e-9d; case MassFractionUnit.PartPerBillion: return baseUnitValue*1e9; case MassFractionUnit.PartPerMillion: return baseUnitValue*1e6; case MassFractionUnit.PartPerThousand: return baseUnitValue*1e3; diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index e48b72bb82..b3df2f3c0d 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -663,24 +663,24 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMeter, new string[]{"g·s⁻¹·m⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMeter, new string[]{"kg·s⁻¹·m⁻²"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerGram, new string[]{"cg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKiloGram, new string[]{"cg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKilogram, new string[]{"cg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerGram, new string[]{"dag/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerKiloGram, new string[]{"dag/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerKilogram, new string[]{"dag/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerGram, new string[]{"dg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerKiloGram, new string[]{"dg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecigramPerKilogram, new string[]{"dg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecimalFraction, new string[]{""}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerGram, new string[]{"g/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerKiloGram, new string[]{"g/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.GramPerKilogram, new string[]{"g/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerGram, new string[]{"hg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerKiloGram, new string[]{"hg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.HectogramPerKilogram, new string[]{"hg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerGram, new string[]{"kg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerKiloGram, new string[]{"kg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.KilogramPerKilogram, new string[]{"kg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerGram, new string[]{"µg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerKiloGram, new string[]{"µg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MicrogramPerKilogram, new string[]{"µg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerGram, new string[]{"mg/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerKiloGram, new string[]{"mg/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.MilligramPerKilogram, new string[]{"mg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerGram, new string[]{"ng/g"}), - ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerKiloGram, new string[]{"ng/kg"}), + ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.NanogramPerKilogram, new string[]{"ng/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerBillion, new string[]{"ppb"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerMillion, new string[]{"ppm"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.PartPerThousand, new string[]{"‰"}), @@ -1169,26 +1169,26 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("ru-RU", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), ("nb-NO", typeof(VolumeUnit), (int)VolumeUnit.UsTeaspoon, new string[]{""}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerLiter, new string[]{"cl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerMililiter, new string[]{"cl/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerLiter, new string[]{"dl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerMililiter, new string[]{"dl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerLiter, new string[]{"cL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.CentilitersPerMililiter, new string[]{"cL/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerLiter, new string[]{"dL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecilitersPerMililiter, new string[]{"dL/mL"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.DecimalFraction, new string[]{""}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerLiter, new string[]{"l/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerMililiter, new string[]{"l/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerLiter, new string[]{"µl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerMililiter, new string[]{"µl/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerLiter, new string[]{"ml/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerMililiter, new string[]{"ml/ml"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerLiter, new string[]{"nl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerMililiter, new string[]{"nl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerLiter, new string[]{"L/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.LitersPerMililiter, new string[]{"L/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerLiter, new string[]{"µL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MicrolitersPerMililiter, new string[]{"µL/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerLiter, new string[]{"mL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.MillilitersPerMililiter, new string[]{"mL/mL"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerLiter, new string[]{"nL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.NanolitersPerMililiter, new string[]{"nL/mL"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerBillion, new string[]{"ppb"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerMillion, new string[]{"ppm"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerThousand, new string[]{"‰"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PartPerTrillion, new string[]{"ppt"}), ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.Percent, new string[]{"%", "% (v/v)"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerLiter, new string[]{"pl/l"}), - ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerMililiter, new string[]{"pl/ml"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerLiter, new string[]{"pL/L"}), + ("en-US", typeof(VolumeConcentrationUnit), (int)VolumeConcentrationUnit.PicolitersPerMililiter, new string[]{"pL/mL"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerDay, new string[]{"af/d"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerHour, new string[]{"af/h"}), ("en-US", typeof(VolumeFlowUnit), (int)VolumeFlowUnit.AcreFootPerMinute, new string[]{"af/m"}), diff --git a/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs index fe7f622126..122721f642 100644 --- a/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MassFractionUnit.g.cs @@ -27,24 +27,24 @@ public enum MassFractionUnit { Undefined = 0, CentigramPerGram, - CentigramPerKiloGram, + CentigramPerKilogram, DecagramPerGram, - DecagramPerKiloGram, + DecagramPerKilogram, DecigramPerGram, - DecigramPerKiloGram, + DecigramPerKilogram, DecimalFraction, GramPerGram, - GramPerKiloGram, + GramPerKilogram, HectogramPerGram, - HectogramPerKiloGram, + HectogramPerKilogram, KilogramPerGram, - KilogramPerKiloGram, + KilogramPerKilogram, MicrogramPerGram, - MicrogramPerKiloGram, + MicrogramPerKilogram, MilligramPerGram, - MilligramPerKiloGram, + MilligramPerKilogram, NanogramPerGram, - NanogramPerKiloGram, + NanogramPerKilogram, PartPerBillion, PartPerMillion, PartPerThousand, From a4255662c8d117a8a79cad17102fcc9cb0c6d504 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sun, 21 Apr 2019 21:48:31 +0200 Subject: [PATCH 8/8] Make single line act-statements in tests --- UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs index 6b4494a0a6..61560c24ec 100644 --- a/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs +++ b/UnitsNet.Tests/CustomCode/AmountOfSubstanceTests.cs @@ -91,8 +91,8 @@ public void MolarityFromComponentMassAndSolutionVolume( var componentMass = new Mass(componentMassValue, componentMassUnit); var componentMolarMass = new MolarMass(componentMolarMassValue, componentMolarMassUnit); var volumeSolution = new Volume(solutionVolumeValue, solutionVolumeUnit); - AmountOfSubstance amountOfSubstance = componentMass / componentMolarMass; + Molarity molarity = amountOfSubstance / volumeSolution; AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerence); @@ -112,8 +112,8 @@ public void VolumeSolutionFromComponentMassAndDesiredConcentration( var componentMass = new Mass(componentMassValue, componentMassUnit); var componentMolarMass = new MolarMass(componentMolarMassValue, componentMolarMassUnit); var desiredMolarity = new Molarity(desiredMolarityValue, desiredMolarityUnit); - AmountOfSubstance amountOfSubstance = componentMass / componentMolarMass; + Volume volumeSolution = amountOfSubstance / desiredMolarity; AssertEx.EqualTolerance(expectedSolutionVolumeValue, volumeSolution.As(expectedSolutionVolumeUnit), tolerence);