From 3f02f6a691e590b34679a75e6f0a053850641177 Mon Sep 17 00:00:00 2001 From: "coding@baxenergy.com" Date: Tue, 16 Jan 2018 18:08:07 +0100 Subject: [PATCH] Added ElectricConductance: Siemens (S) + Prefixes ("Milli", "Micro") --- .../CustomCode/ElectricConductanceTests.cs | 55 ++ .../ElectricConductanceTestsBase.g.cs | 191 +++++ ...NumberToElectricConductanceExtensions.g.cs | 151 ++++ .../Quantities/ElectricConductance.g.cs | 771 ++++++++++++++++++ UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitSystem.Default.g.cs | 19 + .../Units/ElectricConductanceUnit.g.cs | 49 ++ .../UnitDefinitions/ElectricConductance.json | 21 + 8 files changed, 1258 insertions(+) create mode 100644 UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductanceExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs create mode 100644 UnitsNet/UnitDefinitions/ElectricConductance.json diff --git a/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs new file mode 100644 index 0000000000..fff9973c26 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// 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) 2013 Andreas Gullberg Larsen (andreas.larsen84@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 ElectricConductanceTests : ElectricConductanceTestsBase + { + protected override double SiemensInOneSiemens => 1; + + protected override double MillisiemensInOneSiemens => 1E3; + + protected override double MicrosiemensInOneSiemens => 1E6; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.g.cs new file mode 100644 index 0000000000..ebc074643c --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/ElectricConductanceTestsBase.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) 2013 Andreas Gullberg Larsen (andreas.larsen84@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 ElectricConductance. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricConductanceTestsBase + { + protected abstract double MicrosiemensInOneSiemens { get; } + protected abstract double MillisiemensInOneSiemens { get; } + protected abstract double SiemensInOneSiemens { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double MicrosiemensTolerance { get { return 1e-5; } } + protected virtual double MillisiemensTolerance { get { return 1e-5; } } + protected virtual double SiemensTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void SiemensToElectricConductanceUnits() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance); + AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, ElectricConductance.From(1, ElectricConductanceUnit.Microsiemens).Microsiemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.From(1, ElectricConductanceUnit.Millisiemens).Millisiemens, MillisiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.From(1, ElectricConductanceUnit.Siemens).Siemens, SiemensTolerance); + } + + [Fact] + public void As() + { + var siemens = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Microsiemens), MicrosiemensTolerance); + AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Millisiemens), MillisiemensTolerance); + AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Siemens), SiemensTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(1, ElectricConductance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricConductance v = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(-1, -v.Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, (ElectricConductance.FromSiemens(3)-v).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, (v + v).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(10, (v*10).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(10, (10*v).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, (ElectricConductance.FromSiemens(10)/5).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, ElectricConductance.FromSiemens(10)/ElectricConductance.FromSiemens(5), SiemensTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricConductance oneSiemens = ElectricConductance.FromSiemens(1); + ElectricConductance twoSiemens = ElectricConductance.FromSiemens(2); + + Assert.True(oneSiemens < twoSiemens); + Assert.True(oneSiemens <= twoSiemens); + Assert.True(twoSiemens > oneSiemens); + Assert.True(twoSiemens >= oneSiemens); + + Assert.False(oneSiemens > twoSiemens); + Assert.False(oneSiemens >= twoSiemens); + Assert.False(twoSiemens < oneSiemens); + Assert.False(twoSiemens <= oneSiemens); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + Assert.Equal(0, siemens.CompareTo(siemens)); + Assert.True(siemens.CompareTo(ElectricConductance.Zero) > 0); + Assert.True(ElectricConductance.Zero.CompareTo(siemens) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + Assert.Throws(() => siemens.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + Assert.Throws(() => siemens.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + ElectricConductance a = ElectricConductance.FromSiemens(1); + ElectricConductance b = ElectricConductance.FromSiemens(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() + { + ElectricConductance v = ElectricConductance.FromSiemens(1); + Assert.True(v.Equals(ElectricConductance.FromSiemens(1), ElectricConductance.FromSiemens(SiemensTolerance))); + Assert.False(v.Equals(ElectricConductance.Zero, ElectricConductance.FromSiemens(SiemensTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + Assert.False(siemens.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricConductance siemens = ElectricConductance.FromSiemens(1); + Assert.False(siemens.Equals(null)); + } + } +} diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductanceExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductanceExtensions.g.cs new file mode 100644 index 0000000000..a2526e64da --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductanceExtensions.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) 2013 Andreas Gullberg Larsen (andreas.larsen84@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.NumberToElectricConductance +{ + public static class NumberToElectricConductanceExtensions + { + #region Microsiemens + + /// + public static ElectricConductance Microsiemens(this int value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance? Microsiemens(this int? value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance Microsiemens(this long value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance? Microsiemens(this long? value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance Microsiemens(this double value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance? Microsiemens(this double? value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance Microsiemens(this float value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance? Microsiemens(this float? value) => ElectricConductance.FromMicrosiemens(value); + + /// + public static ElectricConductance Microsiemens(this decimal value) => ElectricConductance.FromMicrosiemens(Convert.ToDouble(value)); + + /// + public static ElectricConductance? Microsiemens(this decimal? value) => ElectricConductance.FromMicrosiemens(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region Millisiemens + + /// + public static ElectricConductance Millisiemens(this int value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance? Millisiemens(this int? value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance Millisiemens(this long value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance? Millisiemens(this long? value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance Millisiemens(this double value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance? Millisiemens(this double? value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance Millisiemens(this float value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance? Millisiemens(this float? value) => ElectricConductance.FromMillisiemens(value); + + /// + public static ElectricConductance Millisiemens(this decimal value) => ElectricConductance.FromMillisiemens(Convert.ToDouble(value)); + + /// + public static ElectricConductance? Millisiemens(this decimal? value) => ElectricConductance.FromMillisiemens(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region Siemens + + /// + public static ElectricConductance Siemens(this int value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance? Siemens(this int? value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance Siemens(this long value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance? Siemens(this long? value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance Siemens(this double value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance? Siemens(this double? value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance Siemens(this float value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance? Siemens(this float? value) => ElectricConductance.FromSiemens(value); + + /// + public static ElectricConductance Siemens(this decimal value) => ElectricConductance.FromSiemens(Convert.ToDouble(value)); + + /// + public static ElectricConductance? Siemens(this decimal? value) => ElectricConductance.FromSiemens(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs new file mode 100644 index 0000000000..8dd70e0693 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -0,0 +1,771 @@ +//------------------------------------------------------------------------------ +// +// 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) 2013 Andreas Gullberg Larsen (andreas.larsen84@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 +{ + /// + /// The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor. + /// + // 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 ElectricConductance +#else + public partial struct ElectricConductance : IComparable, IComparable +#endif + { + /// + /// Base unit of ElectricConductance. + /// + private readonly double _siemens; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public ElectricConductance() : this(0) + { + } +#endif + + public ElectricConductance(double siemens) + { + _siemens = Convert.ToDouble(siemens); + } + + // 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 + ElectricConductance(long siemens) + { + _siemens = Convert.ToDouble(siemens); + } + + // 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 + ElectricConductance(decimal siemens) + { + _siemens = Convert.ToDouble(siemens); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.ElectricConductance; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static ElectricConductanceUnit BaseUnit + { + get { return ElectricConductanceUnit.Siemens; } + } + + /// + /// All units of measurement for the ElectricConductance quantity. + /// + public static ElectricConductanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricConductanceUnit)).Cast().ToArray(); + + /// + /// Get ElectricConductance in Microsiemens. + /// + public double Microsiemens + { + get { return (_siemens) / 1e-6d; } + } + + /// + /// Get ElectricConductance in Millisiemens. + /// + public double Millisiemens + { + get { return (_siemens) / 1e-3d; } + } + + /// + /// Get ElectricConductance in Siemens. + /// + public double Siemens + { + get { return _siemens; } + } + + #endregion + + #region Static + + public static ElectricConductance Zero + { + get { return new ElectricConductance(); } + } + + /// + /// Get ElectricConductance from Microsiemens. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricConductance FromMicrosiemens(double microsiemens) + { + double value = (double) microsiemens; + return new ElectricConductance((value) * 1e-6d); + } +#else + public static ElectricConductance FromMicrosiemens(QuantityValue microsiemens) + { + double value = (double) microsiemens; + return new ElectricConductance(((value) * 1e-6d)); + } +#endif + + /// + /// Get ElectricConductance from Millisiemens. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricConductance FromMillisiemens(double millisiemens) + { + double value = (double) millisiemens; + return new ElectricConductance((value) * 1e-3d); + } +#else + public static ElectricConductance FromMillisiemens(QuantityValue millisiemens) + { + double value = (double) millisiemens; + return new ElectricConductance(((value) * 1e-3d)); + } +#endif + + /// + /// Get ElectricConductance from Siemens. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricConductance FromSiemens(double siemens) + { + double value = (double) siemens; + return new ElectricConductance(value); + } +#else + public static ElectricConductance FromSiemens(QuantityValue siemens) + { + double value = (double) siemens; + return new ElectricConductance((value)); + } +#endif + + // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + /// + /// Get nullable ElectricConductance from nullable Microsiemens. + /// + public static ElectricConductance? FromMicrosiemens(QuantityValue? microsiemens) + { + if (microsiemens.HasValue) + { + return FromMicrosiemens(microsiemens.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricConductance from nullable Millisiemens. + /// + public static ElectricConductance? FromMillisiemens(QuantityValue? millisiemens) + { + if (millisiemens.HasValue) + { + return FromMillisiemens(millisiemens.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricConductance from nullable Siemens. + /// + public static ElectricConductance? FromSiemens(QuantityValue? siemens) + { + if (siemens.HasValue) + { + return FromSiemens(siemens.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricConductance unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricConductance From(double value, ElectricConductanceUnit fromUnit) +#else + public static ElectricConductance From(QuantityValue value, ElectricConductanceUnit fromUnit) +#endif + { + switch (fromUnit) + { + case ElectricConductanceUnit.Microsiemens: + return FromMicrosiemens(value); + case ElectricConductanceUnit.Millisiemens: + return FromMillisiemens(value); + case ElectricConductanceUnit.Siemens: + return FromSiemens(value); + + 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. + /// ElectricConductance unit value. + public static ElectricConductance? From(QuantityValue? value, ElectricConductanceUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricConductanceUnit.Microsiemens: + return FromMicrosiemens(value.Value); + case ElectricConductanceUnit.Millisiemens: + return FromMillisiemens(value.Value); + case ElectricConductanceUnit.Siemens: + return FromSiemens(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(ElectricConductanceUnit 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(ElectricConductanceUnit 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 ElectricConductance operator -(ElectricConductance right) + { + return new ElectricConductance(-right._siemens); + } + + public static ElectricConductance operator +(ElectricConductance left, ElectricConductance right) + { + return new ElectricConductance(left._siemens + right._siemens); + } + + public static ElectricConductance operator -(ElectricConductance left, ElectricConductance right) + { + return new ElectricConductance(left._siemens - right._siemens); + } + + public static ElectricConductance operator *(double left, ElectricConductance right) + { + return new ElectricConductance(left*right._siemens); + } + + public static ElectricConductance operator *(ElectricConductance left, double right) + { + return new ElectricConductance(left._siemens*(double)right); + } + + public static ElectricConductance operator /(ElectricConductance left, double right) + { + return new ElectricConductance(left._siemens/(double)right); + } + + public static double operator /(ElectricConductance left, ElectricConductance right) + { + return Convert.ToDouble(left._siemens/right._siemens); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricConductance)) throw new ArgumentException("Expected type ElectricConductance.", "obj"); + return CompareTo((ElectricConductance) 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(ElectricConductance other) + { + return _siemens.CompareTo(other._siemens); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(ElectricConductance left, ElectricConductance right) + { + return left._siemens <= right._siemens; + } + + public static bool operator >=(ElectricConductance left, ElectricConductance right) + { + return left._siemens >= right._siemens; + } + + public static bool operator <(ElectricConductance left, ElectricConductance right) + { + return left._siemens < right._siemens; + } + + public static bool operator >(ElectricConductance left, ElectricConductance right) + { + return left._siemens > right._siemens; + } + + [Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")] + public static bool operator ==(ElectricConductance left, ElectricConductance right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._siemens == right._siemens; + } + + [Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")] + public static bool operator !=(ElectricConductance left, ElectricConductance right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._siemens != right._siemens; + } +#endif + + [Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")] + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _siemens.Equals(((ElectricConductance) obj)._siemens); + } + + /// + /// Compare equality to another ElectricConductance by specifying a max allowed difference. + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// Other quantity to compare to. + /// Max error allowed. + /// True if the difference between the two values is not greater than the specified max. + public bool Equals(ElectricConductance other, ElectricConductance maxError) + { + return Math.Abs(_siemens - other._siemens) <= maxError._siemens; + } + + public override int GetHashCode() + { + return _siemens.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(ElectricConductanceUnit unit) + { + switch (unit) + { + case ElectricConductanceUnit.Microsiemens: + return Microsiemens; + case ElectricConductanceUnit.Millisiemens: + return Millisiemens; + case ElectricConductanceUnit.Siemens: + return Siemens; + + 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 ElectricConductance 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 ElectricConductance 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); + ElectricConductanceUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromSiemens(x.Siemens + y.Siemens)); + } + + /// + /// 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 ElectricConductance 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 ElectricConductance result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(ElectricConductance); + 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 ElectricConductanceUnit 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 ElectricConductanceUnit 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 ElectricConductanceUnit 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 == ElectricConductanceUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricConductanceUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is Siemens + /// + public static ElectricConductanceUnit ToStringDefaultUnit { get; set; } = ElectricConductanceUnit.Siemens; + + /// + /// 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(ElectricConductanceUnit 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(ElectricConductanceUnit 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(ElectricConductanceUnit 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(ElectricConductanceUnit 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 ElectricConductance + /// + public static ElectricConductance MaxValue + { + get + { + return new ElectricConductance(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of ElectricConductance + /// + public static ElectricConductance MinValue + { + get + { + return new ElectricConductance(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 06688fd25d..b48a22fcdf 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -61,6 +61,7 @@ public enum QuantityType Duration, DynamicViscosity, ElectricAdmittance, + ElectricConductance, ElectricCurrent, ElectricPotential, ElectricPotentialAc, diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 1a0537c3df..408e7c7232 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -732,6 +732,25 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "S"), }), }), + new UnitLocalization(typeof (ElectricConductanceUnit), + new[] + { + new CulturesForEnumValue((int) ElectricConductanceUnit.Microsiemens, + new[] + { + new AbbreviationsForCulture("en-US", "µS"), + }), + new CulturesForEnumValue((int) ElectricConductanceUnit.Millisiemens, + new[] + { + new AbbreviationsForCulture("en-US", "mS"), + }), + new CulturesForEnumValue((int) ElectricConductanceUnit.Siemens, + new[] + { + new AbbreviationsForCulture("en-US", "S"), + }), + }), new UnitLocalization(typeof (ElectricCurrentUnit), new[] { diff --git a/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs new file mode 100644 index 0000000000..6fff2f36da --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.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) 2013 Andreas Gullberg Larsen (andreas.larsen84@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 ElectricConductanceUnit + { + Undefined = 0, + Microsiemens, + Millisiemens, + Siemens, + } +} diff --git a/UnitsNet/UnitDefinitions/ElectricConductance.json b/UnitsNet/UnitDefinitions/ElectricConductance.json new file mode 100644 index 0000000000..4cb701e270 --- /dev/null +++ b/UnitsNet/UnitDefinitions/ElectricConductance.json @@ -0,0 +1,21 @@ +{ + "Name": "ElectricConductance", + "BaseUnit": "Siemens", + "XmlDoc": "The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance", + "Units": [ + { + "SingularName": "Siemens", + "PluralName": "Siemens", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Milli", "Micro" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "S" ] + } + ] + } + ] +} \ No newline at end of file