From e51cd526eb7a03a274ca008ed56bd65a2e4ecea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Tun=C3=A7er?= Date: Tue, 7 Nov 2017 17:04:30 +0300 Subject: [PATCH] Add MolarEnergy (#309) --- UnitsNet.Tests/CustomCode/MolarEnergyTests.cs | 53 + .../GeneratedCode/MolarEnergyTestsBase.g.cs | 191 ++++ .../Number/NumberToMolarEnergyExtensions.g.cs | 151 +++ .../GeneratedCode/Quantities/MolarEnergy.g.cs | 944 ++++++++++++++++++ UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitSystem.Default.g.cs | 19 + .../GeneratedCode/Units/MolarEnergyUnit.g.cs | 49 + UnitsNet/UnitDefinitions/MolarEnergy.json | 20 + 8 files changed, 1428 insertions(+) create mode 100644 UnitsNet.Tests/CustomCode/MolarEnergyTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarEnergyExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/MolarEnergyUnit.g.cs create mode 100644 UnitsNet/UnitDefinitions/MolarEnergy.json diff --git a/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs b/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs new file mode 100644 index 0000000000..67e6093b79 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MolarEnergyTests.cs @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// +// 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 MolarEnergyTests : MolarEnergyTestsBase + { + protected override double JoulesPerMoleInOneJoulePerMole => 1e0; + protected override double KilojoulesPerMoleInOneJoulePerMole => 1e-3; + protected override double MegajoulesPerMoleInOneJoulePerMole => 1e-6; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs new file mode 100644 index 0000000000..9e2040f1ef --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/MolarEnergyTestsBase.g.cs @@ -0,0 +1,191 @@ +//------------------------------------------------------------------------------ +// +// 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 MolarEnergy. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class MolarEnergyTestsBase + { + protected abstract double JoulesPerMoleInOneJoulePerMole { get; } + protected abstract double KilojoulesPerMoleInOneJoulePerMole { get; } + protected abstract double MegajoulesPerMoleInOneJoulePerMole { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double JoulesPerMoleTolerance { get { return 1e-5; } } + protected virtual double KilojoulesPerMoleTolerance { get { return 1e-5; } } + protected virtual double MegajoulesPerMoleTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void JoulePerMoleToMolarEnergyUnits() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + AssertEx.EqualTolerance(JoulesPerMoleInOneJoulePerMole, joulepermole.JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(KilojoulesPerMoleInOneJoulePerMole, joulepermole.KilojoulesPerMole, KilojoulesPerMoleTolerance); + AssertEx.EqualTolerance(MegajoulesPerMoleInOneJoulePerMole, joulepermole.MegajoulesPerMole, MegajoulesPerMoleTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, MolarEnergy.From(1, MolarEnergyUnit.JoulePerMole).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(1, MolarEnergy.From(1, MolarEnergyUnit.KilojoulePerMole).KilojoulesPerMole, KilojoulesPerMoleTolerance); + AssertEx.EqualTolerance(1, MolarEnergy.From(1, MolarEnergyUnit.MegajoulePerMole).MegajoulesPerMole, MegajoulesPerMoleTolerance); + } + + [Fact] + public void As() + { + var joulepermole = MolarEnergy.FromJoulesPerMole(1); + AssertEx.EqualTolerance(JoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.JoulePerMole), JoulesPerMoleTolerance); + AssertEx.EqualTolerance(KilojoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.KilojoulePerMole), KilojoulesPerMoleTolerance); + AssertEx.EqualTolerance(MegajoulesPerMoleInOneJoulePerMole, joulepermole.As(MolarEnergyUnit.MegajoulePerMole), MegajoulesPerMoleTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + AssertEx.EqualTolerance(1, MolarEnergy.FromJoulesPerMole(joulepermole.JoulesPerMole).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(1, MolarEnergy.FromKilojoulesPerMole(joulepermole.KilojoulesPerMole).JoulesPerMole, KilojoulesPerMoleTolerance); + AssertEx.EqualTolerance(1, MolarEnergy.FromMegajoulesPerMole(joulepermole.MegajoulesPerMole).JoulesPerMole, MegajoulesPerMoleTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + MolarEnergy v = MolarEnergy.FromJoulesPerMole(1); + AssertEx.EqualTolerance(-1, -v.JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(2, (MolarEnergy.FromJoulesPerMole(3)-v).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(2, (v + v).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(10, (v*10).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(10, (10*v).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(2, (MolarEnergy.FromJoulesPerMole(10)/5).JoulesPerMole, JoulesPerMoleTolerance); + AssertEx.EqualTolerance(2, MolarEnergy.FromJoulesPerMole(10)/MolarEnergy.FromJoulesPerMole(5), JoulesPerMoleTolerance); + } + + [Fact] + public void ComparisonOperators() + { + MolarEnergy oneJoulePerMole = MolarEnergy.FromJoulesPerMole(1); + MolarEnergy twoJoulesPerMole = MolarEnergy.FromJoulesPerMole(2); + + Assert.True(oneJoulePerMole < twoJoulesPerMole); + Assert.True(oneJoulePerMole <= twoJoulesPerMole); + Assert.True(twoJoulesPerMole > oneJoulePerMole); + Assert.True(twoJoulesPerMole >= oneJoulePerMole); + + Assert.False(oneJoulePerMole > twoJoulesPerMole); + Assert.False(oneJoulePerMole >= twoJoulesPerMole); + Assert.False(twoJoulesPerMole < oneJoulePerMole); + Assert.False(twoJoulesPerMole <= oneJoulePerMole); + } + + [Fact] + public void CompareToIsImplemented() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + Assert.Equal(0, joulepermole.CompareTo(joulepermole)); + Assert.True(joulepermole.CompareTo(MolarEnergy.Zero) > 0); + Assert.True(MolarEnergy.Zero.CompareTo(joulepermole) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + Assert.Throws(() => joulepermole.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + Assert.Throws(() => joulepermole.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + MolarEnergy a = MolarEnergy.FromJoulesPerMole(1); + MolarEnergy b = MolarEnergy.FromJoulesPerMole(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() + { + MolarEnergy v = MolarEnergy.FromJoulesPerMole(1); + Assert.True(v.Equals(MolarEnergy.FromJoulesPerMole(1))); + Assert.False(v.Equals(MolarEnergy.Zero)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + Assert.False(joulepermole.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + MolarEnergy joulepermole = MolarEnergy.FromJoulesPerMole(1); + Assert.False(joulepermole.Equals(null)); + } + } +} diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarEnergyExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarEnergyExtensions.g.cs new file mode 100644 index 0000000000..163264f384 --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMolarEnergyExtensions.g.cs @@ -0,0 +1,151 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToMolarEnergy +{ + public static class NumberToMolarEnergyExtensions + { + #region JoulePerMole + + /// + public static MolarEnergy JoulesPerMole(this int value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy? JoulesPerMole(this int? value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy JoulesPerMole(this long value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy? JoulesPerMole(this long? value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy JoulesPerMole(this double value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy? JoulesPerMole(this double? value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy JoulesPerMole(this float value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy? JoulesPerMole(this float? value) => MolarEnergy.FromJoulesPerMole(value); + + /// + public static MolarEnergy JoulesPerMole(this decimal value) => MolarEnergy.FromJoulesPerMole(Convert.ToDouble(value)); + + /// + public static MolarEnergy? JoulesPerMole(this decimal? value) => MolarEnergy.FromJoulesPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region KilojoulePerMole + + /// + public static MolarEnergy KilojoulesPerMole(this int value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy? KilojoulesPerMole(this int? value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy KilojoulesPerMole(this long value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy? KilojoulesPerMole(this long? value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy KilojoulesPerMole(this double value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy? KilojoulesPerMole(this double? value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy KilojoulesPerMole(this float value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy? KilojoulesPerMole(this float? value) => MolarEnergy.FromKilojoulesPerMole(value); + + /// + public static MolarEnergy KilojoulesPerMole(this decimal value) => MolarEnergy.FromKilojoulesPerMole(Convert.ToDouble(value)); + + /// + public static MolarEnergy? KilojoulesPerMole(this decimal? value) => MolarEnergy.FromKilojoulesPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region MegajoulePerMole + + /// + public static MolarEnergy MegajoulesPerMole(this int value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy? MegajoulesPerMole(this int? value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy MegajoulesPerMole(this long value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy? MegajoulesPerMole(this long? value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy MegajoulesPerMole(this double value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy? MegajoulesPerMole(this double? value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy MegajoulesPerMole(this float value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy? MegajoulesPerMole(this float? value) => MolarEnergy.FromMegajoulesPerMole(value); + + /// + public static MolarEnergy MegajoulesPerMole(this decimal value) => MolarEnergy.FromMegajoulesPerMole(Convert.ToDouble(value)); + + /// + public static MolarEnergy? MegajoulesPerMole(this decimal? value) => MolarEnergy.FromMegajoulesPerMole(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs new file mode 100644 index 0000000000..275e9f13c5 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs @@ -0,0 +1,944 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// Molar energy is the amount of energy stored in 1 mole of a 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 MolarEnergy +#else + public partial struct MolarEnergy : IComparable, IComparable +#endif + { + /// + /// Base unit of MolarEnergy. + /// + private readonly double _joulesPerMole; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public MolarEnergy() : this(0) + { + } +#endif + + public MolarEnergy(double joulespermole) + { + _joulesPerMole = Convert.ToDouble(joulespermole); + } + + // 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 + MolarEnergy(long joulespermole) + { + _joulesPerMole = Convert.ToDouble(joulespermole); + } + + // 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 + MolarEnergy(decimal joulespermole) + { + _joulesPerMole = Convert.ToDouble(joulespermole); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.MolarEnergy; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static MolarEnergyUnit BaseUnit + { + get { return MolarEnergyUnit.JoulePerMole; } + } + + /// + /// All units of measurement for the MolarEnergy quantity. + /// + public static MolarEnergyUnit[] Units { get; } = Enum.GetValues(typeof(MolarEnergyUnit)).Cast().ToArray(); + + /// + /// Get MolarEnergy in JoulesPerMole. + /// + public double JoulesPerMole + { + get { return _joulesPerMole; } + } + + /// + /// Get MolarEnergy in KilojoulesPerMole. + /// + public double KilojoulesPerMole + { + get { return (_joulesPerMole) / 1e3d; } + } + + /// + /// Get MolarEnergy in MegajoulesPerMole. + /// + public double MegajoulesPerMole + { + get { return (_joulesPerMole) / 1e6d; } + } + + #endregion + + #region Static + + public static MolarEnergy Zero + { + get { return new MolarEnergy(); } + } + + /// + /// Get MolarEnergy from JoulesPerMole. + /// +#if NETFX_CORE + [Windows.Foundation.Metadata.DefaultOverload] +#endif + public static MolarEnergy FromJoulesPerMole(double joulespermole) + { + return new MolarEnergy(joulespermole); + } + + /// + /// Get MolarEnergy from JoulesPerMole. + /// + public static MolarEnergy FromJoulesPerMole(int joulespermole) + { + return new MolarEnergy(joulespermole); + } + + /// + /// Get MolarEnergy from JoulesPerMole. + /// + public static MolarEnergy FromJoulesPerMole(long joulespermole) + { + return new MolarEnergy(joulespermole); + } + + // Windows Runtime Component does not support decimal type +#if !WINDOWS_UWP + /// + /// Get MolarEnergy from JoulesPerMole of type decimal. + /// + public static MolarEnergy FromJoulesPerMole(decimal joulespermole) + { + return new MolarEnergy(Convert.ToDouble(joulespermole)); + } +#endif + + /// + /// Get MolarEnergy from KilojoulesPerMole. + /// +#if NETFX_CORE + [Windows.Foundation.Metadata.DefaultOverload] +#endif + public static MolarEnergy FromKilojoulesPerMole(double kilojoulespermole) + { + return new MolarEnergy((kilojoulespermole) * 1e3d); + } + + /// + /// Get MolarEnergy from KilojoulesPerMole. + /// + public static MolarEnergy FromKilojoulesPerMole(int kilojoulespermole) + { + return new MolarEnergy((kilojoulespermole) * 1e3d); + } + + /// + /// Get MolarEnergy from KilojoulesPerMole. + /// + public static MolarEnergy FromKilojoulesPerMole(long kilojoulespermole) + { + return new MolarEnergy((kilojoulespermole) * 1e3d); + } + + // Windows Runtime Component does not support decimal type +#if !WINDOWS_UWP + /// + /// Get MolarEnergy from KilojoulesPerMole of type decimal. + /// + public static MolarEnergy FromKilojoulesPerMole(decimal kilojoulespermole) + { + return new MolarEnergy((Convert.ToDouble(kilojoulespermole)) * 1e3d); + } +#endif + + /// + /// Get MolarEnergy from MegajoulesPerMole. + /// +#if NETFX_CORE + [Windows.Foundation.Metadata.DefaultOverload] +#endif + public static MolarEnergy FromMegajoulesPerMole(double megajoulespermole) + { + return new MolarEnergy((megajoulespermole) * 1e6d); + } + + /// + /// Get MolarEnergy from MegajoulesPerMole. + /// + public static MolarEnergy FromMegajoulesPerMole(int megajoulespermole) + { + return new MolarEnergy((megajoulespermole) * 1e6d); + } + + /// + /// Get MolarEnergy from MegajoulesPerMole. + /// + public static MolarEnergy FromMegajoulesPerMole(long megajoulespermole) + { + return new MolarEnergy((megajoulespermole) * 1e6d); + } + + // Windows Runtime Component does not support decimal type +#if !WINDOWS_UWP + /// + /// Get MolarEnergy from MegajoulesPerMole of type decimal. + /// + public static MolarEnergy FromMegajoulesPerMole(decimal megajoulespermole) + { + return new MolarEnergy((Convert.ToDouble(megajoulespermole)) * 1e6d); + } +#endif + + // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + /// + /// Get nullable MolarEnergy from nullable JoulesPerMole. + /// + public static MolarEnergy? FromJoulesPerMole(double? joulespermole) + { + if (joulespermole.HasValue) + { + return FromJoulesPerMole(joulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable JoulesPerMole. + /// + public static MolarEnergy? FromJoulesPerMole(int? joulespermole) + { + if (joulespermole.HasValue) + { + return FromJoulesPerMole(joulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable JoulesPerMole. + /// + public static MolarEnergy? FromJoulesPerMole(long? joulespermole) + { + if (joulespermole.HasValue) + { + return FromJoulesPerMole(joulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from JoulesPerMole of type decimal. + /// + public static MolarEnergy? FromJoulesPerMole(decimal? joulespermole) + { + if (joulespermole.HasValue) + { + return FromJoulesPerMole(joulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable KilojoulesPerMole. + /// + public static MolarEnergy? FromKilojoulesPerMole(double? kilojoulespermole) + { + if (kilojoulespermole.HasValue) + { + return FromKilojoulesPerMole(kilojoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable KilojoulesPerMole. + /// + public static MolarEnergy? FromKilojoulesPerMole(int? kilojoulespermole) + { + if (kilojoulespermole.HasValue) + { + return FromKilojoulesPerMole(kilojoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable KilojoulesPerMole. + /// + public static MolarEnergy? FromKilojoulesPerMole(long? kilojoulespermole) + { + if (kilojoulespermole.HasValue) + { + return FromKilojoulesPerMole(kilojoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from KilojoulesPerMole of type decimal. + /// + public static MolarEnergy? FromKilojoulesPerMole(decimal? kilojoulespermole) + { + if (kilojoulespermole.HasValue) + { + return FromKilojoulesPerMole(kilojoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable MegajoulesPerMole. + /// + public static MolarEnergy? FromMegajoulesPerMole(double? megajoulespermole) + { + if (megajoulespermole.HasValue) + { + return FromMegajoulesPerMole(megajoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable MegajoulesPerMole. + /// + public static MolarEnergy? FromMegajoulesPerMole(int? megajoulespermole) + { + if (megajoulespermole.HasValue) + { + return FromMegajoulesPerMole(megajoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from nullable MegajoulesPerMole. + /// + public static MolarEnergy? FromMegajoulesPerMole(long? megajoulespermole) + { + if (megajoulespermole.HasValue) + { + return FromMegajoulesPerMole(megajoulespermole.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MolarEnergy from MegajoulesPerMole of type decimal. + /// + public static MolarEnergy? FromMegajoulesPerMole(decimal? megajoulespermole) + { + if (megajoulespermole.HasValue) + { + return FromMegajoulesPerMole(megajoulespermole.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MolarEnergy unit value. + public static MolarEnergy From(double val, MolarEnergyUnit fromUnit) + { + switch (fromUnit) + { + case MolarEnergyUnit.JoulePerMole: + return FromJoulesPerMole(val); + case MolarEnergyUnit.KilojoulePerMole: + return FromKilojoulesPerMole(val); + case MolarEnergyUnit.MegajoulePerMole: + return FromMegajoulesPerMole(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. + /// MolarEnergy unit value. + public static MolarEnergy? From(double? value, MolarEnergyUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case MolarEnergyUnit.JoulePerMole: + return FromJoulesPerMole(value.Value); + case MolarEnergyUnit.KilojoulePerMole: + return FromKilojoulesPerMole(value.Value); + case MolarEnergyUnit.MegajoulePerMole: + return FromMegajoulesPerMole(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(MolarEnergyUnit 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(MolarEnergyUnit 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 MolarEnergy operator -(MolarEnergy right) + { + return new MolarEnergy(-right._joulesPerMole); + } + + public static MolarEnergy operator +(MolarEnergy left, MolarEnergy right) + { + return new MolarEnergy(left._joulesPerMole + right._joulesPerMole); + } + + public static MolarEnergy operator -(MolarEnergy left, MolarEnergy right) + { + return new MolarEnergy(left._joulesPerMole - right._joulesPerMole); + } + + public static MolarEnergy operator *(double left, MolarEnergy right) + { + return new MolarEnergy(left*right._joulesPerMole); + } + + public static MolarEnergy operator *(MolarEnergy left, double right) + { + return new MolarEnergy(left._joulesPerMole*(double)right); + } + + public static MolarEnergy operator /(MolarEnergy left, double right) + { + return new MolarEnergy(left._joulesPerMole/(double)right); + } + + public static double operator /(MolarEnergy left, MolarEnergy right) + { + return Convert.ToDouble(left._joulesPerMole/right._joulesPerMole); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is MolarEnergy)) throw new ArgumentException("Expected type MolarEnergy.", "obj"); + return CompareTo((MolarEnergy) 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(MolarEnergy other) + { + return _joulesPerMole.CompareTo(other._joulesPerMole); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(MolarEnergy left, MolarEnergy right) + { + return left._joulesPerMole <= right._joulesPerMole; + } + + public static bool operator >=(MolarEnergy left, MolarEnergy right) + { + return left._joulesPerMole >= right._joulesPerMole; + } + + public static bool operator <(MolarEnergy left, MolarEnergy right) + { + return left._joulesPerMole < right._joulesPerMole; + } + + public static bool operator >(MolarEnergy left, MolarEnergy right) + { + return left._joulesPerMole > right._joulesPerMole; + } + + public static bool operator ==(MolarEnergy left, MolarEnergy right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._joulesPerMole == right._joulesPerMole; + } + + public static bool operator !=(MolarEnergy left, MolarEnergy right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._joulesPerMole != right._joulesPerMole; + } +#endif + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _joulesPerMole.Equals(((MolarEnergy) obj)._joulesPerMole); + } + + public override int GetHashCode() + { + return _joulesPerMole.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(MolarEnergyUnit unit) + { + switch (unit) + { + case MolarEnergyUnit.JoulePerMole: + return JoulesPerMole; + case MolarEnergyUnit.KilojoulePerMole: + return KilojoulesPerMole; + case MolarEnergyUnit.MegajoulePerMole: + return MegajoulesPerMole; + + 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 MolarEnergy 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 MolarEnergy 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); + MolarEnergyUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromJoulesPerMole(x.JoulesPerMole + y.JoulesPerMole)); + } + + /// + /// 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 MolarEnergy 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 MolarEnergy result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(MolarEnergy); + 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 MolarEnergyUnit 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 MolarEnergyUnit 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 MolarEnergyUnit 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 == MolarEnergyUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized MolarEnergyUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is JoulePerMole + /// + public static MolarEnergyUnit ToStringDefaultUnit { get; set; } = MolarEnergyUnit.JoulePerMole; + + /// + /// 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(MolarEnergyUnit 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(MolarEnergyUnit 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(MolarEnergyUnit 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(MolarEnergyUnit 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 MolarEnergy + /// + public static MolarEnergy MaxValue + { + get + { + return new MolarEnergy(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of MolarEnergy + /// + public static MolarEnergy MinValue + { + get + { + return new MolarEnergy(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index abdf0a92d0..e2e0a7502f 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -79,6 +79,7 @@ public enum QuantityType Mass, MassFlow, MassMomentOfInertia, + MolarEnergy, Molarity, MolarMass, Power, diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index fe62242dba..ef682decac 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -1953,6 +1953,25 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "t·mm²"), }), }), + new UnitLocalization(typeof (MolarEnergyUnit), + new[] + { + new CulturesForEnumValue((int) MolarEnergyUnit.JoulePerMole, + new[] + { + new AbbreviationsForCulture("en-US", "J/mol"), + }), + new CulturesForEnumValue((int) MolarEnergyUnit.KilojoulePerMole, + new[] + { + new AbbreviationsForCulture("en-US", "kJ/mol"), + }), + new CulturesForEnumValue((int) MolarEnergyUnit.MegajoulePerMole, + new[] + { + new AbbreviationsForCulture("en-US", "MJ/mol"), + }), + }), new UnitLocalization(typeof (MolarityUnit), new[] { diff --git a/UnitsNet/GeneratedCode/Units/MolarEnergyUnit.g.cs b/UnitsNet/GeneratedCode/Units/MolarEnergyUnit.g.cs new file mode 100644 index 0000000000..4667add916 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/MolarEnergyUnit.g.cs @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// 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 MolarEnergyUnit + { + Undefined = 0, + JoulePerMole, + KilojoulePerMole, + MegajoulePerMole, + } +} diff --git a/UnitsNet/UnitDefinitions/MolarEnergy.json b/UnitsNet/UnitDefinitions/MolarEnergy.json new file mode 100644 index 0000000000..d4fb3a80ee --- /dev/null +++ b/UnitsNet/UnitDefinitions/MolarEnergy.json @@ -0,0 +1,20 @@ +{ + "Name": "MolarEnergy", + "BaseUnit": "JoulePerMole", + "XmlDoc": "Molar energy is the amount of energy stored in 1 mole of a substance.", + "Units": [ + { + "SingularName": "JoulePerMole", + "PluralName": "JoulesPerMole", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "J/mol" ] + } + ] + } + ] +}