diff --git a/UnitsNet.Tests/CustomCode/MolarMassTests.cs b/UnitsNet.Tests/CustomCode/MolarMassTests.cs
new file mode 100644
index 0000000000..2d7f772681
--- /dev/null
+++ b/UnitsNet.Tests/CustomCode/MolarMassTests.cs
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+//
+// 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\MyUnit.extra.cs files to add code to generated quantities.
+// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
+// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2007 Andreas Gullberg Larsen (angularsen@gmail.com).
+// https://github.com/angularsen/UnitsNet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+using System;
+
+namespace UnitsNet.Tests.CustomCode
+{
+ public class MolarMassTests : MolarMassTestsBase
+ {
+ protected override double CentigramsPerMoleInOneKilogramPerMole => 1e5;
+ protected override double DecagramsPerMoleInOneKilogramPerMole => 1e2;
+ protected override double DecigramsPerMoleInOneKilogramPerMole => 1e4;
+ protected override double GramsPerMoleInOneKilogramPerMole => 1e3;
+ protected override double HectogramsPerMoleInOneKilogramPerMole => 10;
+ protected override double KilogramsPerMoleInOneKilogramPerMole => 1;
+ protected override double KilopoundsPerMoleInOneKilogramPerMole => 2.2046226218487757e-3;
+ protected override double MegapoundsPerMoleInOneKilogramPerMole => 2.2046226218487757e-6;
+ protected override double MicrogramsPerMoleInOneKilogramPerMole => 1e9;
+ protected override double MilligramsPerMoleInOneKilogramPerMole => 1e6;
+ protected override double NanogramsPerMoleTolerance => 1e-3;
+ protected override double NanogramsPerMoleInOneKilogramPerMole => 1e12;
+ protected override double PoundsPerMoleInOneKilogramPerMole => 2.2046226218487757;
+ }
+}
diff --git a/UnitsNet.Tests/GeneratedCode/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MolarMassTestsBase.g.cs
new file mode 100644
index 0000000000..562233904f
--- /dev/null
+++ b/UnitsNet.Tests/GeneratedCode/MolarMassTestsBase.g.cs
@@ -0,0 +1,245 @@
+//------------------------------------------------------------------------------
+//
+// 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\MyUnit.extra.cs files to add code to generated quantities.
+// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
+// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2007 Andreas Gullberg Larsen (angularsen@gmail.com).
+// https://github.com/angularsen/UnitsNet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using UnitsNet.Units;
+using Xunit;
+
+// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else?
+#pragma warning disable 1718
+
+// ReSharper disable once CheckNamespace
+namespace UnitsNet.Tests
+{
+ ///
+ /// Test of MolarMass.
+ ///
+// ReSharper disable once PartialTypeWithSinglePart
+ public abstract partial class MolarMassTestsBase
+ {
+ protected abstract double CentigramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double DecagramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double DecigramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double GramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double HectogramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double KilogramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double KilopoundsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double MegapoundsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double MicrogramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double MilligramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double NanogramsPerMoleInOneKilogramPerMole { get; }
+ protected abstract double PoundsPerMoleInOneKilogramPerMole { get; }
+
+// ReSharper disable VirtualMemberNeverOverriden.Global
+ protected virtual double CentigramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double DecagramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double DecigramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double GramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double HectogramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double KilogramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double KilopoundsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double MegapoundsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double MicrogramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double MilligramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double NanogramsPerMoleTolerance { get { return 1e-5; } }
+ protected virtual double PoundsPerMoleTolerance { get { return 1e-5; } }
+// ReSharper restore VirtualMemberNeverOverriden.Global
+
+ [Fact]
+ public void KilogramPerMoleToMolarMassUnits()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ AssertEx.EqualTolerance(CentigramsPerMoleInOneKilogramPerMole, kilogrampermole.CentigramsPerMole, CentigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(DecagramsPerMoleInOneKilogramPerMole, kilogrampermole.DecagramsPerMole, DecagramsPerMoleTolerance);
+ AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, kilogrampermole.DecigramsPerMole, DecigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, kilogrampermole.GramsPerMole, GramsPerMoleTolerance);
+ AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, kilogrampermole.HectogramsPerMole, HectogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, kilogrampermole.KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, kilogrampermole.KilopoundsPerMole, KilopoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, kilogrampermole.MegapoundsPerMole, MegapoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(MicrogramsPerMoleInOneKilogramPerMole, kilogrampermole.MicrogramsPerMole, MicrogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(MilligramsPerMoleInOneKilogramPerMole, kilogrampermole.MilligramsPerMole, MilligramsPerMoleTolerance);
+ AssertEx.EqualTolerance(NanogramsPerMoleInOneKilogramPerMole, kilogrampermole.NanogramsPerMole, NanogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(PoundsPerMoleInOneKilogramPerMole, kilogrampermole.PoundsPerMole, PoundsPerMoleTolerance);
+ }
+
+ [Fact]
+ public void FromValueAndUnit()
+ {
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.CentigramPerMole).CentigramsPerMole, CentigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.DecagramPerMole).DecagramsPerMole, DecagramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.DecigramPerMole).DecigramsPerMole, DecigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.GramPerMole).GramsPerMole, GramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.HectogramPerMole).HectogramsPerMole, HectogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.KilogramPerMole).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.KilopoundPerMole).KilopoundsPerMole, KilopoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.MegapoundPerMole).MegapoundsPerMole, MegapoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.MicrogramPerMole).MicrogramsPerMole, MicrogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.MilligramPerMole).MilligramsPerMole, MilligramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.NanogramPerMole).NanogramsPerMole, NanogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.From(1, MolarMassUnit.PoundPerMole).PoundsPerMole, PoundsPerMoleTolerance);
+ }
+
+ [Fact]
+ public void As()
+ {
+ var kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ AssertEx.EqualTolerance(CentigramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.CentigramPerMole), CentigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(DecagramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.DecagramPerMole), DecagramsPerMoleTolerance);
+ AssertEx.EqualTolerance(DecigramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.DecigramPerMole), DecigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(GramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.GramPerMole), GramsPerMoleTolerance);
+ AssertEx.EqualTolerance(HectogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.HectogramPerMole), HectogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(KilogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilogramPerMole), KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(KilopoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.KilopoundPerMole), KilopoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(MegapoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MegapoundPerMole), MegapoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(MicrogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MicrogramPerMole), MicrogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(MilligramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.MilligramPerMole), MilligramsPerMoleTolerance);
+ AssertEx.EqualTolerance(NanogramsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.NanogramPerMole), NanogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(PoundsPerMoleInOneKilogramPerMole, kilogrampermole.As(MolarMassUnit.PoundPerMole), PoundsPerMoleTolerance);
+ }
+
+ [Fact]
+ public void ConversionRoundTrip()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ AssertEx.EqualTolerance(1, MolarMass.FromCentigramsPerMole(kilogrampermole.CentigramsPerMole).KilogramsPerMole, CentigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromDecagramsPerMole(kilogrampermole.DecagramsPerMole).KilogramsPerMole, DecagramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromDecigramsPerMole(kilogrampermole.DecigramsPerMole).KilogramsPerMole, DecigramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromGramsPerMole(kilogrampermole.GramsPerMole).KilogramsPerMole, GramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromHectogramsPerMole(kilogrampermole.HectogramsPerMole).KilogramsPerMole, HectogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromKilogramsPerMole(kilogrampermole.KilogramsPerMole).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromKilopoundsPerMole(kilogrampermole.KilopoundsPerMole).KilogramsPerMole, KilopoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromMegapoundsPerMole(kilogrampermole.MegapoundsPerMole).KilogramsPerMole, MegapoundsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromMicrogramsPerMole(kilogrampermole.MicrogramsPerMole).KilogramsPerMole, MicrogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromMilligramsPerMole(kilogrampermole.MilligramsPerMole).KilogramsPerMole, MilligramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromNanogramsPerMole(kilogrampermole.NanogramsPerMole).KilogramsPerMole, NanogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(1, MolarMass.FromPoundsPerMole(kilogrampermole.PoundsPerMole).KilogramsPerMole, PoundsPerMoleTolerance);
+ }
+
+ [Fact]
+ public void ArithmeticOperators()
+ {
+ MolarMass v = MolarMass.FromKilogramsPerMole(1);
+ AssertEx.EqualTolerance(-1, -v.KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(2, (MolarMass.FromKilogramsPerMole(3)-v).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(2, (v + v).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(10, (v*10).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(10, (10*v).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(2, (MolarMass.FromKilogramsPerMole(10)/5).KilogramsPerMole, KilogramsPerMoleTolerance);
+ AssertEx.EqualTolerance(2, MolarMass.FromKilogramsPerMole(10)/MolarMass.FromKilogramsPerMole(5), KilogramsPerMoleTolerance);
+ }
+
+ [Fact]
+ public void ComparisonOperators()
+ {
+ MolarMass oneKilogramPerMole = MolarMass.FromKilogramsPerMole(1);
+ MolarMass twoKilogramsPerMole = MolarMass.FromKilogramsPerMole(2);
+
+ Assert.True(oneKilogramPerMole < twoKilogramsPerMole);
+ Assert.True(oneKilogramPerMole <= twoKilogramsPerMole);
+ Assert.True(twoKilogramsPerMole > oneKilogramPerMole);
+ Assert.True(twoKilogramsPerMole >= oneKilogramPerMole);
+
+ Assert.False(oneKilogramPerMole > twoKilogramsPerMole);
+ Assert.False(oneKilogramPerMole >= twoKilogramsPerMole);
+ Assert.False(twoKilogramsPerMole < oneKilogramPerMole);
+ Assert.False(twoKilogramsPerMole <= oneKilogramPerMole);
+ }
+
+ [Fact]
+ public void CompareToIsImplemented()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ Assert.Equal(0, kilogrampermole.CompareTo(kilogrampermole));
+ Assert.True(kilogrampermole.CompareTo(MolarMass.Zero) > 0);
+ Assert.True(MolarMass.Zero.CompareTo(kilogrampermole) < 0);
+ }
+
+ [Fact]
+ public void CompareToThrowsOnTypeMismatch()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ Assert.Throws(() => kilogrampermole.CompareTo(new object()));
+ }
+
+ [Fact]
+ public void CompareToThrowsOnNull()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ Assert.Throws(() => kilogrampermole.CompareTo(null));
+ }
+
+
+ [Fact]
+ public void EqualityOperators()
+ {
+ MolarMass a = MolarMass.FromKilogramsPerMole(1);
+ MolarMass b = MolarMass.FromKilogramsPerMole(2);
+
+// ReSharper disable EqualExpressionComparison
+ Assert.True(a == a);
+ Assert.True(a != b);
+
+ Assert.False(a == b);
+ Assert.False(a != a);
+// ReSharper restore EqualExpressionComparison
+ }
+
+ [Fact]
+ public void EqualsIsImplemented()
+ {
+ MolarMass v = MolarMass.FromKilogramsPerMole(1);
+ Assert.True(v.Equals(MolarMass.FromKilogramsPerMole(1)));
+ Assert.False(v.Equals(MolarMass.Zero));
+ }
+
+ [Fact]
+ public void EqualsReturnsFalseOnTypeMismatch()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ Assert.False(kilogrampermole.Equals(new object()));
+ }
+
+ [Fact]
+ public void EqualsReturnsFalseOnNull()
+ {
+ MolarMass kilogrampermole = MolarMass.FromKilogramsPerMole(1);
+ Assert.False(kilogrampermole.Equals(null));
+ }
+ }
+}
diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarMassExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarMassExtensions.g.cs
new file mode 100644
index 0000000000..a4b7fd9ed4
--- /dev/null
+++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarMassExtensions.g.cs
@@ -0,0 +1,457 @@
+//------------------------------------------------------------------------------
+//
+// 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\MyUnit.extra.cs files to add code to generated quantities.
+// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
+// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2007 Andreas Gullberg Larsen (angularsen@gmail.com).
+// https://github.com/angularsen/UnitsNet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+// Windows Runtime Component does not support extension methods and method overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if !WINDOWS_UWP
+namespace UnitsNet.Extensions.NumberToMolarMass
+{
+ public static class NumberToMolarMassExtensions
+ {
+ #region CentigramPerMole
+
+ ///
+ public static MolarMass CentigramsPerMole(this int value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass? CentigramsPerMole(this int? value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass CentigramsPerMole(this long value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass? CentigramsPerMole(this long? value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass CentigramsPerMole(this double value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass? CentigramsPerMole(this double? value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass CentigramsPerMole(this float value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass? CentigramsPerMole(this float? value) => MolarMass.FromCentigramsPerMole(value);
+
+ ///
+ public static MolarMass CentigramsPerMole(this decimal value) => MolarMass.FromCentigramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? CentigramsPerMole(this decimal? value) => MolarMass.FromCentigramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region DecagramPerMole
+
+ ///
+ public static MolarMass DecagramsPerMole(this int value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass? DecagramsPerMole(this int? value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass DecagramsPerMole(this long value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass? DecagramsPerMole(this long? value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass DecagramsPerMole(this double value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass? DecagramsPerMole(this double? value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass DecagramsPerMole(this float value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass? DecagramsPerMole(this float? value) => MolarMass.FromDecagramsPerMole(value);
+
+ ///
+ public static MolarMass DecagramsPerMole(this decimal value) => MolarMass.FromDecagramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? DecagramsPerMole(this decimal? value) => MolarMass.FromDecagramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region DecigramPerMole
+
+ ///
+ public static MolarMass DecigramsPerMole(this int value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass? DecigramsPerMole(this int? value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass DecigramsPerMole(this long value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass? DecigramsPerMole(this long? value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass DecigramsPerMole(this double value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass? DecigramsPerMole(this double? value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass DecigramsPerMole(this float value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass? DecigramsPerMole(this float? value) => MolarMass.FromDecigramsPerMole(value);
+
+ ///
+ public static MolarMass DecigramsPerMole(this decimal value) => MolarMass.FromDecigramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? DecigramsPerMole(this decimal? value) => MolarMass.FromDecigramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region GramPerMole
+
+ ///
+ public static MolarMass GramsPerMole(this int value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass? GramsPerMole(this int? value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass GramsPerMole(this long value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass? GramsPerMole(this long? value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass GramsPerMole(this double value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass? GramsPerMole(this double? value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass GramsPerMole(this float value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass? GramsPerMole(this float? value) => MolarMass.FromGramsPerMole(value);
+
+ ///
+ public static MolarMass GramsPerMole(this decimal value) => MolarMass.FromGramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? GramsPerMole(this decimal? value) => MolarMass.FromGramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region HectogramPerMole
+
+ ///
+ public static MolarMass HectogramsPerMole(this int value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass? HectogramsPerMole(this int? value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass HectogramsPerMole(this long value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass? HectogramsPerMole(this long? value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass HectogramsPerMole(this double value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass? HectogramsPerMole(this double? value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass HectogramsPerMole(this float value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass? HectogramsPerMole(this float? value) => MolarMass.FromHectogramsPerMole(value);
+
+ ///
+ public static MolarMass HectogramsPerMole(this decimal value) => MolarMass.FromHectogramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? HectogramsPerMole(this decimal? value) => MolarMass.FromHectogramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region KilogramPerMole
+
+ ///
+ public static MolarMass KilogramsPerMole(this int value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass? KilogramsPerMole(this int? value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass KilogramsPerMole(this long value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass? KilogramsPerMole(this long? value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass KilogramsPerMole(this double value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass? KilogramsPerMole(this double? value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass KilogramsPerMole(this float value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass? KilogramsPerMole(this float? value) => MolarMass.FromKilogramsPerMole(value);
+
+ ///
+ public static MolarMass KilogramsPerMole(this decimal value) => MolarMass.FromKilogramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? KilogramsPerMole(this decimal? value) => MolarMass.FromKilogramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region KilopoundPerMole
+
+ ///
+ public static MolarMass KilopoundsPerMole(this int value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass? KilopoundsPerMole(this int? value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass KilopoundsPerMole(this long value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass? KilopoundsPerMole(this long? value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass KilopoundsPerMole(this double value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass? KilopoundsPerMole(this double? value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass KilopoundsPerMole(this float value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass? KilopoundsPerMole(this float? value) => MolarMass.FromKilopoundsPerMole(value);
+
+ ///
+ public static MolarMass KilopoundsPerMole(this decimal value) => MolarMass.FromKilopoundsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? KilopoundsPerMole(this decimal? value) => MolarMass.FromKilopoundsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region MegapoundPerMole
+
+ ///
+ public static MolarMass MegapoundsPerMole(this int value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass? MegapoundsPerMole(this int? value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass MegapoundsPerMole(this long value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass? MegapoundsPerMole(this long? value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass MegapoundsPerMole(this double value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass? MegapoundsPerMole(this double? value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass MegapoundsPerMole(this float value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass? MegapoundsPerMole(this float? value) => MolarMass.FromMegapoundsPerMole(value);
+
+ ///
+ public static MolarMass MegapoundsPerMole(this decimal value) => MolarMass.FromMegapoundsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? MegapoundsPerMole(this decimal? value) => MolarMass.FromMegapoundsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region MicrogramPerMole
+
+ ///
+ public static MolarMass MicrogramsPerMole(this int value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass? MicrogramsPerMole(this int? value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass MicrogramsPerMole(this long value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass? MicrogramsPerMole(this long? value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass MicrogramsPerMole(this double value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass? MicrogramsPerMole(this double? value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass MicrogramsPerMole(this float value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass? MicrogramsPerMole(this float? value) => MolarMass.FromMicrogramsPerMole(value);
+
+ ///
+ public static MolarMass MicrogramsPerMole(this decimal value) => MolarMass.FromMicrogramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? MicrogramsPerMole(this decimal? value) => MolarMass.FromMicrogramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region MilligramPerMole
+
+ ///
+ public static MolarMass MilligramsPerMole(this int value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass? MilligramsPerMole(this int? value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass MilligramsPerMole(this long value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass? MilligramsPerMole(this long? value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass MilligramsPerMole(this double value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass? MilligramsPerMole(this double? value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass MilligramsPerMole(this float value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass? MilligramsPerMole(this float? value) => MolarMass.FromMilligramsPerMole(value);
+
+ ///
+ public static MolarMass MilligramsPerMole(this decimal value) => MolarMass.FromMilligramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? MilligramsPerMole(this decimal? value) => MolarMass.FromMilligramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region NanogramPerMole
+
+ ///
+ public static MolarMass NanogramsPerMole(this int value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass? NanogramsPerMole(this int? value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass NanogramsPerMole(this long value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass? NanogramsPerMole(this long? value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass NanogramsPerMole(this double value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass? NanogramsPerMole(this double? value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass NanogramsPerMole(this float value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass? NanogramsPerMole(this float? value) => MolarMass.FromNanogramsPerMole(value);
+
+ ///
+ public static MolarMass NanogramsPerMole(this decimal value) => MolarMass.FromNanogramsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? NanogramsPerMole(this decimal? value) => MolarMass.FromNanogramsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ #region PoundPerMole
+
+ ///
+ public static MolarMass PoundsPerMole(this int value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass? PoundsPerMole(this int? value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass PoundsPerMole(this long value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass? PoundsPerMole(this long? value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass PoundsPerMole(this double value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass? PoundsPerMole(this double? value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass PoundsPerMole(this float value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass? PoundsPerMole(this float? value) => MolarMass.FromPoundsPerMole(value);
+
+ ///
+ public static MolarMass PoundsPerMole(this decimal value) => MolarMass.FromPoundsPerMole(Convert.ToDouble(value));
+
+ ///
+ public static MolarMass? PoundsPerMole(this decimal? value) => MolarMass.FromPoundsPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value));
+
+ #endregion
+
+ }
+}
+#endif
diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs
new file mode 100644
index 0000000000..ad83e7044f
--- /dev/null
+++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs
@@ -0,0 +1,1952 @@
+//------------------------------------------------------------------------------
+//
+// 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\MyUnit.extra.cs files to add code to generated quantities.
+// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
+// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2007 Andreas Gullberg Larsen (angularsen@gmail.com).
+// https://github.com/angularsen/UnitsNet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text.RegularExpressions;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+
+// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if WINDOWS_UWP
+using Culture = System.String;
+#else
+using Culture = System.IFormatProvider;
+#endif
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In chemistry, the molar mass M is a physical property defined as the mass of a given substance (chemical element or chemical compound) divided by the amount of substance.
+ ///
+ // ReSharper disable once PartialTypeWithSinglePart
+
+ // 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.
+#if WINDOWS_UWP
+ public sealed partial class MolarMass
+#else
+ public partial struct MolarMass : IComparable, IComparable
+#endif
+ {
+ ///
+ /// Base unit of MolarMass.
+ ///
+ private readonly double _kilogramsPerMole;
+
+ // Windows Runtime Component requires a default constructor
+#if WINDOWS_UWP
+ public MolarMass() : this(0)
+ {
+ }
+#endif
+
+ public MolarMass(double kilogramspermole)
+ {
+ _kilogramsPerMole = Convert.ToDouble(kilogramspermole);
+ }
+
+ // 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
+#if WINDOWS_UWP
+ private
+#else
+ public
+#endif
+ MolarMass(long kilogramspermole)
+ {
+ _kilogramsPerMole = Convert.ToDouble(kilogramspermole);
+ }
+
+ // 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
+ // Windows Runtime Component does not support decimal type
+#if WINDOWS_UWP
+ private
+#else
+ public
+#endif
+ MolarMass(decimal kilogramspermole)
+ {
+ _kilogramsPerMole = Convert.ToDouble(kilogramspermole);
+ }
+
+ #region Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.MolarMass;
+
+ ///
+ /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value.
+ ///
+ public static MolarMassUnit BaseUnit
+ {
+ get { return MolarMassUnit.KilogramPerMole; }
+ }
+
+ ///
+ /// All units of measurement for the MolarMass quantity.
+ ///
+ public static MolarMassUnit[] Units { get; } = Enum.GetValues(typeof(MolarMassUnit)).Cast().ToArray();
+
+ ///
+ /// Get MolarMass in CentigramsPerMole.
+ ///
+ public double CentigramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e-2d; }
+ }
+
+ ///
+ /// Get MolarMass in DecagramsPerMole.
+ ///
+ public double DecagramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e1d; }
+ }
+
+ ///
+ /// Get MolarMass in DecigramsPerMole.
+ ///
+ public double DecigramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e-1d; }
+ }
+
+ ///
+ /// Get MolarMass in GramsPerMole.
+ ///
+ public double GramsPerMole
+ {
+ get { return _kilogramsPerMole*1e3; }
+ }
+
+ ///
+ /// Get MolarMass in HectogramsPerMole.
+ ///
+ public double HectogramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e2d; }
+ }
+
+ ///
+ /// Get MolarMass in KilogramsPerMole.
+ ///
+ public double KilogramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e3d; }
+ }
+
+ ///
+ /// Get MolarMass in KilopoundsPerMole.
+ ///
+ public double KilopoundsPerMole
+ {
+ get { return (_kilogramsPerMole/0.45359237) / 1e3d; }
+ }
+
+ ///
+ /// Get MolarMass in MegapoundsPerMole.
+ ///
+ public double MegapoundsPerMole
+ {
+ get { return (_kilogramsPerMole/0.45359237) / 1e6d; }
+ }
+
+ ///
+ /// Get MolarMass in MicrogramsPerMole.
+ ///
+ public double MicrogramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e-6d; }
+ }
+
+ ///
+ /// Get MolarMass in MilligramsPerMole.
+ ///
+ public double MilligramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e-3d; }
+ }
+
+ ///
+ /// Get MolarMass in NanogramsPerMole.
+ ///
+ public double NanogramsPerMole
+ {
+ get { return (_kilogramsPerMole*1e3) / 1e-9d; }
+ }
+
+ ///
+ /// Get MolarMass in PoundsPerMole.
+ ///
+ public double PoundsPerMole
+ {
+ get { return _kilogramsPerMole/0.45359237; }
+ }
+
+ #endregion
+
+ #region Static
+
+ public static MolarMass Zero
+ {
+ get { return new MolarMass(); }
+ }
+
+ ///
+ /// Get MolarMass from CentigramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromCentigramsPerMole(double centigramspermole)
+ {
+ return new MolarMass((centigramspermole/1e3) * 1e-2d);
+ }
+
+ ///
+ /// Get MolarMass from CentigramsPerMole.
+ ///
+ public static MolarMass FromCentigramsPerMole(int centigramspermole)
+ {
+ return new MolarMass((centigramspermole/1e3) * 1e-2d);
+ }
+
+ ///
+ /// Get MolarMass from CentigramsPerMole.
+ ///
+ public static MolarMass FromCentigramsPerMole(long centigramspermole)
+ {
+ return new MolarMass((centigramspermole/1e3) * 1e-2d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from CentigramsPerMole of type decimal.
+ ///
+ public static MolarMass FromCentigramsPerMole(decimal centigramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(centigramspermole)/1e3) * 1e-2d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from DecagramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromDecagramsPerMole(double decagramspermole)
+ {
+ return new MolarMass((decagramspermole/1e3) * 1e1d);
+ }
+
+ ///
+ /// Get MolarMass from DecagramsPerMole.
+ ///
+ public static MolarMass FromDecagramsPerMole(int decagramspermole)
+ {
+ return new MolarMass((decagramspermole/1e3) * 1e1d);
+ }
+
+ ///
+ /// Get MolarMass from DecagramsPerMole.
+ ///
+ public static MolarMass FromDecagramsPerMole(long decagramspermole)
+ {
+ return new MolarMass((decagramspermole/1e3) * 1e1d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from DecagramsPerMole of type decimal.
+ ///
+ public static MolarMass FromDecagramsPerMole(decimal decagramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(decagramspermole)/1e3) * 1e1d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from DecigramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromDecigramsPerMole(double decigramspermole)
+ {
+ return new MolarMass((decigramspermole/1e3) * 1e-1d);
+ }
+
+ ///
+ /// Get MolarMass from DecigramsPerMole.
+ ///
+ public static MolarMass FromDecigramsPerMole(int decigramspermole)
+ {
+ return new MolarMass((decigramspermole/1e3) * 1e-1d);
+ }
+
+ ///
+ /// Get MolarMass from DecigramsPerMole.
+ ///
+ public static MolarMass FromDecigramsPerMole(long decigramspermole)
+ {
+ return new MolarMass((decigramspermole/1e3) * 1e-1d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from DecigramsPerMole of type decimal.
+ ///
+ public static MolarMass FromDecigramsPerMole(decimal decigramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(decigramspermole)/1e3) * 1e-1d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from GramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromGramsPerMole(double gramspermole)
+ {
+ return new MolarMass(gramspermole/1e3);
+ }
+
+ ///
+ /// Get MolarMass from GramsPerMole.
+ ///
+ public static MolarMass FromGramsPerMole(int gramspermole)
+ {
+ return new MolarMass(gramspermole/1e3);
+ }
+
+ ///
+ /// Get MolarMass from GramsPerMole.
+ ///
+ public static MolarMass FromGramsPerMole(long gramspermole)
+ {
+ return new MolarMass(gramspermole/1e3);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from GramsPerMole of type decimal.
+ ///
+ public static MolarMass FromGramsPerMole(decimal gramspermole)
+ {
+ return new MolarMass(Convert.ToDouble(gramspermole)/1e3);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from HectogramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromHectogramsPerMole(double hectogramspermole)
+ {
+ return new MolarMass((hectogramspermole/1e3) * 1e2d);
+ }
+
+ ///
+ /// Get MolarMass from HectogramsPerMole.
+ ///
+ public static MolarMass FromHectogramsPerMole(int hectogramspermole)
+ {
+ return new MolarMass((hectogramspermole/1e3) * 1e2d);
+ }
+
+ ///
+ /// Get MolarMass from HectogramsPerMole.
+ ///
+ public static MolarMass FromHectogramsPerMole(long hectogramspermole)
+ {
+ return new MolarMass((hectogramspermole/1e3) * 1e2d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from HectogramsPerMole of type decimal.
+ ///
+ public static MolarMass FromHectogramsPerMole(decimal hectogramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(hectogramspermole)/1e3) * 1e2d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from KilogramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromKilogramsPerMole(double kilogramspermole)
+ {
+ return new MolarMass((kilogramspermole/1e3) * 1e3d);
+ }
+
+ ///
+ /// Get MolarMass from KilogramsPerMole.
+ ///
+ public static MolarMass FromKilogramsPerMole(int kilogramspermole)
+ {
+ return new MolarMass((kilogramspermole/1e3) * 1e3d);
+ }
+
+ ///
+ /// Get MolarMass from KilogramsPerMole.
+ ///
+ public static MolarMass FromKilogramsPerMole(long kilogramspermole)
+ {
+ return new MolarMass((kilogramspermole/1e3) * 1e3d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from KilogramsPerMole of type decimal.
+ ///
+ public static MolarMass FromKilogramsPerMole(decimal kilogramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(kilogramspermole)/1e3) * 1e3d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from KilopoundsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromKilopoundsPerMole(double kilopoundspermole)
+ {
+ return new MolarMass((kilopoundspermole*0.45359237) * 1e3d);
+ }
+
+ ///
+ /// Get MolarMass from KilopoundsPerMole.
+ ///
+ public static MolarMass FromKilopoundsPerMole(int kilopoundspermole)
+ {
+ return new MolarMass((kilopoundspermole*0.45359237) * 1e3d);
+ }
+
+ ///
+ /// Get MolarMass from KilopoundsPerMole.
+ ///
+ public static MolarMass FromKilopoundsPerMole(long kilopoundspermole)
+ {
+ return new MolarMass((kilopoundspermole*0.45359237) * 1e3d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from KilopoundsPerMole of type decimal.
+ ///
+ public static MolarMass FromKilopoundsPerMole(decimal kilopoundspermole)
+ {
+ return new MolarMass((Convert.ToDouble(kilopoundspermole)*0.45359237) * 1e3d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from MegapoundsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromMegapoundsPerMole(double megapoundspermole)
+ {
+ return new MolarMass((megapoundspermole*0.45359237) * 1e6d);
+ }
+
+ ///
+ /// Get MolarMass from MegapoundsPerMole.
+ ///
+ public static MolarMass FromMegapoundsPerMole(int megapoundspermole)
+ {
+ return new MolarMass((megapoundspermole*0.45359237) * 1e6d);
+ }
+
+ ///
+ /// Get MolarMass from MegapoundsPerMole.
+ ///
+ public static MolarMass FromMegapoundsPerMole(long megapoundspermole)
+ {
+ return new MolarMass((megapoundspermole*0.45359237) * 1e6d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from MegapoundsPerMole of type decimal.
+ ///
+ public static MolarMass FromMegapoundsPerMole(decimal megapoundspermole)
+ {
+ return new MolarMass((Convert.ToDouble(megapoundspermole)*0.45359237) * 1e6d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from MicrogramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromMicrogramsPerMole(double microgramspermole)
+ {
+ return new MolarMass((microgramspermole/1e3) * 1e-6d);
+ }
+
+ ///
+ /// Get MolarMass from MicrogramsPerMole.
+ ///
+ public static MolarMass FromMicrogramsPerMole(int microgramspermole)
+ {
+ return new MolarMass((microgramspermole/1e3) * 1e-6d);
+ }
+
+ ///
+ /// Get MolarMass from MicrogramsPerMole.
+ ///
+ public static MolarMass FromMicrogramsPerMole(long microgramspermole)
+ {
+ return new MolarMass((microgramspermole/1e3) * 1e-6d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from MicrogramsPerMole of type decimal.
+ ///
+ public static MolarMass FromMicrogramsPerMole(decimal microgramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(microgramspermole)/1e3) * 1e-6d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from MilligramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromMilligramsPerMole(double milligramspermole)
+ {
+ return new MolarMass((milligramspermole/1e3) * 1e-3d);
+ }
+
+ ///
+ /// Get MolarMass from MilligramsPerMole.
+ ///
+ public static MolarMass FromMilligramsPerMole(int milligramspermole)
+ {
+ return new MolarMass((milligramspermole/1e3) * 1e-3d);
+ }
+
+ ///
+ /// Get MolarMass from MilligramsPerMole.
+ ///
+ public static MolarMass FromMilligramsPerMole(long milligramspermole)
+ {
+ return new MolarMass((milligramspermole/1e3) * 1e-3d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from MilligramsPerMole of type decimal.
+ ///
+ public static MolarMass FromMilligramsPerMole(decimal milligramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(milligramspermole)/1e3) * 1e-3d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from NanogramsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromNanogramsPerMole(double nanogramspermole)
+ {
+ return new MolarMass((nanogramspermole/1e3) * 1e-9d);
+ }
+
+ ///
+ /// Get MolarMass from NanogramsPerMole.
+ ///
+ public static MolarMass FromNanogramsPerMole(int nanogramspermole)
+ {
+ return new MolarMass((nanogramspermole/1e3) * 1e-9d);
+ }
+
+ ///
+ /// Get MolarMass from NanogramsPerMole.
+ ///
+ public static MolarMass FromNanogramsPerMole(long nanogramspermole)
+ {
+ return new MolarMass((nanogramspermole/1e3) * 1e-9d);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from NanogramsPerMole of type decimal.
+ ///
+ public static MolarMass FromNanogramsPerMole(decimal nanogramspermole)
+ {
+ return new MolarMass((Convert.ToDouble(nanogramspermole)/1e3) * 1e-9d);
+ }
+#endif
+
+ ///
+ /// Get MolarMass from PoundsPerMole.
+ ///
+#if NETFX_CORE
+ [Windows.Foundation.Metadata.DefaultOverload]
+#endif
+ public static MolarMass FromPoundsPerMole(double poundspermole)
+ {
+ return new MolarMass(poundspermole*0.45359237);
+ }
+
+ ///
+ /// Get MolarMass from PoundsPerMole.
+ ///
+ public static MolarMass FromPoundsPerMole(int poundspermole)
+ {
+ return new MolarMass(poundspermole*0.45359237);
+ }
+
+ ///
+ /// Get MolarMass from PoundsPerMole.
+ ///
+ public static MolarMass FromPoundsPerMole(long poundspermole)
+ {
+ return new MolarMass(poundspermole*0.45359237);
+ }
+
+ // Windows Runtime Component does not support decimal type
+#if !WINDOWS_UWP
+ ///
+ /// Get MolarMass from PoundsPerMole of type decimal.
+ ///
+ public static MolarMass FromPoundsPerMole(decimal poundspermole)
+ {
+ return new MolarMass(Convert.ToDouble(poundspermole)*0.45359237);
+ }
+#endif
+
+ // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if !WINDOWS_UWP
+ ///
+ /// Get nullable MolarMass from nullable CentigramsPerMole.
+ ///
+ public static MolarMass? FromCentigramsPerMole(double? centigramspermole)
+ {
+ if (centigramspermole.HasValue)
+ {
+ return FromCentigramsPerMole(centigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable CentigramsPerMole.
+ ///
+ public static MolarMass? FromCentigramsPerMole(int? centigramspermole)
+ {
+ if (centigramspermole.HasValue)
+ {
+ return FromCentigramsPerMole(centigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable CentigramsPerMole.
+ ///
+ public static MolarMass? FromCentigramsPerMole(long? centigramspermole)
+ {
+ if (centigramspermole.HasValue)
+ {
+ return FromCentigramsPerMole(centigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from CentigramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromCentigramsPerMole(decimal? centigramspermole)
+ {
+ if (centigramspermole.HasValue)
+ {
+ return FromCentigramsPerMole(centigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable DecagramsPerMole.
+ ///
+ public static MolarMass? FromDecagramsPerMole(double? decagramspermole)
+ {
+ if (decagramspermole.HasValue)
+ {
+ return FromDecagramsPerMole(decagramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable DecagramsPerMole.
+ ///
+ public static MolarMass? FromDecagramsPerMole(int? decagramspermole)
+ {
+ if (decagramspermole.HasValue)
+ {
+ return FromDecagramsPerMole(decagramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable DecagramsPerMole.
+ ///
+ public static MolarMass? FromDecagramsPerMole(long? decagramspermole)
+ {
+ if (decagramspermole.HasValue)
+ {
+ return FromDecagramsPerMole(decagramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from DecagramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromDecagramsPerMole(decimal? decagramspermole)
+ {
+ if (decagramspermole.HasValue)
+ {
+ return FromDecagramsPerMole(decagramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable DecigramsPerMole.
+ ///
+ public static MolarMass? FromDecigramsPerMole(double? decigramspermole)
+ {
+ if (decigramspermole.HasValue)
+ {
+ return FromDecigramsPerMole(decigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable DecigramsPerMole.
+ ///
+ public static MolarMass? FromDecigramsPerMole(int? decigramspermole)
+ {
+ if (decigramspermole.HasValue)
+ {
+ return FromDecigramsPerMole(decigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable DecigramsPerMole.
+ ///
+ public static MolarMass? FromDecigramsPerMole(long? decigramspermole)
+ {
+ if (decigramspermole.HasValue)
+ {
+ return FromDecigramsPerMole(decigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from DecigramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromDecigramsPerMole(decimal? decigramspermole)
+ {
+ if (decigramspermole.HasValue)
+ {
+ return FromDecigramsPerMole(decigramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable GramsPerMole.
+ ///
+ public static MolarMass? FromGramsPerMole(double? gramspermole)
+ {
+ if (gramspermole.HasValue)
+ {
+ return FromGramsPerMole(gramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable GramsPerMole.
+ ///
+ public static MolarMass? FromGramsPerMole(int? gramspermole)
+ {
+ if (gramspermole.HasValue)
+ {
+ return FromGramsPerMole(gramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable GramsPerMole.
+ ///
+ public static MolarMass? FromGramsPerMole(long? gramspermole)
+ {
+ if (gramspermole.HasValue)
+ {
+ return FromGramsPerMole(gramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from GramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromGramsPerMole(decimal? gramspermole)
+ {
+ if (gramspermole.HasValue)
+ {
+ return FromGramsPerMole(gramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable HectogramsPerMole.
+ ///
+ public static MolarMass? FromHectogramsPerMole(double? hectogramspermole)
+ {
+ if (hectogramspermole.HasValue)
+ {
+ return FromHectogramsPerMole(hectogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable HectogramsPerMole.
+ ///
+ public static MolarMass? FromHectogramsPerMole(int? hectogramspermole)
+ {
+ if (hectogramspermole.HasValue)
+ {
+ return FromHectogramsPerMole(hectogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable HectogramsPerMole.
+ ///
+ public static MolarMass? FromHectogramsPerMole(long? hectogramspermole)
+ {
+ if (hectogramspermole.HasValue)
+ {
+ return FromHectogramsPerMole(hectogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from HectogramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromHectogramsPerMole(decimal? hectogramspermole)
+ {
+ if (hectogramspermole.HasValue)
+ {
+ return FromHectogramsPerMole(hectogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable KilogramsPerMole.
+ ///
+ public static MolarMass? FromKilogramsPerMole(double? kilogramspermole)
+ {
+ if (kilogramspermole.HasValue)
+ {
+ return FromKilogramsPerMole(kilogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable KilogramsPerMole.
+ ///
+ public static MolarMass? FromKilogramsPerMole(int? kilogramspermole)
+ {
+ if (kilogramspermole.HasValue)
+ {
+ return FromKilogramsPerMole(kilogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable KilogramsPerMole.
+ ///
+ public static MolarMass? FromKilogramsPerMole(long? kilogramspermole)
+ {
+ if (kilogramspermole.HasValue)
+ {
+ return FromKilogramsPerMole(kilogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from KilogramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromKilogramsPerMole(decimal? kilogramspermole)
+ {
+ if (kilogramspermole.HasValue)
+ {
+ return FromKilogramsPerMole(kilogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable KilopoundsPerMole.
+ ///
+ public static MolarMass? FromKilopoundsPerMole(double? kilopoundspermole)
+ {
+ if (kilopoundspermole.HasValue)
+ {
+ return FromKilopoundsPerMole(kilopoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable KilopoundsPerMole.
+ ///
+ public static MolarMass? FromKilopoundsPerMole(int? kilopoundspermole)
+ {
+ if (kilopoundspermole.HasValue)
+ {
+ return FromKilopoundsPerMole(kilopoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable KilopoundsPerMole.
+ ///
+ public static MolarMass? FromKilopoundsPerMole(long? kilopoundspermole)
+ {
+ if (kilopoundspermole.HasValue)
+ {
+ return FromKilopoundsPerMole(kilopoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from KilopoundsPerMole of type decimal.
+ ///
+ public static MolarMass? FromKilopoundsPerMole(decimal? kilopoundspermole)
+ {
+ if (kilopoundspermole.HasValue)
+ {
+ return FromKilopoundsPerMole(kilopoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MegapoundsPerMole.
+ ///
+ public static MolarMass? FromMegapoundsPerMole(double? megapoundspermole)
+ {
+ if (megapoundspermole.HasValue)
+ {
+ return FromMegapoundsPerMole(megapoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MegapoundsPerMole.
+ ///
+ public static MolarMass? FromMegapoundsPerMole(int? megapoundspermole)
+ {
+ if (megapoundspermole.HasValue)
+ {
+ return FromMegapoundsPerMole(megapoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MegapoundsPerMole.
+ ///
+ public static MolarMass? FromMegapoundsPerMole(long? megapoundspermole)
+ {
+ if (megapoundspermole.HasValue)
+ {
+ return FromMegapoundsPerMole(megapoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from MegapoundsPerMole of type decimal.
+ ///
+ public static MolarMass? FromMegapoundsPerMole(decimal? megapoundspermole)
+ {
+ if (megapoundspermole.HasValue)
+ {
+ return FromMegapoundsPerMole(megapoundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MicrogramsPerMole.
+ ///
+ public static MolarMass? FromMicrogramsPerMole(double? microgramspermole)
+ {
+ if (microgramspermole.HasValue)
+ {
+ return FromMicrogramsPerMole(microgramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MicrogramsPerMole.
+ ///
+ public static MolarMass? FromMicrogramsPerMole(int? microgramspermole)
+ {
+ if (microgramspermole.HasValue)
+ {
+ return FromMicrogramsPerMole(microgramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MicrogramsPerMole.
+ ///
+ public static MolarMass? FromMicrogramsPerMole(long? microgramspermole)
+ {
+ if (microgramspermole.HasValue)
+ {
+ return FromMicrogramsPerMole(microgramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from MicrogramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromMicrogramsPerMole(decimal? microgramspermole)
+ {
+ if (microgramspermole.HasValue)
+ {
+ return FromMicrogramsPerMole(microgramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MilligramsPerMole.
+ ///
+ public static MolarMass? FromMilligramsPerMole(double? milligramspermole)
+ {
+ if (milligramspermole.HasValue)
+ {
+ return FromMilligramsPerMole(milligramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MilligramsPerMole.
+ ///
+ public static MolarMass? FromMilligramsPerMole(int? milligramspermole)
+ {
+ if (milligramspermole.HasValue)
+ {
+ return FromMilligramsPerMole(milligramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable MilligramsPerMole.
+ ///
+ public static MolarMass? FromMilligramsPerMole(long? milligramspermole)
+ {
+ if (milligramspermole.HasValue)
+ {
+ return FromMilligramsPerMole(milligramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from MilligramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromMilligramsPerMole(decimal? milligramspermole)
+ {
+ if (milligramspermole.HasValue)
+ {
+ return FromMilligramsPerMole(milligramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable NanogramsPerMole.
+ ///
+ public static MolarMass? FromNanogramsPerMole(double? nanogramspermole)
+ {
+ if (nanogramspermole.HasValue)
+ {
+ return FromNanogramsPerMole(nanogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable NanogramsPerMole.
+ ///
+ public static MolarMass? FromNanogramsPerMole(int? nanogramspermole)
+ {
+ if (nanogramspermole.HasValue)
+ {
+ return FromNanogramsPerMole(nanogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable NanogramsPerMole.
+ ///
+ public static MolarMass? FromNanogramsPerMole(long? nanogramspermole)
+ {
+ if (nanogramspermole.HasValue)
+ {
+ return FromNanogramsPerMole(nanogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from NanogramsPerMole of type decimal.
+ ///
+ public static MolarMass? FromNanogramsPerMole(decimal? nanogramspermole)
+ {
+ if (nanogramspermole.HasValue)
+ {
+ return FromNanogramsPerMole(nanogramspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable PoundsPerMole.
+ ///
+ public static MolarMass? FromPoundsPerMole(double? poundspermole)
+ {
+ if (poundspermole.HasValue)
+ {
+ return FromPoundsPerMole(poundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable PoundsPerMole.
+ ///
+ public static MolarMass? FromPoundsPerMole(int? poundspermole)
+ {
+ if (poundspermole.HasValue)
+ {
+ return FromPoundsPerMole(poundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from nullable PoundsPerMole.
+ ///
+ public static MolarMass? FromPoundsPerMole(long? poundspermole)
+ {
+ if (poundspermole.HasValue)
+ {
+ return FromPoundsPerMole(poundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Get nullable MolarMass from PoundsPerMole of type decimal.
+ ///
+ public static MolarMass? FromPoundsPerMole(decimal? poundspermole)
+ {
+ if (poundspermole.HasValue)
+ {
+ return FromPoundsPerMole(poundspermole.Value);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+#endif
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// MolarMass unit value.
+ public static MolarMass From(double val, MolarMassUnit fromUnit)
+ {
+ switch (fromUnit)
+ {
+ case MolarMassUnit.CentigramPerMole:
+ return FromCentigramsPerMole(val);
+ case MolarMassUnit.DecagramPerMole:
+ return FromDecagramsPerMole(val);
+ case MolarMassUnit.DecigramPerMole:
+ return FromDecigramsPerMole(val);
+ case MolarMassUnit.GramPerMole:
+ return FromGramsPerMole(val);
+ case MolarMassUnit.HectogramPerMole:
+ return FromHectogramsPerMole(val);
+ case MolarMassUnit.KilogramPerMole:
+ return FromKilogramsPerMole(val);
+ case MolarMassUnit.KilopoundPerMole:
+ return FromKilopoundsPerMole(val);
+ case MolarMassUnit.MegapoundPerMole:
+ return FromMegapoundsPerMole(val);
+ case MolarMassUnit.MicrogramPerMole:
+ return FromMicrogramsPerMole(val);
+ case MolarMassUnit.MilligramPerMole:
+ return FromMilligramsPerMole(val);
+ case MolarMassUnit.NanogramPerMole:
+ return FromNanogramsPerMole(val);
+ case MolarMassUnit.PoundPerMole:
+ return FromPoundsPerMole(val);
+
+ default:
+ throw new NotImplementedException("fromUnit: " + fromUnit);
+ }
+ }
+
+ // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if !WINDOWS_UWP
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// MolarMass unit value.
+ public static MolarMass? From(double? value, MolarMassUnit fromUnit)
+ {
+ if (!value.HasValue)
+ {
+ return null;
+ }
+ switch (fromUnit)
+ {
+ case MolarMassUnit.CentigramPerMole:
+ return FromCentigramsPerMole(value.Value);
+ case MolarMassUnit.DecagramPerMole:
+ return FromDecagramsPerMole(value.Value);
+ case MolarMassUnit.DecigramPerMole:
+ return FromDecigramsPerMole(value.Value);
+ case MolarMassUnit.GramPerMole:
+ return FromGramsPerMole(value.Value);
+ case MolarMassUnit.HectogramPerMole:
+ return FromHectogramsPerMole(value.Value);
+ case MolarMassUnit.KilogramPerMole:
+ return FromKilogramsPerMole(value.Value);
+ case MolarMassUnit.KilopoundPerMole:
+ return FromKilopoundsPerMole(value.Value);
+ case MolarMassUnit.MegapoundPerMole:
+ return FromMegapoundsPerMole(value.Value);
+ case MolarMassUnit.MicrogramPerMole:
+ return FromMicrogramsPerMole(value.Value);
+ case MolarMassUnit.MilligramPerMole:
+ return FromMilligramsPerMole(value.Value);
+ case MolarMassUnit.NanogramPerMole:
+ return FromNanogramsPerMole(value.Value);
+ case MolarMassUnit.PoundPerMole:
+ return FromPoundsPerMole(value.Value);
+
+ default:
+ throw new NotImplementedException("fromUnit: " + fromUnit);
+ }
+ }
+#endif
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ [UsedImplicitly]
+ public static string GetAbbreviation(MolarMassUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Culture to use for localization. Defaults to Thread.CurrentUICulture.
+ /// Unit abbreviation string.
+ [UsedImplicitly]
+ public static string GetAbbreviation(MolarMassUnit unit, [CanBeNull] Culture culture)
+ {
+ return UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit);
+ }
+
+ #endregion
+
+ #region Arithmetic Operators
+
+ // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if !WINDOWS_UWP
+ public static MolarMass operator -(MolarMass right)
+ {
+ return new MolarMass(-right._kilogramsPerMole);
+ }
+
+ public static MolarMass operator +(MolarMass left, MolarMass right)
+ {
+ return new MolarMass(left._kilogramsPerMole + right._kilogramsPerMole);
+ }
+
+ public static MolarMass operator -(MolarMass left, MolarMass right)
+ {
+ return new MolarMass(left._kilogramsPerMole - right._kilogramsPerMole);
+ }
+
+ public static MolarMass operator *(double left, MolarMass right)
+ {
+ return new MolarMass(left*right._kilogramsPerMole);
+ }
+
+ public static MolarMass operator *(MolarMass left, double right)
+ {
+ return new MolarMass(left._kilogramsPerMole*(double)right);
+ }
+
+ public static MolarMass operator /(MolarMass left, double right)
+ {
+ return new MolarMass(left._kilogramsPerMole/(double)right);
+ }
+
+ public static double operator /(MolarMass left, MolarMass right)
+ {
+ return Convert.ToDouble(left._kilogramsPerMole/right._kilogramsPerMole);
+ }
+#endif
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if (obj == null) throw new ArgumentNullException("obj");
+ if (!(obj is MolarMass)) throw new ArgumentException("Expected type MolarMass.", "obj");
+ return CompareTo((MolarMass) obj);
+ }
+
+ // 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
+#if WINDOWS_UWP
+ internal
+#else
+ public
+#endif
+ int CompareTo(MolarMass other)
+ {
+ return _kilogramsPerMole.CompareTo(other._kilogramsPerMole);
+ }
+
+ // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if !WINDOWS_UWP
+ public static bool operator <=(MolarMass left, MolarMass right)
+ {
+ return left._kilogramsPerMole <= right._kilogramsPerMole;
+ }
+
+ public static bool operator >=(MolarMass left, MolarMass right)
+ {
+ return left._kilogramsPerMole >= right._kilogramsPerMole;
+ }
+
+ public static bool operator <(MolarMass left, MolarMass right)
+ {
+ return left._kilogramsPerMole < right._kilogramsPerMole;
+ }
+
+ public static bool operator >(MolarMass left, MolarMass right)
+ {
+ return left._kilogramsPerMole > right._kilogramsPerMole;
+ }
+
+ public static bool operator ==(MolarMass left, MolarMass right)
+ {
+ // ReSharper disable once CompareOfFloatsByEqualityOperator
+ return left._kilogramsPerMole == right._kilogramsPerMole;
+ }
+
+ public static bool operator !=(MolarMass left, MolarMass right)
+ {
+ // ReSharper disable once CompareOfFloatsByEqualityOperator
+ return left._kilogramsPerMole != right._kilogramsPerMole;
+ }
+#endif
+
+ public override bool Equals(object obj)
+ {
+ if (obj == null || GetType() != obj.GetType())
+ {
+ return false;
+ }
+
+ return _kilogramsPerMole.Equals(((MolarMass) obj)._kilogramsPerMole);
+ }
+
+ public override int GetHashCode()
+ {
+ return _kilogramsPerMole.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value in new unit if successful, exception otherwise.
+ /// If conversion was not successful.
+ public double As(MolarMassUnit unit)
+ {
+ switch (unit)
+ {
+ case MolarMassUnit.CentigramPerMole:
+ return CentigramsPerMole;
+ case MolarMassUnit.DecagramPerMole:
+ return DecagramsPerMole;
+ case MolarMassUnit.DecigramPerMole:
+ return DecigramsPerMole;
+ case MolarMassUnit.GramPerMole:
+ return GramsPerMole;
+ case MolarMassUnit.HectogramPerMole:
+ return HectogramsPerMole;
+ case MolarMassUnit.KilogramPerMole:
+ return KilogramsPerMole;
+ case MolarMassUnit.KilopoundPerMole:
+ return KilopoundsPerMole;
+ case MolarMassUnit.MegapoundPerMole:
+ return MegapoundsPerMole;
+ case MolarMassUnit.MicrogramPerMole:
+ return MicrogramsPerMole;
+ case MolarMassUnit.MilligramPerMole:
+ return MilligramsPerMole;
+ case MolarMassUnit.NanogramPerMole:
+ return NanogramsPerMole;
+ case MolarMassUnit.PoundPerMole:
+ return PoundsPerMole;
+
+ default:
+ throw new NotImplementedException("unit: " + unit);
+ }
+ }
+
+ #endregion
+
+ #region Parsing
+
+ ///
+ /// 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 MolarMass 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}
+ /// Format to use when parsing number and unit. If it is null, it defaults to for parsing the number and for parsing the unit abbreviation by culture/language.
+ ///
+ /// 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 MolarMass Parse(string str, [CanBeNull] Culture culture)
+ {
+ if (str == null) throw new ArgumentNullException("str");
+
+ // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if WINDOWS_UWP
+ IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
+#else
+ IFormatProvider formatProvider = culture;
+#endif
+ return QuantityParser.Parse(str, formatProvider,
+ delegate(string value, string unit, IFormatProvider formatProvider2)
+ {
+ double parsedValue = double.Parse(value, formatProvider2);
+ MolarMassUnit parsedUnit = ParseUnit(unit, formatProvider2);
+ return From(parsedValue, parsedUnit);
+ }, (x, y) => FromKilogramsPerMole(x.KilogramsPerMole + y.KilogramsPerMole));
+ }
+
+ ///
+ /// 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 MolarMass 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}
+ /// Format to use when parsing number and unit. If it is null, it defaults to for parsing the number and for parsing the unit abbreviation by culture/language.
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] Culture culture, out MolarMass result)
+ {
+ try
+ {
+ result = Parse(str, culture);
+ return true;
+ }
+ catch
+ {
+ result = default(MolarMass);
+ return false;
+ }
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static MolarMassUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, (IFormatProvider)null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static MolarMassUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName));
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+
+ // 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
+#if WINDOWS_UWP
+ internal
+#else
+ public
+#endif
+ static MolarMassUnit ParseUnit(string str, IFormatProvider formatProvider = null)
+ {
+ if (str == null) throw new ArgumentNullException("str");
+
+ var unitSystem = UnitSystem.GetCached(formatProvider);
+ var unit = unitSystem.Parse(str.Trim());
+
+ if (unit == MolarMassUnit.Undefined)
+ {
+ var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized MolarMassUnit.");
+ newEx.Data["input"] = str;
+ newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)";
+ throw newEx;
+ }
+
+ return unit;
+ }
+
+ #endregion
+
+ ///
+ /// Set the default unit used by ToString(). Default is KilogramPerMole
+ ///
+ public static MolarMassUnit ToStringDefaultUnit { get; set; } = MolarMassUnit.KilogramPerMole;
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(ToStringDefaultUnit);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
+ ///
+ /// Unit representation to use.
+ /// String representation.
+ public string ToString(MolarMassUnit unit)
+ {
+ return ToString(unit, null, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// Unit representation to use.
+ /// Culture to use for localization and number formatting.
+ /// String representation.
+ public string ToString(MolarMassUnit unit, [CanBeNull] Culture culture)
+ {
+ return ToString(unit, culture, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// Unit representation to use.
+ /// Culture to use for localization and number formatting.
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ [UsedImplicitly]
+ public string ToString(MolarMassUnit unit, [CanBeNull] Culture culture, int significantDigitsAfterRadix)
+ {
+ double value = As(unit);
+ string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(unit, culture, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// Culture to use for localization and number formatting.
+ /// Unit representation to use.
+ /// 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.
+ [UsedImplicitly]
+ public string ToString(MolarMassUnit unit, [CanBeNull] Culture culture, [NotNull] string format,
+ [NotNull] params object[] args)
+ {
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx
+#if WINDOWS_UWP
+ IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
+#else
+ IFormatProvider formatProvider = culture;
+#endif
+ double value = As(unit);
+ object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
+ return string.Format(formatProvider, format, formatArgs);
+ }
+
+ ///
+ /// Represents the largest possible value of MolarMass
+ ///
+ public static MolarMass MaxValue
+ {
+ get
+ {
+ return new MolarMass(double.MaxValue);
+ }
+ }
+
+ ///
+ /// Represents the smallest possible value of MolarMass
+ ///
+ public static MolarMass MinValue
+ {
+ get
+ {
+ return new MolarMass(double.MinValue);
+ }
+ }
+ }
+}
diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs
index 753bf3bf6b..83b20ab126 100644
--- a/UnitsNet/GeneratedCode/QuantityType.g.cs
+++ b/UnitsNet/GeneratedCode/QuantityType.g.cs
@@ -79,6 +79,7 @@ public enum QuantityType
MassFlow,
MassMomentOfInertia,
Molarity,
+ MolarMass,
Power,
PowerRatio,
Pressure,
diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
index 9582a43b3a..9deefc4110 100644
--- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
+++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
@@ -1923,6 +1923,82 @@ private static readonly ReadOnlyCollection DefaultLocalization
new AbbreviationsForCulture("en-US", "pmol/L"),
}),
}),
+ new UnitLocalization(typeof (MolarMassUnit),
+ new[]
+ {
+ new CulturesForEnumValue((int) MolarMassUnit.CentigramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "cg/mol"),
+ new AbbreviationsForCulture("ru-RU", "сг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.DecagramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "dag/mol"),
+ new AbbreviationsForCulture("ru-RU", "даг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.DecigramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "dg/mol"),
+ new AbbreviationsForCulture("ru-RU", "дг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.GramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "g/mol"),
+ new AbbreviationsForCulture("ru-RU", "г/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.HectogramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "hg/mol"),
+ new AbbreviationsForCulture("ru-RU", "гг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.KilogramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "kg/mol"),
+ new AbbreviationsForCulture("ru-RU", "кг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.KilopoundPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "klb/mol"),
+ new AbbreviationsForCulture("ru-RU", "kфунт/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.MegapoundPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "Mlb/mol"),
+ new AbbreviationsForCulture("ru-RU", "Mфунт/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.MicrogramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "µg/mol"),
+ new AbbreviationsForCulture("ru-RU", "мкг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.MilligramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "mg/mol"),
+ new AbbreviationsForCulture("ru-RU", "мг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.NanogramPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "ng/mol"),
+ new AbbreviationsForCulture("ru-RU", "нг/моль"),
+ }),
+ new CulturesForEnumValue((int) MolarMassUnit.PoundPerMole,
+ new[]
+ {
+ new AbbreviationsForCulture("en-US", "lb/mol"),
+ new AbbreviationsForCulture("ru-RU", "фунт/моль"),
+ }),
+ }),
new UnitLocalization(typeof (PowerUnit),
new[]
{
diff --git a/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs
new file mode 100644
index 0000000000..7d0bf7645a
--- /dev/null
+++ b/UnitsNet/GeneratedCode/Units/MolarMassUnit.g.cs
@@ -0,0 +1,58 @@
+//------------------------------------------------------------------------------
+//
+// 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\MyUnit.extra.cs files to add code to generated quantities.
+// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior.
+// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2007 Andreas Gullberg Larsen (angularsen@gmail.com).
+// https://github.com/angularsen/UnitsNet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// ReSharper disable once CheckNamespace
+namespace UnitsNet.Units
+{
+ public enum MolarMassUnit
+ {
+ Undefined = 0,
+ CentigramPerMole,
+ DecagramPerMole,
+ DecigramPerMole,
+ GramPerMole,
+ HectogramPerMole,
+ KilogramPerMole,
+ KilopoundPerMole,
+ MegapoundPerMole,
+ MicrogramPerMole,
+ MilligramPerMole,
+ NanogramPerMole,
+ PoundPerMole,
+ }
+}
diff --git a/UnitsNet/UnitDefinitions/MolarMass.json b/UnitsNet/UnitDefinitions/MolarMass.json
new file mode 100644
index 0000000000..03674da0f2
--- /dev/null
+++ b/UnitsNet/UnitDefinitions/MolarMass.json
@@ -0,0 +1,42 @@
+{
+ "Name": "MolarMass",
+ "BaseUnit": "KilogramPerMole",
+ "XmlDoc": "In chemistry, the molar mass M is a physical property defined as the mass of a given substance (chemical element or chemical compound) divided by the amount of substance.",
+ "Units": [
+ {
+ "SingularName": "GramPerMole",
+ "PluralName": "GramsPerMole",
+ "FromUnitToBaseFunc": "x/1e3",
+ "FromBaseToUnitFunc": "x*1e3",
+ "Prefixes": [ "Nano", "Micro", "Milli", "Centi", "Deci", "Deca", "Hecto", "Kilo" ],
+ "Localization": [
+ {
+ "Culture": "en-US",
+ "Abbreviations": [ "g/mol" ]
+ },
+ {
+ "Culture": "ru-RU",
+ "Abbreviations": [ "г/моль" ],
+ "AbbreviationsWithPrefixes": [ "нг/моль", "мкг/моль", "мг/моль", "сг/моль", "дг/моль", "даг/моль", "гг/моль", "кг/моль" ]
+ }
+ ]
+ },
+ {
+ "SingularName": "PoundPerMole",
+ "PluralName": "PoundsPerMole",
+ "FromUnitToBaseFunc": "x*0.45359237",
+ "FromBaseToUnitFunc": "x/0.45359237",
+ "Prefixes": [ "Kilo", "Mega" ],
+ "Localization": [
+ {
+ "Culture": "en-US",
+ "Abbreviations": [ "lb/mol" ]
+ },
+ {
+ "Culture": "ru-RU",
+ "Abbreviations": [ "фунт/моль" ]
+ }
+ ]
+ }
+ ]
+}