diff --git a/Common/UnitDefinitions/MassConcentration.json b/Common/UnitDefinitions/MassConcentration.json new file mode 100644 index 0000000000..062645ff69 --- /dev/null +++ b/Common/UnitDefinitions/MassConcentration.json @@ -0,0 +1,238 @@ +{ + "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": { + "M": 1, + "L": -3 + }, + "Units": [ + { + "SingularName": "GramPerCubicMillimeter", + "PluralName": "GramsPerCubicMillimeter", + "BaseUnits": { + "M": "Gram", + "L": "Millimeter" + }, + "FromUnitToBaseFunc": "x/1e-6", + "FromBaseToUnitFunc": "x*1e-6", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/mm³" ] + } + ] + }, + { + "SingularName": "GramPerCubicCentimeter", + "PluralName": "GramsPerCubicCentimeter", + "BaseUnits": { + "M": "Gram", + "L": "Centimeter" + }, + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/cm³" ] + } + ] + }, + { + "SingularName": "GramPerCubicMeter", + "PluralName": "GramsPerCubicMeter", + "BaseUnits": { + "M": "Gram", + "L": "Meter" + }, + "FromUnitToBaseFunc": "x/1e3", + "FromBaseToUnitFunc": "x*1e3", + "Prefixes": [ "Kilo", "Milli", "Micro" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/m³" ] + }, + { + "Culture": "ru-RU", + "Abbreviations": [ "г/м³" ] + } + ] + }, + { + "SingularName": "GramPerMilliliter", + "PluralName": "GramsPerMilliliter", + "BaseUnits": { + "M": "Gram", + "L": "Centimeter" + }, + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/mL" ] + } + ] + }, + { + "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": "GramPerLiter", + "PluralName": "GramsPerLiter", + "BaseUnits": { + "M": "Gram", + "L": "Decimeter" + }, + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci", "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/L"] + } + ] + }, + { + "SingularName": "TonnePerCubicMillimeter", + "PluralName": "TonnesPerCubicMillimeter", + "BaseUnits": { + "M": "Tonne", + "L": "Millimeter" + }, + "FromUnitToBaseFunc": "x/1e-12", + "FromBaseToUnitFunc": "x*1e-12", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "t/mm³" ] + } + ] + }, + { + "SingularName": "TonnePerCubicCentimeter", + "PluralName": "TonnesPerCubicCentimeter", + "BaseUnits": { + "M": "Tonne", + "L": "Centimeter" + }, + "FromUnitToBaseFunc": "x/1e-9", + "FromBaseToUnitFunc": "x*1e-9", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "t/cm³" ] + } + ] + }, + { + "SingularName": "TonnePerCubicMeter", + "PluralName": "TonnesPerCubicMeter", + "BaseUnits": { + "M": "Tonne", + "L": "Meter" + }, + "FromUnitToBaseFunc": "x/0.001", + "FromBaseToUnitFunc": "x*0.001", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "t/m³" ] + } + ] + }, + { + "SingularName": "PoundPerCubicInch", + "PluralName": "PoundsPerCubicInch", + "BaseUnits": { + "M": "Pound", + "L": "Inch" + }, + "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": { + "M": "Pound", + "L": "Foot" + }, + "FromUnitToBaseFunc": "x/0.062427961", + "FromBaseToUnitFunc": "x*0.062427961", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "lb/ft³" ], + "AbbreviationsWithPrefixes": [ "kip/ft³" ] + } + ] + }, + { + "SingularName": "SlugPerCubicFoot", + "PluralName": "SlugsPerCubicFoot", + "BaseUnits": { + "M": "Slug", + "L": "Foot" + }, + "FromUnitToBaseFunc": "x*515.378818", + "FromBaseToUnitFunc": "x*0.00194032033", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "slug/ft³" ] + } + ] + }, + { + "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.)" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/MassFraction.json b/Common/UnitDefinitions/MassFraction.json new file mode 100644 index 0000000000..fdfc016073 --- /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..30a55110e0 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,13 +28,17 @@ { "SingularName": "MolesPerLiter", "PluralName": "MolesPerLiter", + "BaseUnits": { + "L": "Decimeter", + "N": "Mole" + }, "FromUnitToBaseFunc": "x/1e-3", "FromBaseToUnitFunc": "x*1e-3", "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Centi", "Deci" ], "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "mol/L" ] + "Abbreviations": [ "mol/L", "M"] } ] } diff --git a/Common/UnitDefinitions/VolumeConcentration.json b/Common/UnitDefinitions/VolumeConcentration.json new file mode 100644 index 0000000000..de56f8491f --- /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..61560c24ec 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 @@ -42,7 +43,7 @@ public class AmountOfSubstanceTests : AmountOfSubstanceTestsBase protected override double NanopoundMolesInOneMole => 0.002204622621848776 * 1e9; protected override double PoundMolesInOneMole => 0.002204622621848776; protected override double MegamolesInOneMole => 1e-6; - + [Fact] public void NumberOfParticlesInOneMoleEqualsAvogadroConstant() { @@ -58,5 +59,64 @@ public void NumberOfParticlesInTwoMolesIsDoubleAvogadroConstant() var numberOfParticles = twoMoles.NumberOfParticles(); Assert.Equal(AmountOfSubstance.AvogadroConstant * 2, numberOfParticles); } + + [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 amountOfSubstance = new AmountOfSubstance(amountOfSubstanceValue, amountOfSubstanceUnit); + MolarMass molarMass = new MolarMass(molarMassValue, molarMassUnit); + + Mass mass = amountOfSubstance * molarMass; + + AssertEx.EqualTolerance(expectedMass, mass.As(expectedMassUnit), tolerence); + } + + [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) + { + 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); + } + + [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) + { + 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); + } } } 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/KnownQuantities.cs b/UnitsNet.Tests/CustomCode/KnownQuantities.cs new file mode 100644 index 0000000000..0a3b8a9b37 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/KnownQuantities.cs @@ -0,0 +1,12 @@ +namespace UnitsNet.Tests.CustomCode +{ + public static class KnownQuantities + { + public const double MolarMassOfOxygen = 15.9994; + + 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 new file mode 100644 index 0000000000..b4fc2cb9fd --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MassConcentrationTests.cs @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +// +// 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 + { + #region Unit Conversion Coefficients + 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; + #endregion + + [Theory] + [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) + { + var massConcentration = new MassConcentration(massConcValue, massConcUnit); + var molarMass = new MolarMass(molarMassValue, molarMassUnit); + + Molarity molarity = massConcentration.ToMolarity(molarMass); // molarity / molarMass + + AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerance); + } + + [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 density = new Density(componentDensityValue, componentDensityUnit); + var massConcentration = new MassConcentration(massConcValue, masConcUnit); + + VolumeConcentration volumeConcentration = massConcentration.ToVolumeConcentration(density); // massConcentration / density; + + AssertEx.EqualTolerance(expectedVolumeConcValue, volumeConcentration.As(expectedVolumeConcUnit), tolerence); + } + + [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) + { + var massConcentration = new MassConcentration(massConcValue, massConcUnit); + var volume = new Volume(volumeValue, volumeUnit); + + 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 + } + + [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 new file mode 100644 index 0000000000..4f29919a7a --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MassFractionTests.cs @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// 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 + { + #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 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 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 MassFractionFromMassesConstructedCorrectly() + { + 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/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 696d990359..585c4e1dfa 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,6 @@ public class MolarMassTests : MolarMassTestsBase protected override double NanogramsPerMoleTolerance => 1e-3; protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12; protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757; + } } diff --git a/UnitsNet.Tests/CustomCode/MolarityTests.cs b/UnitsNet.Tests/CustomCode/MolarityTests.cs index 0b65235b16..229098406e 100644 --- a/UnitsNet.Tests/CustomCode/MolarityTests.cs +++ b/UnitsNet.Tests/CustomCode/MolarityTests.cs @@ -23,36 +23,92 @@ using Xunit; using System; +using UnitsNet.Units; 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 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; + #endregion + + [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 molarity = new Molarity(molarityValue, molarityUnit); + var componentDensity = new Density(componentDensityValue, componentDensityUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, compontMolarMassUnit); - [Fact] - public void ExpectDensityConvertedToMolarityCorrectly() + VolumeConcentration volumeConcentration = molarity.ToVolumeConcentration(componentDensity, componentMolarMass); + + AssertEx.EqualTolerance(expectedVolumeConcValue, volumeConcentration.As(expectedVolumeConcUnit), tolerence); + } + + [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) { - var density = Density.FromKilogramsPerCubicMeter(60.02); - var mw = Mass.FromGrams(58.443); - var molarity = (density / mw).MolesPerCubicMeter; - AssertEx.EqualTolerance(1026.98355, molarity, MolesPerCubicMeterTolerance); + var molarity = new Molarity(molarityValue, molarityUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, compontMolarMassUnit); + + MassConcentration concentration = molarity.ToMassConcentration(componentMolarMass); // molarity * molarMass + + AssertEx.EqualTolerance(expectedMassConcValue, concentration.As(expectedMassConcUnit), tolerence); + } + + [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) + { + var startingMolarity = new Molarity(startingMolarityValue, startingMolarityUnit); + var newVolumeConc = new VolumeConcentration(newConcentration, newConcentrationUnit); + + Molarity dilutedMolarity = startingMolarity * newVolumeConc; + + AssertEx.EqualTolerance(expectedMolarityValue, dilutedMolarity.As(expectedMolarityUnit), tolerence); } [Fact] - public void ExpectMolarityConvertedToDensityCorrectly() + public void OneMolarFromStringParsedCorrectly() { - var molarity = Molarity.FromMolesPerLiter(1.02698355); - var mw = Mass.FromGrams(58.443); - var density = molarity.ToDensity(mw).KilogramsPerCubicMeter; - AssertEx.EqualTolerance(60.02, density, MolesPerCubicMeterTolerance); + Assert.Equal(Molarity.Parse("1M"), Molarity.Parse("1 mol/L")); + } + + [Fact(Skip = "Awaiting fix for https://github.com/angularsen/UnitsNet/issues/344")] + 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..729517d139 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/VolumeConcentrationTests.cs @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// 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 VolumeConcentrationTests : VolumeConcentrationTestsBase + { + #region Unit Conversion Coefficients + 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 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 + + [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 volumeConcentration = new VolumeConcentration(volumeConcValue, volumeConcUnit); + var componentDensity = new Density(componentDensityValue, componentDensityUnit); + + MassConcentration massConcentration = volumeConcentration.ToMassConcentration(componentDensity); // volumeConcentration * density + + AssertEx.EqualTolerance(expectedMassConcValue, massConcentration.As(expectedMassConcUnit), tolerence); + } + + [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 volumeConcentration = new VolumeConcentration(volumeConcValue, volumeConcUnit); + var componentDensity = new Density(componentDensityValue, componetDensityUnit); + var componentMolarMass = new MolarMass(componentMolarMassValue, componentMolarMassUnit); + + Molarity molarity = volumeConcentration.ToMolarity(componentDensity, componentMolarMass); // volumeConcentration * density / molarMass + + AssertEx.EqualTolerance(expectedMolarityValue, molarity.As(expectedMolarityUnit), tolerence); + } + + } +} 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..b0cc59b8db --- /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) * 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) * 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; + 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) * 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; + case MassConcentrationUnit.MicrogramPerDeciliter: return (_value/1e-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) * 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) * 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) * 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) / 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) / 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; + 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) / 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; + case MassConcentrationUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-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) / 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) / 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) / 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..2c2665b7fe --- /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/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 8129d11254..d59eca7fa8 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -583,6 +583,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"}), @@ -618,6 +662,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²"}), @@ -657,7 +725,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MicromolesPerLiter, new string[]{"µmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MillimolesPerLiter, new string[]{"mmol/L"}), ("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.MolesPerLiter, new string[]{"mol/L", "M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.NanomolesPerLiter, new string[]{"nmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.PicomolesPerLiter, new string[]{"pmol/L"}), ("en-US", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"cg/mol"}), @@ -1101,6 +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.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..122721f642 --- /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/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..e569cefac5 100644 --- a/UnitsNet/CustomCode/Quantities/Density.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Density.extra.cs @@ -1,6 +1,7 @@ // 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 @@ -11,6 +12,8 @@ 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); @@ -21,6 +24,8 @@ public Molarity ToMolarity(Mass molecularWeight) /// /// 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); @@ -59,6 +64,8 @@ public static Density FromMolarity(Molarity molarity, Mass molecularWeight) } /// 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/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/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/Molarity.extra.cs b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs index b7ce39d5f3..53af6eeb15 100644 --- a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs @@ -8,8 +8,8 @@ public partial struct Molarity /// /// Construct from divided by . /// - /// - [Obsolete("This constructor will be removed in favor of operator overload Density.op_Division(UnitsNet.Density,UnitsNet.Mass).")] + /// + [Obsolete("This constructor will be removed in favor of operator overload MassConcentration.op_Division(MassConcentration,MolarMass).")] public Molarity(Density density, Mass molecularWeight) : this() { @@ -21,11 +21,32 @@ public Molarity(Density density, Mass molecularWeight) /// 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 . + /// + /// + public MassConcentration ToMassConcentration(MolarMass molecularWeight) + { + return this * molecularWeight; + } + + /// + /// Get a from this . + /// + /// + /// + public VolumeConcentration ToVolumeConcentration(Density componentDensity, MolarMass componentMass) + { + return this * componentMass / componentDensity; + } + #region Static Methods /// @@ -33,12 +54,53 @@ public Density ToDensity(Mass molecularWeight) /// /// /// - [Obsolete("Use Density / Mass operator overload instead.")] + [Obsolete("Use MassConcentration / MolarMass operator overload instead.")] public static Molarity FromDensity(Density density, Mass molecularWeight) { return density / molecularWeight; } + /// + /// Get from and known component and . + /// + /// + /// + /// + /// + 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 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..b64ee1f7f8 --- /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, 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, BaseUnits.Undefined), + 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) * 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) * 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; + 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) * 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; + case MassConcentrationUnit.MicrogramPerDeciliter: return (_value/1e-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) * 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) * 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) * 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) / 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) / 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; + 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) / 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; + case MassConcentrationUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-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) / 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) / 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) / 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..deffd3afb7 --- /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..ecd13c4733 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs @@ -57,8 +57,8 @@ static Molarity() new UnitInfo(MolarityUnit.DecimolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MicromolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.MillimolesPerLiter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.MolesPerCubicMeter, BaseUnits.Undefined), - new UnitInfo(MolarityUnit.MolesPerLiter, BaseUnits.Undefined), + new UnitInfo(MolarityUnit.MolesPerCubicMeter, new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)), + new UnitInfo(MolarityUnit.MolesPerLiter, new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Mole)), new UnitInfo(MolarityUnit.NanomolesPerLiter, BaseUnits.Undefined), new UnitInfo(MolarityUnit.PicomolesPerLiter, BaseUnits.Undefined), }, 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 08142c416c..b3df2f3c0d 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -583,6 +583,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"}), @@ -618,6 +662,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²"}), @@ -657,7 +725,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MicromolesPerLiter, new string[]{"µmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.MillimolesPerLiter, new string[]{"mmol/L"}), ("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.MolesPerLiter, new string[]{"mol/L", "M"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.NanomolesPerLiter, new string[]{"nmol/L"}), ("en-US", typeof(MolarityUnit), (int)MolarityUnit.PicomolesPerLiter, new string[]{"pmol/L"}), ("en-US", typeof(MolarMassUnit), (int)MolarMassUnit.CentigramPerMole, new string[]{"cg/mol"}), @@ -1101,6 +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.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..122721f642 --- /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/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 +}