From 1be7093210306f006b6545fa04a561332b9e051e Mon Sep 17 00:00:00 2001 From: "coding@baxenergy.com" Date: Thu, 11 Jan 2018 11:38:42 +0100 Subject: [PATCH] Added the following physical quantities: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ElectricConductivity - SiemensPerMeter (S/m) ElectricCurrentDensity - AmperePerMeterSecondSquared (A/m²) ElectricCurrentGradient - AmperePerSecond (A/s) ElectricField - VoltPerMeter (V/m) ElectricInductance - Henry (H) --- .../CustomCode/ElectricConductivityTests.cs | 51 ++ .../CustomCode/ElectricCurrentDensityTests.cs | 51 ++ .../ElectricCurrentGradientTests.cs | 51 ++ .../CustomCode/ElectricFieldTests.cs | 51 ++ .../CustomCode/ElectricInductanceTests.cs | 51 ++ .../ElectricConductivityTestsBase.g.cs | 179 +++++ .../ElectricCurrentDensityTestsBase.g.cs | 179 +++++ .../ElectricCurrentGradientTestsBase.g.cs | 179 +++++ .../GeneratedCode/ElectricFieldTestsBase.g.cs | 179 +++++ .../ElectricInductanceTestsBase.g.cs | 179 +++++ ...umberToElectricConductivityExtensions.g.cs | 83 +++ ...berToElectricCurrentDensityExtensions.g.cs | 83 +++ ...erToElectricCurrentGradientExtensions.g.cs | 83 +++ .../NumberToElectricFieldExtensions.g.cs | 83 +++ .../NumberToElectricInductanceExtensions.g.cs | 83 +++ .../Quantities/ElectricConductivity.g.cs | 677 ++++++++++++++++++ .../Quantities/ElectricCurrentDensity.g.cs | 677 ++++++++++++++++++ .../Quantities/ElectricCurrentGradient.g.cs | 677 ++++++++++++++++++ .../Quantities/ElectricField.g.cs | 677 ++++++++++++++++++ .../Quantities/ElectricInductance.g.cs | 677 ++++++++++++++++++ UnitsNet/GeneratedCode/QuantityType.g.cs | 5 + .../GeneratedCode/UnitSystem.Default.g.cs | 45 ++ .../Units/ElectricConductivityUnit.g.cs | 47 ++ .../Units/ElectricCurrentDensityUnit.g.cs | 47 ++ .../Units/ElectricCurrentGradientUnit.g.cs | 47 ++ .../Units/ElectricFieldUnit.g.cs | 47 ++ .../Units/ElectricInductanceUnit.g.cs | 47 ++ .../UnitDefinitions/ElectricConductivity.json | 20 + .../ElectricCurrentDensity.json | 20 + .../ElectricCurrentGradient.json | 19 + UnitsNet/UnitDefinitions/ElectricField.json | 20 + .../UnitDefinitions/ElectricInductance.json | 20 + 32 files changed, 5334 insertions(+) create mode 100644 UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs create mode 100644 UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs create mode 100644 UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs create mode 100644 UnitsNet.Tests/CustomCode/ElectricFieldTests.cs create mode 100644 UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs create mode 100644 UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs create mode 100644 UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs create mode 100644 UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs create mode 100644 UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductivityExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentDensityExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentGradientExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricFieldExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricInductanceExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricConductivityUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricCurrentDensityUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricCurrentGradientUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricFieldUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/ElectricInductanceUnit.g.cs create mode 100644 UnitsNet/UnitDefinitions/ElectricConductivity.json create mode 100644 UnitsNet/UnitDefinitions/ElectricCurrentDensity.json create mode 100644 UnitsNet/UnitDefinitions/ElectricCurrentGradient.json create mode 100644 UnitsNet/UnitDefinitions/ElectricField.json create mode 100644 UnitsNet/UnitDefinitions/ElectricInductance.json diff --git a/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs b/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs new file mode 100644 index 0000000000..f2d36afba1 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricConductivityTests.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricConductivityTests : ElectricConductivityTestsBase + { + protected override double SiemensPerMeterInOneSiemensPerMeter => 1; + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs b/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs new file mode 100644 index 0000000000..afcfcc9e39 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricCurrentDensityTests.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCurrentDensityTests : ElectricCurrentDensityTestsBase + { + protected override double AmperesPerMeterSecondSquaredInOneAmperePerMeterSecondSquared => 1; + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs b/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs new file mode 100644 index 0000000000..a0a02b4612 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCurrentGradientTests : ElectricCurrentGradientTestsBase + { + protected override double AmperesPerSecondInOneAmperePerSecond => 1; + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs b/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs new file mode 100644 index 0000000000..644911e6db --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricFieldTests.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricFieldTests : ElectricFieldTestsBase + { + protected override double VoltsPerMeterInOneVoltPerMeter => 1; + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs new file mode 100644 index 0000000000..00fd2aad6d --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricInductanceTests.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricInductanceTests : ElectricInductanceTestsBase + { + protected override double HenriesInOneHenry => 1; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs new file mode 100644 index 0000000000..c39cb029dd --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/ElectricConductivityTestsBase.g.cs @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricConductivity. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricConductivityTestsBase + { + protected abstract double SiemensPerMeterInOneSiemensPerMeter { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double SiemensPerMeterTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void SiemensPerMeterToElectricConductivityUnits() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + AssertEx.EqualTolerance(SiemensPerMeterInOneSiemensPerMeter, siemenspermeter.SiemensPerMeter, SiemensPerMeterTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, ElectricConductivity.From(1, ElectricConductivityUnit.SiemensPerMeter).SiemensPerMeter, SiemensPerMeterTolerance); + } + + [Fact] + public void As() + { + var siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + AssertEx.EqualTolerance(SiemensPerMeterInOneSiemensPerMeter, siemenspermeter.As(ElectricConductivityUnit.SiemensPerMeter), SiemensPerMeterTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + AssertEx.EqualTolerance(1, ElectricConductivity.FromSiemensPerMeter(siemenspermeter.SiemensPerMeter).SiemensPerMeter, SiemensPerMeterTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricConductivity v = ElectricConductivity.FromSiemensPerMeter(1); + AssertEx.EqualTolerance(-1, -v.SiemensPerMeter, SiemensPerMeterTolerance); + AssertEx.EqualTolerance(2, (ElectricConductivity.FromSiemensPerMeter(3)-v).SiemensPerMeter, SiemensPerMeterTolerance); + AssertEx.EqualTolerance(2, (v + v).SiemensPerMeter, SiemensPerMeterTolerance); + AssertEx.EqualTolerance(10, (v*10).SiemensPerMeter, SiemensPerMeterTolerance); + AssertEx.EqualTolerance(10, (10*v).SiemensPerMeter, SiemensPerMeterTolerance); + AssertEx.EqualTolerance(2, (ElectricConductivity.FromSiemensPerMeter(10)/5).SiemensPerMeter, SiemensPerMeterTolerance); + AssertEx.EqualTolerance(2, ElectricConductivity.FromSiemensPerMeter(10)/ElectricConductivity.FromSiemensPerMeter(5), SiemensPerMeterTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricConductivity oneSiemensPerMeter = ElectricConductivity.FromSiemensPerMeter(1); + ElectricConductivity twoSiemensPerMeter = ElectricConductivity.FromSiemensPerMeter(2); + + Assert.True(oneSiemensPerMeter < twoSiemensPerMeter); + Assert.True(oneSiemensPerMeter <= twoSiemensPerMeter); + Assert.True(twoSiemensPerMeter > oneSiemensPerMeter); + Assert.True(twoSiemensPerMeter >= oneSiemensPerMeter); + + Assert.False(oneSiemensPerMeter > twoSiemensPerMeter); + Assert.False(oneSiemensPerMeter >= twoSiemensPerMeter); + Assert.False(twoSiemensPerMeter < oneSiemensPerMeter); + Assert.False(twoSiemensPerMeter <= oneSiemensPerMeter); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + Assert.Equal(0, siemenspermeter.CompareTo(siemenspermeter)); + Assert.True(siemenspermeter.CompareTo(ElectricConductivity.Zero) > 0); + Assert.True(ElectricConductivity.Zero.CompareTo(siemenspermeter) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + Assert.Throws(() => siemenspermeter.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + Assert.Throws(() => siemenspermeter.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + ElectricConductivity a = ElectricConductivity.FromSiemensPerMeter(1); + ElectricConductivity b = ElectricConductivity.FromSiemensPerMeter(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() + { + ElectricConductivity v = ElectricConductivity.FromSiemensPerMeter(1); + Assert.True(v.Equals(ElectricConductivity.FromSiemensPerMeter(1), ElectricConductivity.FromSiemensPerMeter(SiemensPerMeterTolerance))); + Assert.False(v.Equals(ElectricConductivity.Zero, ElectricConductivity.FromSiemensPerMeter(SiemensPerMeterTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + Assert.False(siemenspermeter.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricConductivity siemenspermeter = ElectricConductivity.FromSiemensPerMeter(1); + Assert.False(siemenspermeter.Equals(null)); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs new file mode 100644 index 0000000000..8c170a5ccf --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/ElectricCurrentDensityTestsBase.g.cs @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCurrentDensity. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricCurrentDensityTestsBase + { + protected abstract double AmperesPerMeterSecondSquaredInOneAmperePerMeterSecondSquared { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double AmperesPerMeterSecondSquaredTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void AmperePerMeterSecondSquaredToElectricCurrentDensityUnits() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + AssertEx.EqualTolerance(AmperesPerMeterSecondSquaredInOneAmperePerMeterSecondSquared, amperepermetersecondsquared.AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, ElectricCurrentDensity.From(1, ElectricCurrentDensityUnit.AmperePerMeterSecondSquared).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + } + + [Fact] + public void As() + { + var amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + AssertEx.EqualTolerance(AmperesPerMeterSecondSquaredInOneAmperePerMeterSecondSquared, amperepermetersecondsquared.As(ElectricCurrentDensityUnit.AmperePerMeterSecondSquared), AmperesPerMeterSecondSquaredTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + AssertEx.EqualTolerance(1, ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(amperepermetersecondsquared.AmperesPerMeterSecondSquared).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricCurrentDensity v = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + AssertEx.EqualTolerance(-1, -v.AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + AssertEx.EqualTolerance(2, (ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(3)-v).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + AssertEx.EqualTolerance(2, (v + v).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + AssertEx.EqualTolerance(10, (v*10).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + AssertEx.EqualTolerance(10, (10*v).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + AssertEx.EqualTolerance(2, (ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(10)/5).AmperesPerMeterSecondSquared, AmperesPerMeterSecondSquaredTolerance); + AssertEx.EqualTolerance(2, ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(10)/ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(5), AmperesPerMeterSecondSquaredTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricCurrentDensity oneAmperePerMeterSecondSquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + ElectricCurrentDensity twoAmperesPerMeterSecondSquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(2); + + Assert.True(oneAmperePerMeterSecondSquared < twoAmperesPerMeterSecondSquared); + Assert.True(oneAmperePerMeterSecondSquared <= twoAmperesPerMeterSecondSquared); + Assert.True(twoAmperesPerMeterSecondSquared > oneAmperePerMeterSecondSquared); + Assert.True(twoAmperesPerMeterSecondSquared >= oneAmperePerMeterSecondSquared); + + Assert.False(oneAmperePerMeterSecondSquared > twoAmperesPerMeterSecondSquared); + Assert.False(oneAmperePerMeterSecondSquared >= twoAmperesPerMeterSecondSquared); + Assert.False(twoAmperesPerMeterSecondSquared < oneAmperePerMeterSecondSquared); + Assert.False(twoAmperesPerMeterSecondSquared <= oneAmperePerMeterSecondSquared); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + Assert.Equal(0, amperepermetersecondsquared.CompareTo(amperepermetersecondsquared)); + Assert.True(amperepermetersecondsquared.CompareTo(ElectricCurrentDensity.Zero) > 0); + Assert.True(ElectricCurrentDensity.Zero.CompareTo(amperepermetersecondsquared) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + Assert.Throws(() => amperepermetersecondsquared.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + Assert.Throws(() => amperepermetersecondsquared.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + ElectricCurrentDensity a = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + ElectricCurrentDensity b = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(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() + { + ElectricCurrentDensity v = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + Assert.True(v.Equals(ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1), ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(AmperesPerMeterSecondSquaredTolerance))); + Assert.False(v.Equals(ElectricCurrentDensity.Zero, ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(AmperesPerMeterSecondSquaredTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + Assert.False(amperepermetersecondsquared.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricCurrentDensity amperepermetersecondsquared = ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(1); + Assert.False(amperepermetersecondsquared.Equals(null)); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs new file mode 100644 index 0000000000..3cc9c75728 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/ElectricCurrentGradientTestsBase.g.cs @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCurrentGradient. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricCurrentGradientTestsBase + { + protected abstract double AmperesPerSecondInOneAmperePerSecond { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double AmperesPerSecondTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void AmperePerSecondToElectricCurrentGradientUnits() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.AmperesPerSecond, AmperesPerSecondTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, ElectricCurrentGradient.From(1, ElectricCurrentGradientUnit.AmperePerSecond).AmperesPerSecond, AmperesPerSecondTolerance); + } + + [Fact] + public void As() + { + var amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + AssertEx.EqualTolerance(AmperesPerSecondInOneAmperePerSecond, amperepersecond.As(ElectricCurrentGradientUnit.AmperePerSecond), AmperesPerSecondTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + AssertEx.EqualTolerance(1, ElectricCurrentGradient.FromAmperesPerSecond(amperepersecond.AmperesPerSecond).AmperesPerSecond, AmperesPerSecondTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricCurrentGradient v = ElectricCurrentGradient.FromAmperesPerSecond(1); + AssertEx.EqualTolerance(-1, -v.AmperesPerSecond, AmperesPerSecondTolerance); + AssertEx.EqualTolerance(2, (ElectricCurrentGradient.FromAmperesPerSecond(3)-v).AmperesPerSecond, AmperesPerSecondTolerance); + AssertEx.EqualTolerance(2, (v + v).AmperesPerSecond, AmperesPerSecondTolerance); + AssertEx.EqualTolerance(10, (v*10).AmperesPerSecond, AmperesPerSecondTolerance); + AssertEx.EqualTolerance(10, (10*v).AmperesPerSecond, AmperesPerSecondTolerance); + AssertEx.EqualTolerance(2, (ElectricCurrentGradient.FromAmperesPerSecond(10)/5).AmperesPerSecond, AmperesPerSecondTolerance); + AssertEx.EqualTolerance(2, ElectricCurrentGradient.FromAmperesPerSecond(10)/ElectricCurrentGradient.FromAmperesPerSecond(5), AmperesPerSecondTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricCurrentGradient oneAmperePerSecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + ElectricCurrentGradient twoAmperesPerSecond = ElectricCurrentGradient.FromAmperesPerSecond(2); + + Assert.True(oneAmperePerSecond < twoAmperesPerSecond); + Assert.True(oneAmperePerSecond <= twoAmperesPerSecond); + Assert.True(twoAmperesPerSecond > oneAmperePerSecond); + Assert.True(twoAmperesPerSecond >= oneAmperePerSecond); + + Assert.False(oneAmperePerSecond > twoAmperesPerSecond); + Assert.False(oneAmperePerSecond >= twoAmperesPerSecond); + Assert.False(twoAmperesPerSecond < oneAmperePerSecond); + Assert.False(twoAmperesPerSecond <= oneAmperePerSecond); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + Assert.Equal(0, amperepersecond.CompareTo(amperepersecond)); + Assert.True(amperepersecond.CompareTo(ElectricCurrentGradient.Zero) > 0); + Assert.True(ElectricCurrentGradient.Zero.CompareTo(amperepersecond) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + Assert.Throws(() => amperepersecond.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + Assert.Throws(() => amperepersecond.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + ElectricCurrentGradient a = ElectricCurrentGradient.FromAmperesPerSecond(1); + ElectricCurrentGradient b = ElectricCurrentGradient.FromAmperesPerSecond(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() + { + ElectricCurrentGradient v = ElectricCurrentGradient.FromAmperesPerSecond(1); + Assert.True(v.Equals(ElectricCurrentGradient.FromAmperesPerSecond(1), ElectricCurrentGradient.FromAmperesPerSecond(AmperesPerSecondTolerance))); + Assert.False(v.Equals(ElectricCurrentGradient.Zero, ElectricCurrentGradient.FromAmperesPerSecond(AmperesPerSecondTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + Assert.False(amperepersecond.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricCurrentGradient amperepersecond = ElectricCurrentGradient.FromAmperesPerSecond(1); + Assert.False(amperepersecond.Equals(null)); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs new file mode 100644 index 0000000000..e8a74655a4 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/ElectricFieldTestsBase.g.cs @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricField. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricFieldTestsBase + { + protected abstract double VoltsPerMeterInOneVoltPerMeter { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double VoltsPerMeterTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void VoltPerMeterToElectricFieldUnits() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + AssertEx.EqualTolerance(VoltsPerMeterInOneVoltPerMeter, voltpermeter.VoltsPerMeter, VoltsPerMeterTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, ElectricField.From(1, ElectricFieldUnit.VoltPerMeter).VoltsPerMeter, VoltsPerMeterTolerance); + } + + [Fact] + public void As() + { + var voltpermeter = ElectricField.FromVoltsPerMeter(1); + AssertEx.EqualTolerance(VoltsPerMeterInOneVoltPerMeter, voltpermeter.As(ElectricFieldUnit.VoltPerMeter), VoltsPerMeterTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + AssertEx.EqualTolerance(1, ElectricField.FromVoltsPerMeter(voltpermeter.VoltsPerMeter).VoltsPerMeter, VoltsPerMeterTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricField v = ElectricField.FromVoltsPerMeter(1); + AssertEx.EqualTolerance(-1, -v.VoltsPerMeter, VoltsPerMeterTolerance); + AssertEx.EqualTolerance(2, (ElectricField.FromVoltsPerMeter(3)-v).VoltsPerMeter, VoltsPerMeterTolerance); + AssertEx.EqualTolerance(2, (v + v).VoltsPerMeter, VoltsPerMeterTolerance); + AssertEx.EqualTolerance(10, (v*10).VoltsPerMeter, VoltsPerMeterTolerance); + AssertEx.EqualTolerance(10, (10*v).VoltsPerMeter, VoltsPerMeterTolerance); + AssertEx.EqualTolerance(2, (ElectricField.FromVoltsPerMeter(10)/5).VoltsPerMeter, VoltsPerMeterTolerance); + AssertEx.EqualTolerance(2, ElectricField.FromVoltsPerMeter(10)/ElectricField.FromVoltsPerMeter(5), VoltsPerMeterTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricField oneVoltPerMeter = ElectricField.FromVoltsPerMeter(1); + ElectricField twoVoltsPerMeter = ElectricField.FromVoltsPerMeter(2); + + Assert.True(oneVoltPerMeter < twoVoltsPerMeter); + Assert.True(oneVoltPerMeter <= twoVoltsPerMeter); + Assert.True(twoVoltsPerMeter > oneVoltPerMeter); + Assert.True(twoVoltsPerMeter >= oneVoltPerMeter); + + Assert.False(oneVoltPerMeter > twoVoltsPerMeter); + Assert.False(oneVoltPerMeter >= twoVoltsPerMeter); + Assert.False(twoVoltsPerMeter < oneVoltPerMeter); + Assert.False(twoVoltsPerMeter <= oneVoltPerMeter); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + Assert.Equal(0, voltpermeter.CompareTo(voltpermeter)); + Assert.True(voltpermeter.CompareTo(ElectricField.Zero) > 0); + Assert.True(ElectricField.Zero.CompareTo(voltpermeter) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + Assert.Throws(() => voltpermeter.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + Assert.Throws(() => voltpermeter.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + ElectricField a = ElectricField.FromVoltsPerMeter(1); + ElectricField b = ElectricField.FromVoltsPerMeter(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() + { + ElectricField v = ElectricField.FromVoltsPerMeter(1); + Assert.True(v.Equals(ElectricField.FromVoltsPerMeter(1), ElectricField.FromVoltsPerMeter(VoltsPerMeterTolerance))); + Assert.False(v.Equals(ElectricField.Zero, ElectricField.FromVoltsPerMeter(VoltsPerMeterTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + Assert.False(voltpermeter.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricField voltpermeter = ElectricField.FromVoltsPerMeter(1); + Assert.False(voltpermeter.Equals(null)); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs new file mode 100644 index 0000000000..ea43196f33 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/ElectricInductanceTestsBase.g.cs @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricInductance. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricInductanceTestsBase + { + protected abstract double HenriesInOneHenry { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double HenriesTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void HenryToElectricInductanceUnits() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + AssertEx.EqualTolerance(HenriesInOneHenry, henry.Henries, HenriesTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, ElectricInductance.From(1, ElectricInductanceUnit.Henry).Henries, HenriesTolerance); + } + + [Fact] + public void As() + { + var henry = ElectricInductance.FromHenries(1); + AssertEx.EqualTolerance(HenriesInOneHenry, henry.As(ElectricInductanceUnit.Henry), HenriesTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + AssertEx.EqualTolerance(1, ElectricInductance.FromHenries(henry.Henries).Henries, HenriesTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricInductance v = ElectricInductance.FromHenries(1); + AssertEx.EqualTolerance(-1, -v.Henries, HenriesTolerance); + AssertEx.EqualTolerance(2, (ElectricInductance.FromHenries(3)-v).Henries, HenriesTolerance); + AssertEx.EqualTolerance(2, (v + v).Henries, HenriesTolerance); + AssertEx.EqualTolerance(10, (v*10).Henries, HenriesTolerance); + AssertEx.EqualTolerance(10, (10*v).Henries, HenriesTolerance); + AssertEx.EqualTolerance(2, (ElectricInductance.FromHenries(10)/5).Henries, HenriesTolerance); + AssertEx.EqualTolerance(2, ElectricInductance.FromHenries(10)/ElectricInductance.FromHenries(5), HenriesTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricInductance oneHenry = ElectricInductance.FromHenries(1); + ElectricInductance twoHenries = ElectricInductance.FromHenries(2); + + Assert.True(oneHenry < twoHenries); + Assert.True(oneHenry <= twoHenries); + Assert.True(twoHenries > oneHenry); + Assert.True(twoHenries >= oneHenry); + + Assert.False(oneHenry > twoHenries); + Assert.False(oneHenry >= twoHenries); + Assert.False(twoHenries < oneHenry); + Assert.False(twoHenries <= oneHenry); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + Assert.Equal(0, henry.CompareTo(henry)); + Assert.True(henry.CompareTo(ElectricInductance.Zero) > 0); + Assert.True(ElectricInductance.Zero.CompareTo(henry) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + Assert.Throws(() => henry.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + Assert.Throws(() => henry.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + ElectricInductance a = ElectricInductance.FromHenries(1); + ElectricInductance b = ElectricInductance.FromHenries(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() + { + ElectricInductance v = ElectricInductance.FromHenries(1); + Assert.True(v.Equals(ElectricInductance.FromHenries(1), ElectricInductance.FromHenries(HenriesTolerance))); + Assert.False(v.Equals(ElectricInductance.Zero, ElectricInductance.FromHenries(HenriesTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + Assert.False(henry.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricInductance henry = ElectricInductance.FromHenries(1); + Assert.False(henry.Equals(null)); + } + } +} diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductivityExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductivityExtensions.g.cs new file mode 100644 index 0000000000..535f5404df --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricConductivityExtensions.g.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricConductivity +{ + public static class NumberToElectricConductivityExtensions + { + #region SiemensPerMeter + + /// + public static ElectricConductivity SiemensPerMeter(this int value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity? SiemensPerMeter(this int? value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity SiemensPerMeter(this long value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity? SiemensPerMeter(this long? value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity SiemensPerMeter(this double value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity? SiemensPerMeter(this double? value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity SiemensPerMeter(this float value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity? SiemensPerMeter(this float? value) => ElectricConductivity.FromSiemensPerMeter(value); + + /// + public static ElectricConductivity SiemensPerMeter(this decimal value) => ElectricConductivity.FromSiemensPerMeter(Convert.ToDouble(value)); + + /// + public static ElectricConductivity? SiemensPerMeter(this decimal? value) => ElectricConductivity.FromSiemensPerMeter(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentDensityExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentDensityExtensions.g.cs new file mode 100644 index 0000000000..037bb72645 --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentDensityExtensions.g.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricCurrentDensity +{ + public static class NumberToElectricCurrentDensityExtensions + { + #region AmperePerMeterSecondSquared + + /// + public static ElectricCurrentDensity AmperesPerMeterSecondSquared(this int value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity? AmperesPerMeterSecondSquared(this int? value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity AmperesPerMeterSecondSquared(this long value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity? AmperesPerMeterSecondSquared(this long? value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity AmperesPerMeterSecondSquared(this double value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity? AmperesPerMeterSecondSquared(this double? value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity AmperesPerMeterSecondSquared(this float value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity? AmperesPerMeterSecondSquared(this float? value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value); + + /// + public static ElectricCurrentDensity AmperesPerMeterSecondSquared(this decimal value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(Convert.ToDouble(value)); + + /// + public static ElectricCurrentDensity? AmperesPerMeterSecondSquared(this decimal? value) => ElectricCurrentDensity.FromAmperesPerMeterSecondSquared(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentGradientExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentGradientExtensions.g.cs new file mode 100644 index 0000000000..4f30cd8669 --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricCurrentGradientExtensions.g.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricCurrentGradient +{ + public static class NumberToElectricCurrentGradientExtensions + { + #region AmperePerSecond + + /// + public static ElectricCurrentGradient AmperesPerSecond(this int value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient? AmperesPerSecond(this int? value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient AmperesPerSecond(this long value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient? AmperesPerSecond(this long? value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient AmperesPerSecond(this double value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient? AmperesPerSecond(this double? value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient AmperesPerSecond(this float value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient? AmperesPerSecond(this float? value) => ElectricCurrentGradient.FromAmperesPerSecond(value); + + /// + public static ElectricCurrentGradient AmperesPerSecond(this decimal value) => ElectricCurrentGradient.FromAmperesPerSecond(Convert.ToDouble(value)); + + /// + public static ElectricCurrentGradient? AmperesPerSecond(this decimal? value) => ElectricCurrentGradient.FromAmperesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricFieldExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricFieldExtensions.g.cs new file mode 100644 index 0000000000..55443915ca --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricFieldExtensions.g.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricField +{ + public static class NumberToElectricFieldExtensions + { + #region VoltPerMeter + + /// + public static ElectricField VoltsPerMeter(this int value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField? VoltsPerMeter(this int? value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField VoltsPerMeter(this long value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField? VoltsPerMeter(this long? value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField VoltsPerMeter(this double value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField? VoltsPerMeter(this double? value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField VoltsPerMeter(this float value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField? VoltsPerMeter(this float? value) => ElectricField.FromVoltsPerMeter(value); + + /// + public static ElectricField VoltsPerMeter(this decimal value) => ElectricField.FromVoltsPerMeter(Convert.ToDouble(value)); + + /// + public static ElectricField? VoltsPerMeter(this decimal? value) => ElectricField.FromVoltsPerMeter(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricInductanceExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricInductanceExtensions.g.cs new file mode 100644 index 0000000000..a75d6fc112 --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToElectricInductanceExtensions.g.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricInductance +{ + public static class NumberToElectricInductanceExtensions + { + #region Henry + + /// + public static ElectricInductance Henries(this int value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance? Henries(this int? value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance Henries(this long value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance? Henries(this long? value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance Henries(this double value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance? Henries(this double? value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance Henries(this float value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance? Henries(this float? value) => ElectricInductance.FromHenries(value); + + /// + public static ElectricInductance Henries(this decimal value) => ElectricInductance.FromHenries(Convert.ToDouble(value)); + + /// + public static ElectricInductance? Henries(this decimal? value) => ElectricInductance.FromHenries(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs new file mode 100644 index 0000000000..e695c63f35 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs @@ -0,0 +1,677 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// Electrical conductivity or specific conductance is the reciprocal of electrical resistivity, and measures a material's ability to conduct an electric current. + /// + // 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 ElectricConductivity +#else + public partial struct ElectricConductivity : IComparable, IComparable +#endif + { + /// + /// Base unit of ElectricConductivity. + /// + private readonly double _siemensPerMeter; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public ElectricConductivity() : this(0) + { + } +#endif + + public ElectricConductivity(double siemenspermeter) + { + _siemensPerMeter = Convert.ToDouble(siemenspermeter); + } + + // 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 + ElectricConductivity(long siemenspermeter) + { + _siemensPerMeter = Convert.ToDouble(siemenspermeter); + } + + // 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 + ElectricConductivity(decimal siemenspermeter) + { + _siemensPerMeter = Convert.ToDouble(siemenspermeter); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.ElectricConductivity; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static ElectricConductivityUnit BaseUnit + { + get { return ElectricConductivityUnit.SiemensPerMeter; } + } + + /// + /// All units of measurement for the ElectricConductivity quantity. + /// + public static ElectricConductivityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricConductivityUnit)).Cast().ToArray(); + + /// + /// Get ElectricConductivity in SiemensPerMeter. + /// + public double SiemensPerMeter + { + get { return _siemensPerMeter; } + } + + #endregion + + #region Static + + public static ElectricConductivity Zero + { + get { return new ElectricConductivity(); } + } + + /// + /// Get ElectricConductivity from SiemensPerMeter. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricConductivity FromSiemensPerMeter(double siemenspermeter) + { + double value = (double) siemenspermeter; + return new ElectricConductivity(value); + } +#else + public static ElectricConductivity FromSiemensPerMeter(QuantityValue siemenspermeter) + { + double value = (double) siemenspermeter; + return new ElectricConductivity((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 ElectricConductivity from nullable SiemensPerMeter. + /// + public static ElectricConductivity? FromSiemensPerMeter(QuantityValue? siemenspermeter) + { + if (siemenspermeter.HasValue) + { + return FromSiemensPerMeter(siemenspermeter.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricConductivity unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricConductivity From(double value, ElectricConductivityUnit fromUnit) +#else + public static ElectricConductivity From(QuantityValue value, ElectricConductivityUnit fromUnit) +#endif + { + switch (fromUnit) + { + case ElectricConductivityUnit.SiemensPerMeter: + return FromSiemensPerMeter(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. + /// ElectricConductivity unit value. + public static ElectricConductivity? From(QuantityValue? value, ElectricConductivityUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricConductivityUnit.SiemensPerMeter: + return FromSiemensPerMeter(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(ElectricConductivityUnit 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(ElectricConductivityUnit 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 ElectricConductivity operator -(ElectricConductivity right) + { + return new ElectricConductivity(-right._siemensPerMeter); + } + + public static ElectricConductivity operator +(ElectricConductivity left, ElectricConductivity right) + { + return new ElectricConductivity(left._siemensPerMeter + right._siemensPerMeter); + } + + public static ElectricConductivity operator -(ElectricConductivity left, ElectricConductivity right) + { + return new ElectricConductivity(left._siemensPerMeter - right._siemensPerMeter); + } + + public static ElectricConductivity operator *(double left, ElectricConductivity right) + { + return new ElectricConductivity(left*right._siemensPerMeter); + } + + public static ElectricConductivity operator *(ElectricConductivity left, double right) + { + return new ElectricConductivity(left._siemensPerMeter*(double)right); + } + + public static ElectricConductivity operator /(ElectricConductivity left, double right) + { + return new ElectricConductivity(left._siemensPerMeter/(double)right); + } + + public static double operator /(ElectricConductivity left, ElectricConductivity right) + { + return Convert.ToDouble(left._siemensPerMeter/right._siemensPerMeter); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricConductivity)) throw new ArgumentException("Expected type ElectricConductivity.", "obj"); + return CompareTo((ElectricConductivity) 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(ElectricConductivity other) + { + return _siemensPerMeter.CompareTo(other._siemensPerMeter); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(ElectricConductivity left, ElectricConductivity right) + { + return left._siemensPerMeter <= right._siemensPerMeter; + } + + public static bool operator >=(ElectricConductivity left, ElectricConductivity right) + { + return left._siemensPerMeter >= right._siemensPerMeter; + } + + public static bool operator <(ElectricConductivity left, ElectricConductivity right) + { + return left._siemensPerMeter < right._siemensPerMeter; + } + + public static bool operator >(ElectricConductivity left, ElectricConductivity right) + { + return left._siemensPerMeter > right._siemensPerMeter; + } + + [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 ==(ElectricConductivity left, ElectricConductivity right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._siemensPerMeter == right._siemensPerMeter; + } + + [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 !=(ElectricConductivity left, ElectricConductivity right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._siemensPerMeter != right._siemensPerMeter; + } +#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 _siemensPerMeter.Equals(((ElectricConductivity) obj)._siemensPerMeter); + } + + /// + /// Compare equality to another ElectricConductivity 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(ElectricConductivity other, ElectricConductivity maxError) + { + return Math.Abs(_siemensPerMeter - other._siemensPerMeter) <= maxError._siemensPerMeter; + } + + public override int GetHashCode() + { + return _siemensPerMeter.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(ElectricConductivityUnit unit) + { + switch (unit) + { + case ElectricConductivityUnit.SiemensPerMeter: + return SiemensPerMeter; + + 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 ElectricConductivity 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 ElectricConductivity 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); + ElectricConductivityUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromSiemensPerMeter(x.SiemensPerMeter + y.SiemensPerMeter)); + } + + /// + /// 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 ElectricConductivity 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 ElectricConductivity result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(ElectricConductivity); + 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 ElectricConductivityUnit 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 ElectricConductivityUnit 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 ElectricConductivityUnit 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 == ElectricConductivityUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricConductivityUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is SiemensPerMeter + /// + public static ElectricConductivityUnit ToStringDefaultUnit { get; set; } = ElectricConductivityUnit.SiemensPerMeter; + + /// + /// 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(ElectricConductivityUnit 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(ElectricConductivityUnit 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(ElectricConductivityUnit 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(ElectricConductivityUnit 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 ElectricConductivity + /// + public static ElectricConductivity MaxValue + { + get + { + return new ElectricConductivity(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of ElectricConductivity + /// + public static ElectricConductivity MinValue + { + get + { + return new ElectricConductivity(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs new file mode 100644 index 0000000000..0c6f6fb74b --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs @@ -0,0 +1,677 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// In electromagnetism, current density is the electric current per unit area of cross section. + /// + // 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 ElectricCurrentDensity +#else + public partial struct ElectricCurrentDensity : IComparable, IComparable +#endif + { + /// + /// Base unit of ElectricCurrentDensity. + /// + private readonly double _amperesPerMeterSecondSquared; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public ElectricCurrentDensity() : this(0) + { + } +#endif + + public ElectricCurrentDensity(double amperespermetersecondsquared) + { + _amperesPerMeterSecondSquared = Convert.ToDouble(amperespermetersecondsquared); + } + + // 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 + ElectricCurrentDensity(long amperespermetersecondsquared) + { + _amperesPerMeterSecondSquared = Convert.ToDouble(amperespermetersecondsquared); + } + + // 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 + ElectricCurrentDensity(decimal amperespermetersecondsquared) + { + _amperesPerMeterSecondSquared = Convert.ToDouble(amperespermetersecondsquared); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.ElectricCurrentDensity; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static ElectricCurrentDensityUnit BaseUnit + { + get { return ElectricCurrentDensityUnit.AmperePerMeterSecondSquared; } + } + + /// + /// All units of measurement for the ElectricCurrentDensity quantity. + /// + public static ElectricCurrentDensityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentDensityUnit)).Cast().ToArray(); + + /// + /// Get ElectricCurrentDensity in AmperesPerMeterSecondSquared. + /// + public double AmperesPerMeterSecondSquared + { + get { return _amperesPerMeterSecondSquared; } + } + + #endregion + + #region Static + + public static ElectricCurrentDensity Zero + { + get { return new ElectricCurrentDensity(); } + } + + /// + /// Get ElectricCurrentDensity from AmperesPerMeterSecondSquared. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricCurrentDensity FromAmperesPerMeterSecondSquared(double amperespermetersecondsquared) + { + double value = (double) amperespermetersecondsquared; + return new ElectricCurrentDensity(value); + } +#else + public static ElectricCurrentDensity FromAmperesPerMeterSecondSquared(QuantityValue amperespermetersecondsquared) + { + double value = (double) amperespermetersecondsquared; + return new ElectricCurrentDensity((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 ElectricCurrentDensity from nullable AmperesPerMeterSecondSquared. + /// + public static ElectricCurrentDensity? FromAmperesPerMeterSecondSquared(QuantityValue? amperespermetersecondsquared) + { + if (amperespermetersecondsquared.HasValue) + { + return FromAmperesPerMeterSecondSquared(amperespermetersecondsquared.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricCurrentDensity unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricCurrentDensity From(double value, ElectricCurrentDensityUnit fromUnit) +#else + public static ElectricCurrentDensity From(QuantityValue value, ElectricCurrentDensityUnit fromUnit) +#endif + { + switch (fromUnit) + { + case ElectricCurrentDensityUnit.AmperePerMeterSecondSquared: + return FromAmperesPerMeterSecondSquared(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. + /// ElectricCurrentDensity unit value. + public static ElectricCurrentDensity? From(QuantityValue? value, ElectricCurrentDensityUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricCurrentDensityUnit.AmperePerMeterSecondSquared: + return FromAmperesPerMeterSecondSquared(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(ElectricCurrentDensityUnit 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(ElectricCurrentDensityUnit 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 ElectricCurrentDensity operator -(ElectricCurrentDensity right) + { + return new ElectricCurrentDensity(-right._amperesPerMeterSecondSquared); + } + + public static ElectricCurrentDensity operator +(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return new ElectricCurrentDensity(left._amperesPerMeterSecondSquared + right._amperesPerMeterSecondSquared); + } + + public static ElectricCurrentDensity operator -(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return new ElectricCurrentDensity(left._amperesPerMeterSecondSquared - right._amperesPerMeterSecondSquared); + } + + public static ElectricCurrentDensity operator *(double left, ElectricCurrentDensity right) + { + return new ElectricCurrentDensity(left*right._amperesPerMeterSecondSquared); + } + + public static ElectricCurrentDensity operator *(ElectricCurrentDensity left, double right) + { + return new ElectricCurrentDensity(left._amperesPerMeterSecondSquared*(double)right); + } + + public static ElectricCurrentDensity operator /(ElectricCurrentDensity left, double right) + { + return new ElectricCurrentDensity(left._amperesPerMeterSecondSquared/(double)right); + } + + public static double operator /(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return Convert.ToDouble(left._amperesPerMeterSecondSquared/right._amperesPerMeterSecondSquared); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricCurrentDensity)) throw new ArgumentException("Expected type ElectricCurrentDensity.", "obj"); + return CompareTo((ElectricCurrentDensity) 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(ElectricCurrentDensity other) + { + return _amperesPerMeterSecondSquared.CompareTo(other._amperesPerMeterSecondSquared); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return left._amperesPerMeterSecondSquared <= right._amperesPerMeterSecondSquared; + } + + public static bool operator >=(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return left._amperesPerMeterSecondSquared >= right._amperesPerMeterSecondSquared; + } + + public static bool operator <(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return left._amperesPerMeterSecondSquared < right._amperesPerMeterSecondSquared; + } + + public static bool operator >(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + return left._amperesPerMeterSecondSquared > right._amperesPerMeterSecondSquared; + } + + [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 ==(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._amperesPerMeterSecondSquared == right._amperesPerMeterSecondSquared; + } + + [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 !=(ElectricCurrentDensity left, ElectricCurrentDensity right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._amperesPerMeterSecondSquared != right._amperesPerMeterSecondSquared; + } +#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 _amperesPerMeterSecondSquared.Equals(((ElectricCurrentDensity) obj)._amperesPerMeterSecondSquared); + } + + /// + /// Compare equality to another ElectricCurrentDensity 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(ElectricCurrentDensity other, ElectricCurrentDensity maxError) + { + return Math.Abs(_amperesPerMeterSecondSquared - other._amperesPerMeterSecondSquared) <= maxError._amperesPerMeterSecondSquared; + } + + public override int GetHashCode() + { + return _amperesPerMeterSecondSquared.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(ElectricCurrentDensityUnit unit) + { + switch (unit) + { + case ElectricCurrentDensityUnit.AmperePerMeterSecondSquared: + return AmperesPerMeterSecondSquared; + + 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 ElectricCurrentDensity 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 ElectricCurrentDensity 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); + ElectricCurrentDensityUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromAmperesPerMeterSecondSquared(x.AmperesPerMeterSecondSquared + y.AmperesPerMeterSecondSquared)); + } + + /// + /// 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 ElectricCurrentDensity 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 ElectricCurrentDensity result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(ElectricCurrentDensity); + 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 ElectricCurrentDensityUnit 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 ElectricCurrentDensityUnit 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 ElectricCurrentDensityUnit 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 == ElectricCurrentDensityUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricCurrentDensityUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is AmperePerMeterSecondSquared + /// + public static ElectricCurrentDensityUnit ToStringDefaultUnit { get; set; } = ElectricCurrentDensityUnit.AmperePerMeterSecondSquared; + + /// + /// 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(ElectricCurrentDensityUnit 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(ElectricCurrentDensityUnit 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(ElectricCurrentDensityUnit 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(ElectricCurrentDensityUnit 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 ElectricCurrentDensity + /// + public static ElectricCurrentDensity MaxValue + { + get + { + return new ElectricCurrentDensity(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of ElectricCurrentDensity + /// + public static ElectricCurrentDensity MinValue + { + get + { + return new ElectricCurrentDensity(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs new file mode 100644 index 0000000000..92a9034ee9 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -0,0 +1,677 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// In electromagnetism, the current gradient describes how the current changes in time. + /// + // 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 ElectricCurrentGradient +#else + public partial struct ElectricCurrentGradient : IComparable, IComparable +#endif + { + /// + /// Base unit of ElectricCurrentGradient. + /// + private readonly double _amperesPerSecond; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public ElectricCurrentGradient() : this(0) + { + } +#endif + + public ElectricCurrentGradient(double amperespersecond) + { + _amperesPerSecond = Convert.ToDouble(amperespersecond); + } + + // 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 + ElectricCurrentGradient(long amperespersecond) + { + _amperesPerSecond = Convert.ToDouble(amperespersecond); + } + + // 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 + ElectricCurrentGradient(decimal amperespersecond) + { + _amperesPerSecond = Convert.ToDouble(amperespersecond); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.ElectricCurrentGradient; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static ElectricCurrentGradientUnit BaseUnit + { + get { return ElectricCurrentGradientUnit.AmperePerSecond; } + } + + /// + /// All units of measurement for the ElectricCurrentGradient quantity. + /// + public static ElectricCurrentGradientUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentGradientUnit)).Cast().ToArray(); + + /// + /// Get ElectricCurrentGradient in AmperesPerSecond. + /// + public double AmperesPerSecond + { + get { return _amperesPerSecond; } + } + + #endregion + + #region Static + + public static ElectricCurrentGradient Zero + { + get { return new ElectricCurrentGradient(); } + } + + /// + /// Get ElectricCurrentGradient from AmperesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricCurrentGradient FromAmperesPerSecond(double amperespersecond) + { + double value = (double) amperespersecond; + return new ElectricCurrentGradient(value); + } +#else + public static ElectricCurrentGradient FromAmperesPerSecond(QuantityValue amperespersecond) + { + double value = (double) amperespersecond; + return new ElectricCurrentGradient((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 ElectricCurrentGradient from nullable AmperesPerSecond. + /// + public static ElectricCurrentGradient? FromAmperesPerSecond(QuantityValue? amperespersecond) + { + if (amperespersecond.HasValue) + { + return FromAmperesPerSecond(amperespersecond.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricCurrentGradient unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricCurrentGradient From(double value, ElectricCurrentGradientUnit fromUnit) +#else + public static ElectricCurrentGradient From(QuantityValue value, ElectricCurrentGradientUnit fromUnit) +#endif + { + switch (fromUnit) + { + case ElectricCurrentGradientUnit.AmperePerSecond: + return FromAmperesPerSecond(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. + /// ElectricCurrentGradient unit value. + public static ElectricCurrentGradient? From(QuantityValue? value, ElectricCurrentGradientUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricCurrentGradientUnit.AmperePerSecond: + return FromAmperesPerSecond(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(ElectricCurrentGradientUnit 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(ElectricCurrentGradientUnit 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 ElectricCurrentGradient operator -(ElectricCurrentGradient right) + { + return new ElectricCurrentGradient(-right._amperesPerSecond); + } + + public static ElectricCurrentGradient operator +(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return new ElectricCurrentGradient(left._amperesPerSecond + right._amperesPerSecond); + } + + public static ElectricCurrentGradient operator -(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return new ElectricCurrentGradient(left._amperesPerSecond - right._amperesPerSecond); + } + + public static ElectricCurrentGradient operator *(double left, ElectricCurrentGradient right) + { + return new ElectricCurrentGradient(left*right._amperesPerSecond); + } + + public static ElectricCurrentGradient operator *(ElectricCurrentGradient left, double right) + { + return new ElectricCurrentGradient(left._amperesPerSecond*(double)right); + } + + public static ElectricCurrentGradient operator /(ElectricCurrentGradient left, double right) + { + return new ElectricCurrentGradient(left._amperesPerSecond/(double)right); + } + + public static double operator /(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return Convert.ToDouble(left._amperesPerSecond/right._amperesPerSecond); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricCurrentGradient)) throw new ArgumentException("Expected type ElectricCurrentGradient.", "obj"); + return CompareTo((ElectricCurrentGradient) 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(ElectricCurrentGradient other) + { + return _amperesPerSecond.CompareTo(other._amperesPerSecond); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return left._amperesPerSecond <= right._amperesPerSecond; + } + + public static bool operator >=(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return left._amperesPerSecond >= right._amperesPerSecond; + } + + public static bool operator <(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return left._amperesPerSecond < right._amperesPerSecond; + } + + public static bool operator >(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + return left._amperesPerSecond > right._amperesPerSecond; + } + + [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 ==(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._amperesPerSecond == right._amperesPerSecond; + } + + [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 !=(ElectricCurrentGradient left, ElectricCurrentGradient right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._amperesPerSecond != right._amperesPerSecond; + } +#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 _amperesPerSecond.Equals(((ElectricCurrentGradient) obj)._amperesPerSecond); + } + + /// + /// Compare equality to another ElectricCurrentGradient 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(ElectricCurrentGradient other, ElectricCurrentGradient maxError) + { + return Math.Abs(_amperesPerSecond - other._amperesPerSecond) <= maxError._amperesPerSecond; + } + + public override int GetHashCode() + { + return _amperesPerSecond.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(ElectricCurrentGradientUnit unit) + { + switch (unit) + { + case ElectricCurrentGradientUnit.AmperePerSecond: + return AmperesPerSecond; + + 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 ElectricCurrentGradient 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 ElectricCurrentGradient 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); + ElectricCurrentGradientUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromAmperesPerSecond(x.AmperesPerSecond + y.AmperesPerSecond)); + } + + /// + /// 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 ElectricCurrentGradient 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 ElectricCurrentGradient result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(ElectricCurrentGradient); + 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 ElectricCurrentGradientUnit 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 ElectricCurrentGradientUnit 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 ElectricCurrentGradientUnit 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 == ElectricCurrentGradientUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricCurrentGradientUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is AmperePerSecond + /// + public static ElectricCurrentGradientUnit ToStringDefaultUnit { get; set; } = ElectricCurrentGradientUnit.AmperePerSecond; + + /// + /// 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(ElectricCurrentGradientUnit 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(ElectricCurrentGradientUnit 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(ElectricCurrentGradientUnit 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(ElectricCurrentGradientUnit 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 ElectricCurrentGradient + /// + public static ElectricCurrentGradient MaxValue + { + get + { + return new ElectricCurrentGradient(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of ElectricCurrentGradient + /// + public static ElectricCurrentGradient MinValue + { + get + { + return new ElectricCurrentGradient(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs new file mode 100644 index 0000000000..2b9bf4f159 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs @@ -0,0 +1,677 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// An electric field is a force field that surrounds electric charges that attracts or repels other electric charges. + /// + // 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 ElectricField +#else + public partial struct ElectricField : IComparable, IComparable +#endif + { + /// + /// Base unit of ElectricField. + /// + private readonly double _voltsPerMeter; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public ElectricField() : this(0) + { + } +#endif + + public ElectricField(double voltspermeter) + { + _voltsPerMeter = Convert.ToDouble(voltspermeter); + } + + // 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 + ElectricField(long voltspermeter) + { + _voltsPerMeter = Convert.ToDouble(voltspermeter); + } + + // 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 + ElectricField(decimal voltspermeter) + { + _voltsPerMeter = Convert.ToDouble(voltspermeter); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.ElectricField; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static ElectricFieldUnit BaseUnit + { + get { return ElectricFieldUnit.VoltPerMeter; } + } + + /// + /// All units of measurement for the ElectricField quantity. + /// + public static ElectricFieldUnit[] Units { get; } = Enum.GetValues(typeof(ElectricFieldUnit)).Cast().ToArray(); + + /// + /// Get ElectricField in VoltsPerMeter. + /// + public double VoltsPerMeter + { + get { return _voltsPerMeter; } + } + + #endregion + + #region Static + + public static ElectricField Zero + { + get { return new ElectricField(); } + } + + /// + /// Get ElectricField from VoltsPerMeter. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricField FromVoltsPerMeter(double voltspermeter) + { + double value = (double) voltspermeter; + return new ElectricField(value); + } +#else + public static ElectricField FromVoltsPerMeter(QuantityValue voltspermeter) + { + double value = (double) voltspermeter; + return new ElectricField((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 ElectricField from nullable VoltsPerMeter. + /// + public static ElectricField? FromVoltsPerMeter(QuantityValue? voltspermeter) + { + if (voltspermeter.HasValue) + { + return FromVoltsPerMeter(voltspermeter.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricField unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricField From(double value, ElectricFieldUnit fromUnit) +#else + public static ElectricField From(QuantityValue value, ElectricFieldUnit fromUnit) +#endif + { + switch (fromUnit) + { + case ElectricFieldUnit.VoltPerMeter: + return FromVoltsPerMeter(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. + /// ElectricField unit value. + public static ElectricField? From(QuantityValue? value, ElectricFieldUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricFieldUnit.VoltPerMeter: + return FromVoltsPerMeter(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(ElectricFieldUnit 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(ElectricFieldUnit 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 ElectricField operator -(ElectricField right) + { + return new ElectricField(-right._voltsPerMeter); + } + + public static ElectricField operator +(ElectricField left, ElectricField right) + { + return new ElectricField(left._voltsPerMeter + right._voltsPerMeter); + } + + public static ElectricField operator -(ElectricField left, ElectricField right) + { + return new ElectricField(left._voltsPerMeter - right._voltsPerMeter); + } + + public static ElectricField operator *(double left, ElectricField right) + { + return new ElectricField(left*right._voltsPerMeter); + } + + public static ElectricField operator *(ElectricField left, double right) + { + return new ElectricField(left._voltsPerMeter*(double)right); + } + + public static ElectricField operator /(ElectricField left, double right) + { + return new ElectricField(left._voltsPerMeter/(double)right); + } + + public static double operator /(ElectricField left, ElectricField right) + { + return Convert.ToDouble(left._voltsPerMeter/right._voltsPerMeter); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricField)) throw new ArgumentException("Expected type ElectricField.", "obj"); + return CompareTo((ElectricField) 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(ElectricField other) + { + return _voltsPerMeter.CompareTo(other._voltsPerMeter); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(ElectricField left, ElectricField right) + { + return left._voltsPerMeter <= right._voltsPerMeter; + } + + public static bool operator >=(ElectricField left, ElectricField right) + { + return left._voltsPerMeter >= right._voltsPerMeter; + } + + public static bool operator <(ElectricField left, ElectricField right) + { + return left._voltsPerMeter < right._voltsPerMeter; + } + + public static bool operator >(ElectricField left, ElectricField right) + { + return left._voltsPerMeter > right._voltsPerMeter; + } + + [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 ==(ElectricField left, ElectricField right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._voltsPerMeter == right._voltsPerMeter; + } + + [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 !=(ElectricField left, ElectricField right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._voltsPerMeter != right._voltsPerMeter; + } +#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 _voltsPerMeter.Equals(((ElectricField) obj)._voltsPerMeter); + } + + /// + /// Compare equality to another ElectricField 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(ElectricField other, ElectricField maxError) + { + return Math.Abs(_voltsPerMeter - other._voltsPerMeter) <= maxError._voltsPerMeter; + } + + public override int GetHashCode() + { + return _voltsPerMeter.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(ElectricFieldUnit unit) + { + switch (unit) + { + case ElectricFieldUnit.VoltPerMeter: + return VoltsPerMeter; + + 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 ElectricField 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 ElectricField 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); + ElectricFieldUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromVoltsPerMeter(x.VoltsPerMeter + y.VoltsPerMeter)); + } + + /// + /// 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 ElectricField 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 ElectricField result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(ElectricField); + 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 ElectricFieldUnit 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 ElectricFieldUnit 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 ElectricFieldUnit 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 == ElectricFieldUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricFieldUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is VoltPerMeter + /// + public static ElectricFieldUnit ToStringDefaultUnit { get; set; } = ElectricFieldUnit.VoltPerMeter; + + /// + /// 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(ElectricFieldUnit 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(ElectricFieldUnit 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(ElectricFieldUnit 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(ElectricFieldUnit 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 ElectricField + /// + public static ElectricField MaxValue + { + get + { + return new ElectricField(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of ElectricField + /// + public static ElectricField MinValue + { + get + { + return new ElectricField(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs new file mode 100644 index 0000000000..589889c70e --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs @@ -0,0 +1,677 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// Inductance is a property of an electrical conductor which opposes a change in current. + /// + // 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 ElectricInductance +#else + public partial struct ElectricInductance : IComparable, IComparable +#endif + { + /// + /// Base unit of ElectricInductance. + /// + private readonly double _henries; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public ElectricInductance() : this(0) + { + } +#endif + + public ElectricInductance(double henries) + { + _henries = Convert.ToDouble(henries); + } + + // 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 + ElectricInductance(long henries) + { + _henries = Convert.ToDouble(henries); + } + + // 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 + ElectricInductance(decimal henries) + { + _henries = Convert.ToDouble(henries); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.ElectricInductance; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static ElectricInductanceUnit BaseUnit + { + get { return ElectricInductanceUnit.Henry; } + } + + /// + /// All units of measurement for the ElectricInductance quantity. + /// + public static ElectricInductanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricInductanceUnit)).Cast().ToArray(); + + /// + /// Get ElectricInductance in Henries. + /// + public double Henries + { + get { return _henries; } + } + + #endregion + + #region Static + + public static ElectricInductance Zero + { + get { return new ElectricInductance(); } + } + + /// + /// Get ElectricInductance from Henries. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static ElectricInductance FromHenries(double henries) + { + double value = (double) henries; + return new ElectricInductance(value); + } +#else + public static ElectricInductance FromHenries(QuantityValue henries) + { + double value = (double) henries; + return new ElectricInductance((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 ElectricInductance from nullable Henries. + /// + public static ElectricInductance? FromHenries(QuantityValue? henries) + { + if (henries.HasValue) + { + return FromHenries(henries.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricInductance unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static ElectricInductance From(double value, ElectricInductanceUnit fromUnit) +#else + public static ElectricInductance From(QuantityValue value, ElectricInductanceUnit fromUnit) +#endif + { + switch (fromUnit) + { + case ElectricInductanceUnit.Henry: + return FromHenries(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. + /// ElectricInductance unit value. + public static ElectricInductance? From(QuantityValue? value, ElectricInductanceUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricInductanceUnit.Henry: + return FromHenries(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(ElectricInductanceUnit 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(ElectricInductanceUnit 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 ElectricInductance operator -(ElectricInductance right) + { + return new ElectricInductance(-right._henries); + } + + public static ElectricInductance operator +(ElectricInductance left, ElectricInductance right) + { + return new ElectricInductance(left._henries + right._henries); + } + + public static ElectricInductance operator -(ElectricInductance left, ElectricInductance right) + { + return new ElectricInductance(left._henries - right._henries); + } + + public static ElectricInductance operator *(double left, ElectricInductance right) + { + return new ElectricInductance(left*right._henries); + } + + public static ElectricInductance operator *(ElectricInductance left, double right) + { + return new ElectricInductance(left._henries*(double)right); + } + + public static ElectricInductance operator /(ElectricInductance left, double right) + { + return new ElectricInductance(left._henries/(double)right); + } + + public static double operator /(ElectricInductance left, ElectricInductance right) + { + return Convert.ToDouble(left._henries/right._henries); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is ElectricInductance)) throw new ArgumentException("Expected type ElectricInductance.", "obj"); + return CompareTo((ElectricInductance) 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(ElectricInductance other) + { + return _henries.CompareTo(other._henries); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(ElectricInductance left, ElectricInductance right) + { + return left._henries <= right._henries; + } + + public static bool operator >=(ElectricInductance left, ElectricInductance right) + { + return left._henries >= right._henries; + } + + public static bool operator <(ElectricInductance left, ElectricInductance right) + { + return left._henries < right._henries; + } + + public static bool operator >(ElectricInductance left, ElectricInductance right) + { + return left._henries > right._henries; + } + + [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 ==(ElectricInductance left, ElectricInductance right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._henries == right._henries; + } + + [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 !=(ElectricInductance left, ElectricInductance right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._henries != right._henries; + } +#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 _henries.Equals(((ElectricInductance) obj)._henries); + } + + /// + /// Compare equality to another ElectricInductance 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(ElectricInductance other, ElectricInductance maxError) + { + return Math.Abs(_henries - other._henries) <= maxError._henries; + } + + public override int GetHashCode() + { + return _henries.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(ElectricInductanceUnit unit) + { + switch (unit) + { + case ElectricInductanceUnit.Henry: + return Henries; + + 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 ElectricInductance 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 ElectricInductance 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); + ElectricInductanceUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromHenries(x.Henries + y.Henries)); + } + + /// + /// 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 ElectricInductance 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 ElectricInductance result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(ElectricInductance); + 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 ElectricInductanceUnit 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 ElectricInductanceUnit 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 ElectricInductanceUnit 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 == ElectricInductanceUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricInductanceUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is Henry + /// + public static ElectricInductanceUnit ToStringDefaultUnit { get; set; } = ElectricInductanceUnit.Henry; + + /// + /// 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(ElectricInductanceUnit 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(ElectricInductanceUnit 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(ElectricInductanceUnit 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(ElectricInductanceUnit 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 ElectricInductance + /// + public static ElectricInductance MaxValue + { + get + { + return new ElectricInductance(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of ElectricInductance + /// + public static ElectricInductance MinValue + { + get + { + return new ElectricInductance(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 06688fd25d..cbd1b6c3dc 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -61,7 +61,12 @@ public enum QuantityType Duration, DynamicViscosity, ElectricAdmittance, + ElectricConductivity, ElectricCurrent, + ElectricCurrentDensity, + ElectricCurrentGradient, + ElectricField, + ElectricInductance, ElectricPotential, ElectricPotentialAc, ElectricPotentialDc, diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 1a0537c3df..a0014d0063 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -732,6 +732,15 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "S"), }), }), + new UnitLocalization(typeof (ElectricConductivityUnit), + new[] + { + new CulturesForEnumValue((int) ElectricConductivityUnit.SiemensPerMeter, + new[] + { + new AbbreviationsForCulture("en-US", "S/m"), + }), + }), new UnitLocalization(typeof (ElectricCurrentUnit), new[] { @@ -771,6 +780,42 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "pA"), }), }), + new UnitLocalization(typeof (ElectricCurrentDensityUnit), + new[] + { + new CulturesForEnumValue((int) ElectricCurrentDensityUnit.AmperePerMeterSecondSquared, + new[] + { + new AbbreviationsForCulture("en-US", "A/m²"), + }), + }), + new UnitLocalization(typeof (ElectricCurrentGradientUnit), + new[] + { + new CulturesForEnumValue((int) ElectricCurrentGradientUnit.AmperePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "A/s"), + }), + }), + new UnitLocalization(typeof (ElectricFieldUnit), + new[] + { + new CulturesForEnumValue((int) ElectricFieldUnit.VoltPerMeter, + new[] + { + new AbbreviationsForCulture("en-US", "V/m"), + }), + }), + new UnitLocalization(typeof (ElectricInductanceUnit), + new[] + { + new CulturesForEnumValue((int) ElectricInductanceUnit.Henry, + new[] + { + new AbbreviationsForCulture("en-US", "H"), + }), + }), new UnitLocalization(typeof (ElectricPotentialUnit), new[] { diff --git a/UnitsNet/GeneratedCode/Units/ElectricConductivityUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricConductivityUnit.g.cs new file mode 100644 index 0000000000..9cd3728a8f --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricConductivityUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricConductivityUnit + { + Undefined = 0, + SiemensPerMeter, + } +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricCurrentDensityUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricCurrentDensityUnit.g.cs new file mode 100644 index 0000000000..c2d8d13e65 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricCurrentDensityUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCurrentDensityUnit + { + Undefined = 0, + AmperePerMeterSecondSquared, + } +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricCurrentGradientUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricCurrentGradientUnit.g.cs new file mode 100644 index 0000000000..5ef8d4d3df --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricCurrentGradientUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCurrentGradientUnit + { + Undefined = 0, + AmperePerSecond, + } +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricFieldUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricFieldUnit.g.cs new file mode 100644 index 0000000000..bb10c3b054 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricFieldUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricFieldUnit + { + Undefined = 0, + VoltPerMeter, + } +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricInductanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricInductanceUnit.g.cs new file mode 100644 index 0000000000..2471f24516 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricInductanceUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricInductanceUnit + { + Undefined = 0, + Henry, + } +} diff --git a/UnitsNet/UnitDefinitions/ElectricConductivity.json b/UnitsNet/UnitDefinitions/ElectricConductivity.json new file mode 100644 index 0000000000..d02e220f84 --- /dev/null +++ b/UnitsNet/UnitDefinitions/ElectricConductivity.json @@ -0,0 +1,20 @@ +{ + "Name": "ElectricConductivity", + "BaseUnit": "SiemensPerMeter", + "XmlDoc": "Electrical conductivity or specific conductance is the reciprocal of electrical resistivity, and measures a material's ability to conduct an electric current.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity", + "Units": [ + { + "SingularName": "SiemensPerMeter", + "PluralName": "SiemensPerMeter", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "S/m" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/ElectricCurrentDensity.json b/UnitsNet/UnitDefinitions/ElectricCurrentDensity.json new file mode 100644 index 0000000000..382c38861c --- /dev/null +++ b/UnitsNet/UnitDefinitions/ElectricCurrentDensity.json @@ -0,0 +1,20 @@ +{ + "Name": "ElectricCurrentDensity", + "BaseUnit": "AmperePerMeterSecondSquared", + "XmlDoc": "In electromagnetism, current density is the electric current per unit area of cross section.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Current_density", + "Units": [ + { + "SingularName": "AmperePerMeterSecondSquared", + "PluralName": "AmperesPerMeterSecondSquared", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "A/m²" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/ElectricCurrentGradient.json b/UnitsNet/UnitDefinitions/ElectricCurrentGradient.json new file mode 100644 index 0000000000..d17fa3d160 --- /dev/null +++ b/UnitsNet/UnitDefinitions/ElectricCurrentGradient.json @@ -0,0 +1,19 @@ +{ + "Name": "ElectricCurrentGradient", + "BaseUnit": "AmperePerSecond", + "XmlDoc": "In electromagnetism, the current gradient describes how the current changes in time.", + "Units": [ + { + "SingularName": "AmperePerSecond", + "PluralName": "AmperesPerSecond", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "A/s" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/ElectricField.json b/UnitsNet/UnitDefinitions/ElectricField.json new file mode 100644 index 0000000000..5c66754d0d --- /dev/null +++ b/UnitsNet/UnitDefinitions/ElectricField.json @@ -0,0 +1,20 @@ +{ + "Name": "ElectricField", + "BaseUnit": "VoltPerMeter", + "XmlDoc": "An electric field is a force field that surrounds electric charges that attracts or repels other electric charges.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electric_field", + "Units": [ + { + "SingularName": "VoltPerMeter", + "PluralName": "VoltsPerMeter", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "V/m" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet/UnitDefinitions/ElectricInductance.json b/UnitsNet/UnitDefinitions/ElectricInductance.json new file mode 100644 index 0000000000..f1208b4f1c --- /dev/null +++ b/UnitsNet/UnitDefinitions/ElectricInductance.json @@ -0,0 +1,20 @@ +{ + "Name": "ElectricInductance", + "BaseUnit": "Henry", + "XmlDoc": "Inductance is a property of an electrical conductor which opposes a change in current.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Inductance", + "Units": [ + { + "SingularName": "Henry", + "PluralName": "Henries", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "H" ] + } + ] + } + ] +} \ No newline at end of file