From 0095629b20d9af2c881fb7284938c5b68bb600cd Mon Sep 17 00:00:00 2001 From: Neil McNeight Date: Thu, 20 Sep 2018 10:21:05 -0500 Subject: [PATCH 1/3] Fix the use of '%' in ParseTests --- UnitsNet.Tests/CustomCode/ParseTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/ParseTests.cs b/UnitsNet.Tests/CustomCode/ParseTests.cs index 3fb03de1a0..44d29e7316 100644 --- a/UnitsNet.Tests/CustomCode/ParseTests.cs +++ b/UnitsNet.Tests/CustomCode/ParseTests.cs @@ -204,7 +204,7 @@ public void TryParseLengthUnitAbbreviationSpecialCharacters(string s) [InlineData("@")] [InlineData("#")] [InlineData("$")] - [InlineData("%")] + [InlineData("%%")] [InlineData("^")] [InlineData("&")] [InlineData("*")] @@ -235,4 +235,4 @@ private static string AssertExceptionAndGetFullTypeName(Action code) } } -} \ No newline at end of file +} From cba1a3242122f47182801eb9d9037a7b7120e342 Mon Sep 17 00:00:00 2001 From: Neil McNeight Date: Thu, 20 Sep 2018 17:23:13 -0500 Subject: [PATCH 2/3] Add 'SlugSquareFoot' and 'SlugSquareInch' as units of MassMomentOfIntertia, and 'slug' as a unit of Mass --- .../GeneratedCode/Quantities/Mass.Common.g.cs | 21 ++++++ .../MassMomentOfInertia.Common.g.cs | 42 ++++++++++++ Common/UnitDefinitions/Mass.json | 14 ++++ .../UnitDefinitions/MassMomentOfInertia.json | 24 +++++++ .../CustomCode/MassMomentOfInertiaTests.cs | 4 ++ UnitsNet.Tests/CustomCode/MassTests.cs | 2 + .../MassMomentOfInertiaTestsBase.g.cs | 20 ++++++ .../GeneratedCode/MassTestsBase.g.cs | 10 +++ .../Number/NumberToMassExtensions.g.cs | 34 ++++++++++ ...NumberToMassMomentOfInertiaExtensions.g.cs | 68 +++++++++++++++++++ .../Quantities/Mass.NetFramework.g.cs | 8 +++ .../MassMomentOfInertia.NetFramework.g.cs | 16 +++++ .../GeneratedCode/UnitSystem.Default.g.cs | 15 ++++ .../Units/MassMomentOfInertiaUnit.g.cs | 2 + UnitsNet/GeneratedCode/Units/MassUnit.g.cs | 6 ++ 15 files changed, 286 insertions(+) diff --git a/Common/GeneratedCode/Quantities/Mass.Common.g.cs b/Common/GeneratedCode/Quantities/Mass.Common.g.cs index 6840e238b6..6ec2eb035d 100644 --- a/Common/GeneratedCode/Quantities/Mass.Common.g.cs +++ b/Common/GeneratedCode/Quantities/Mass.Common.g.cs @@ -253,6 +253,11 @@ public static BaseDimensions BaseDimensions /// public double ShortTons => As(MassUnit.ShortTon); + /// + /// Get Mass in Slugs. + /// + public double Slugs => As(MassUnit.Slug); + /// /// Get Mass in Stone. /// @@ -535,6 +540,20 @@ public static Mass FromShortTons(QuantityValue shorttons) return new Mass(value, MassUnit.ShortTon); } + /// + /// Get Mass from Slugs. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static Mass FromSlugs(double slugs) +#else + public static Mass FromSlugs(QuantityValue slugs) +#endif + { + double value = (double) slugs; + return new Mass(value, MassUnit.Slug); + } + /// /// Get Mass from Stone. /// @@ -779,6 +798,7 @@ private double AsBaseUnit() case MassUnit.Pound: return _value*0.45359237; case MassUnit.ShortHundredweight: return _value/0.022046226218487758; case MassUnit.ShortTon: return _value*9.0718474e2; + case MassUnit.Slug: return _value/6.85217659e-2; case MassUnit.Stone: return _value/0.1574731728702698; case MassUnit.Tonne: return _value*1e3; default: @@ -814,6 +834,7 @@ private double AsBaseNumericType(MassUnit unit) case MassUnit.Pound: return baseUnitValue/0.45359237; case MassUnit.ShortHundredweight: return baseUnitValue*0.022046226218487758; case MassUnit.ShortTon: return baseUnitValue/9.0718474e2; + case MassUnit.Slug: return baseUnitValue*6.85217659e-2; case MassUnit.Stone: return baseUnitValue*0.1574731728702698; case MassUnit.Tonne: return baseUnitValue/1e3; default: diff --git a/Common/GeneratedCode/Quantities/MassMomentOfInertia.Common.g.cs b/Common/GeneratedCode/Quantities/MassMomentOfInertia.Common.g.cs index dd6e5d762f..b6ab53ea1e 100644 --- a/Common/GeneratedCode/Quantities/MassMomentOfInertia.Common.g.cs +++ b/Common/GeneratedCode/Quantities/MassMomentOfInertia.Common.g.cs @@ -268,6 +268,16 @@ public static BaseDimensions BaseDimensions /// public double PoundSquareInches => As(MassMomentOfInertiaUnit.PoundSquareInch); + /// + /// Get MassMomentOfInertia in SlugSquareFeet. + /// + public double SlugSquareFeet => As(MassMomentOfInertiaUnit.SlugSquareFoot); + + /// + /// Get MassMomentOfInertia in SlugSquareInches. + /// + public double SlugSquareInches => As(MassMomentOfInertiaUnit.SlugSquareInch); + /// /// Get MassMomentOfInertia in TonneSquareCentimeters. /// @@ -602,6 +612,34 @@ public static MassMomentOfInertia FromPoundSquareInches(QuantityValue poundsquar return new MassMomentOfInertia(value, MassMomentOfInertiaUnit.PoundSquareInch); } + /// + /// Get MassMomentOfInertia from SlugSquareFeet. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static MassMomentOfInertia FromSlugSquareFeet(double slugsquarefeet) +#else + public static MassMomentOfInertia FromSlugSquareFeet(QuantityValue slugsquarefeet) +#endif + { + double value = (double) slugsquarefeet; + return new MassMomentOfInertia(value, MassMomentOfInertiaUnit.SlugSquareFoot); + } + + /// + /// Get MassMomentOfInertia from SlugSquareInches. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static MassMomentOfInertia FromSlugSquareInches(double slugsquareinches) +#else + public static MassMomentOfInertia FromSlugSquareInches(QuantityValue slugsquareinches) +#endif + { + double value = (double) slugsquareinches; + return new MassMomentOfInertia(value, MassMomentOfInertiaUnit.SlugSquareInch); + } + /// /// Get MassMomentOfInertia from TonneSquareCentimeters. /// @@ -877,6 +915,8 @@ private double AsBaseUnit() case MassMomentOfInertiaUnit.MilligramSquareMillimeter: return (_value/1e9) * 1e-3d; case MassMomentOfInertiaUnit.PoundSquareFoot: return _value*4.21401101e-2; case MassMomentOfInertiaUnit.PoundSquareInch: return _value*2.9263965e-4; + case MassMomentOfInertiaUnit.SlugSquareFoot: return _value*1.35583; + case MassMomentOfInertiaUnit.SlugSquareInch: return _value*9.41548e-3; case MassMomentOfInertiaUnit.TonneSquareCentimeter: return _value/1e1; case MassMomentOfInertiaUnit.TonneSquareDecimeter: return _value/1e-1; case MassMomentOfInertiaUnit.TonneSquareMeter: return _value/1e-3; @@ -917,6 +957,8 @@ private double AsBaseNumericType(MassMomentOfInertiaUnit unit) case MassMomentOfInertiaUnit.MilligramSquareMillimeter: return (baseUnitValue*1e9) / 1e-3d; case MassMomentOfInertiaUnit.PoundSquareFoot: return baseUnitValue/4.21401101e-2; case MassMomentOfInertiaUnit.PoundSquareInch: return baseUnitValue/2.9263965e-4; + case MassMomentOfInertiaUnit.SlugSquareFoot: return baseUnitValue/1.35583; + case MassMomentOfInertiaUnit.SlugSquareInch: return baseUnitValue/9.41548e-3; case MassMomentOfInertiaUnit.TonneSquareCentimeter: return baseUnitValue*1e1; case MassMomentOfInertiaUnit.TonneSquareDecimeter: return baseUnitValue*1e-1; case MassMomentOfInertiaUnit.TonneSquareMeter: return baseUnitValue*1e-3; diff --git a/Common/UnitDefinitions/Mass.json b/Common/UnitDefinitions/Mass.json index 02b48baf56..01da8c5e01 100644 --- a/Common/UnitDefinitions/Mass.json +++ b/Common/UnitDefinitions/Mass.json @@ -110,6 +110,20 @@ } ] }, + { + "SingularName": "Slug", + "PluralName": "Slugs", + "FromUnitToBaseFunc": "x/6.85217659e-2", + "FromBaseToUnitFunc": "x*6.85217659e-2", + "XmlDocSummary": "The slug (abbreviation slug) is a unit of mass that is accelerated by 1 ft/s² when a force of one pound (lbf) is exerted on it.", + "XmlDocRemarks": "http://en.wikipedia.org/wiki/Slug_(unit)", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "slug" ] + } + ] + }, { "SingularName": "Stone", "PluralName": "Stone", diff --git a/Common/UnitDefinitions/MassMomentOfInertia.json b/Common/UnitDefinitions/MassMomentOfInertia.json index e7ad65903f..a817f43839 100644 --- a/Common/UnitDefinitions/MassMomentOfInertia.json +++ b/Common/UnitDefinitions/MassMomentOfInertia.json @@ -134,6 +134,30 @@ "Abbreviations": [ "lb·in²" ] } ] + }, + { + "SingularName": "SlugSquareFoot", + "PluralName": "SlugSquareFeet", + "FromUnitToBaseFunc": "x*1.35583", + "FromBaseToUnitFunc": "x/1.35583", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "slug·ft²" ] + } + ] + }, + { + "SingularName": "SlugSquareInch", + "PluralName": "SlugSquareInches", + "FromUnitToBaseFunc": "x*9.41548e-3", + "FromBaseToUnitFunc": "x/9.41548e-3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "slug·in²" ] + } + ] } ] } \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs b/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs index 076f89e01b..37ba5c84cd 100644 --- a/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs +++ b/UnitsNet.Tests/CustomCode/MassMomentOfInertiaTests.cs @@ -74,6 +74,10 @@ public class MassMomentOfInertiaTests : MassMomentOfInertiaTestsBase protected override double PoundSquareInchesInOneKilogramSquareMeter => 1 / 2.9263965e-4; + protected override double SlugSquareFeetInOneKilogramSquareMeter => 1 / 1.35583; + + protected override double SlugSquareInchesInOneKilogramSquareMeter => 1 / 9.41548e-3; + protected override double KilotonneSquareCentimetersInOneKilogramSquareMeter => 1e-2; protected override double KilotonneSquareDecimetersInOneKilogramSquareMeter => 1e-4; diff --git a/UnitsNet.Tests/CustomCode/MassTests.cs b/UnitsNet.Tests/CustomCode/MassTests.cs index 3519707e1e..05fb6c3f0e 100644 --- a/UnitsNet.Tests/CustomCode/MassTests.cs +++ b/UnitsNet.Tests/CustomCode/MassTests.cs @@ -62,6 +62,8 @@ public class MassTests : MassTestsBase protected override double ShortTonsInOneKilogram => 1.102311310924388e-3; + protected override double SlugsInOneKilogram => 6.85217659e-2; + protected override double StoneInOneKilogram => 0.1574731728702698; protected override double TonnesInOneKilogram => 1E-3; diff --git a/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs index 0e5d3c566f..9cfce397eb 100644 --- a/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/MassMomentOfInertiaTestsBase.g.cs @@ -74,6 +74,8 @@ public abstract partial class MassMomentOfInertiaTestsBase protected abstract double MilligramSquareMillimetersInOneKilogramSquareMeter { get; } protected abstract double PoundSquareFeetInOneKilogramSquareMeter { get; } protected abstract double PoundSquareInchesInOneKilogramSquareMeter { get; } + protected abstract double SlugSquareFeetInOneKilogramSquareMeter { get; } + protected abstract double SlugSquareInchesInOneKilogramSquareMeter { get; } protected abstract double TonneSquareCentimetersInOneKilogramSquareMeter { get; } protected abstract double TonneSquareDecimetersInOneKilogramSquareMeter { get; } protected abstract double TonneSquareMetersInOneKilogramSquareMeter { get; } @@ -102,6 +104,8 @@ public abstract partial class MassMomentOfInertiaTestsBase protected virtual double MilligramSquareMillimetersTolerance { get { return 1e-5; } } protected virtual double PoundSquareFeetTolerance { get { return 1e-5; } } protected virtual double PoundSquareInchesTolerance { get { return 1e-5; } } + protected virtual double SlugSquareFeetTolerance { get { return 1e-5; } } + protected virtual double SlugSquareInchesTolerance { get { return 1e-5; } } protected virtual double TonneSquareCentimetersTolerance { get { return 1e-5; } } protected virtual double TonneSquareDecimetersTolerance { get { return 1e-5; } } protected virtual double TonneSquareMetersTolerance { get { return 1e-5; } } @@ -134,6 +138,8 @@ public void KilogramSquareMeterToMassMomentOfInertiaUnits() AssertEx.EqualTolerance(MilligramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.MilligramSquareMillimeters, MilligramSquareMillimetersTolerance); AssertEx.EqualTolerance(PoundSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.PoundSquareFeet, PoundSquareFeetTolerance); AssertEx.EqualTolerance(PoundSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.PoundSquareInches, PoundSquareInchesTolerance); + AssertEx.EqualTolerance(SlugSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.SlugSquareFeet, SlugSquareFeetTolerance); + AssertEx.EqualTolerance(SlugSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.SlugSquareInches, SlugSquareInchesTolerance); AssertEx.EqualTolerance(TonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareCentimeters, TonneSquareCentimetersTolerance); AssertEx.EqualTolerance(TonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareDecimeters, TonneSquareDecimetersTolerance); AssertEx.EqualTolerance(TonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.TonneSquareMeters, TonneSquareMetersTolerance); @@ -165,6 +171,8 @@ public void FromValueAndUnit() AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.MilligramSquareMillimeter).MilligramSquareMillimeters, MilligramSquareMillimetersTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.PoundSquareFoot).PoundSquareFeet, PoundSquareFeetTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.PoundSquareInch).PoundSquareInches, PoundSquareInchesTolerance); + AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.SlugSquareFoot).SlugSquareFeet, SlugSquareFeetTolerance); + AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.SlugSquareInch).SlugSquareInches, SlugSquareInchesTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareCentimeter).TonneSquareCentimeters, TonneSquareCentimetersTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareDecimeter).TonneSquareDecimeters, TonneSquareDecimetersTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.From(1, MassMomentOfInertiaUnit.TonneSquareMeter).TonneSquareMeters, TonneSquareMetersTolerance); @@ -197,6 +205,8 @@ public void As() AssertEx.EqualTolerance(MilligramSquareMillimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.MilligramSquareMillimeter), MilligramSquareMillimetersTolerance); AssertEx.EqualTolerance(PoundSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.PoundSquareFoot), PoundSquareFeetTolerance); AssertEx.EqualTolerance(PoundSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.PoundSquareInch), PoundSquareInchesTolerance); + AssertEx.EqualTolerance(SlugSquareFeetInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.SlugSquareFoot), SlugSquareFeetTolerance); + AssertEx.EqualTolerance(SlugSquareInchesInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.SlugSquareInch), SlugSquareInchesTolerance); AssertEx.EqualTolerance(TonneSquareCentimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareCentimeter), TonneSquareCentimetersTolerance); AssertEx.EqualTolerance(TonneSquareDecimetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareDecimeter), TonneSquareDecimetersTolerance); AssertEx.EqualTolerance(TonneSquareMetersInOneKilogramSquareMeter, kilogramsquaremeter.As(MassMomentOfInertiaUnit.TonneSquareMeter), TonneSquareMetersTolerance); @@ -296,6 +306,14 @@ public void ToUnit() AssertEx.EqualTolerance(PoundSquareInchesInOneKilogramSquareMeter, (double)poundsquareinchQuantity.Value, PoundSquareInchesTolerance); Assert.Equal(MassMomentOfInertiaUnit.PoundSquareInch, poundsquareinchQuantity.Unit); + var slugsquarefootQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.SlugSquareFoot); + AssertEx.EqualTolerance(SlugSquareFeetInOneKilogramSquareMeter, (double)slugsquarefootQuantity.Value, SlugSquareFeetTolerance); + Assert.Equal(MassMomentOfInertiaUnit.SlugSquareFoot, slugsquarefootQuantity.Unit); + + var slugsquareinchQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.SlugSquareInch); + AssertEx.EqualTolerance(SlugSquareInchesInOneKilogramSquareMeter, (double)slugsquareinchQuantity.Value, SlugSquareInchesTolerance); + Assert.Equal(MassMomentOfInertiaUnit.SlugSquareInch, slugsquareinchQuantity.Unit); + var tonnesquarecentimeterQuantity = kilogramsquaremeter.ToUnit(MassMomentOfInertiaUnit.TonneSquareCentimeter); AssertEx.EqualTolerance(TonneSquareCentimetersInOneKilogramSquareMeter, (double)tonnesquarecentimeterQuantity.Value, TonneSquareCentimetersTolerance); Assert.Equal(MassMomentOfInertiaUnit.TonneSquareCentimeter, tonnesquarecentimeterQuantity.Unit); @@ -339,6 +357,8 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, MassMomentOfInertia.FromMilligramSquareMillimeters(kilogramsquaremeter.MilligramSquareMillimeters).KilogramSquareMeters, MilligramSquareMillimetersTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.FromPoundSquareFeet(kilogramsquaremeter.PoundSquareFeet).KilogramSquareMeters, PoundSquareFeetTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.FromPoundSquareInches(kilogramsquaremeter.PoundSquareInches).KilogramSquareMeters, PoundSquareInchesTolerance); + AssertEx.EqualTolerance(1, MassMomentOfInertia.FromSlugSquareFeet(kilogramsquaremeter.SlugSquareFeet).KilogramSquareMeters, SlugSquareFeetTolerance); + AssertEx.EqualTolerance(1, MassMomentOfInertia.FromSlugSquareInches(kilogramsquaremeter.SlugSquareInches).KilogramSquareMeters, SlugSquareInchesTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareCentimeters(kilogramsquaremeter.TonneSquareCentimeters).KilogramSquareMeters, TonneSquareCentimetersTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareDecimeters(kilogramsquaremeter.TonneSquareDecimeters).KilogramSquareMeters, TonneSquareDecimetersTolerance); AssertEx.EqualTolerance(1, MassMomentOfInertia.FromTonneSquareMeters(kilogramsquaremeter.TonneSquareMeters).KilogramSquareMeters, TonneSquareMetersTolerance); diff --git a/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs index af84e2275c..a05072faec 100644 --- a/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs @@ -71,6 +71,7 @@ public abstract partial class MassTestsBase protected abstract double PoundsInOneKilogram { get; } protected abstract double ShortHundredweightInOneKilogram { get; } protected abstract double ShortTonsInOneKilogram { get; } + protected abstract double SlugsInOneKilogram { get; } protected abstract double StoneInOneKilogram { get; } protected abstract double TonnesInOneKilogram { get; } @@ -94,6 +95,7 @@ public abstract partial class MassTestsBase protected virtual double PoundsTolerance { get { return 1e-5; } } protected virtual double ShortHundredweightTolerance { get { return 1e-5; } } protected virtual double ShortTonsTolerance { get { return 1e-5; } } + protected virtual double SlugsTolerance { get { return 1e-5; } } protected virtual double StoneTolerance { get { return 1e-5; } } protected virtual double TonnesTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -121,6 +123,7 @@ public void KilogramToMassUnits() AssertEx.EqualTolerance(PoundsInOneKilogram, kilogram.Pounds, PoundsTolerance); AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, kilogram.ShortHundredweight, ShortHundredweightTolerance); AssertEx.EqualTolerance(ShortTonsInOneKilogram, kilogram.ShortTons, ShortTonsTolerance); + AssertEx.EqualTolerance(SlugsInOneKilogram, kilogram.Slugs, SlugsTolerance); AssertEx.EqualTolerance(StoneInOneKilogram, kilogram.Stone, StoneTolerance); AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.Tonnes, TonnesTolerance); } @@ -147,6 +150,7 @@ public void FromValueAndUnit() AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Pound).Pounds, PoundsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.ShortHundredweight).ShortHundredweight, ShortHundredweightTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.ShortTon).ShortTons, ShortTonsTolerance); + AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Slug).Slugs, SlugsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Stone).Stone, StoneTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Tonne).Tonnes, TonnesTolerance); } @@ -174,6 +178,7 @@ public void As() AssertEx.EqualTolerance(PoundsInOneKilogram, kilogram.As(MassUnit.Pound), PoundsTolerance); AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, kilogram.As(MassUnit.ShortHundredweight), ShortHundredweightTolerance); AssertEx.EqualTolerance(ShortTonsInOneKilogram, kilogram.As(MassUnit.ShortTon), ShortTonsTolerance); + AssertEx.EqualTolerance(SlugsInOneKilogram, kilogram.As(MassUnit.Slug), SlugsTolerance); AssertEx.EqualTolerance(StoneInOneKilogram, kilogram.As(MassUnit.Stone), StoneTolerance); AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.As(MassUnit.Tonne), TonnesTolerance); } @@ -259,6 +264,10 @@ public void ToUnit() AssertEx.EqualTolerance(ShortTonsInOneKilogram, (double)shorttonQuantity.Value, ShortTonsTolerance); Assert.Equal(MassUnit.ShortTon, shorttonQuantity.Unit); + var slugQuantity = kilogram.ToUnit(MassUnit.Slug); + AssertEx.EqualTolerance(SlugsInOneKilogram, (double)slugQuantity.Value, SlugsTolerance); + Assert.Equal(MassUnit.Slug, slugQuantity.Unit); + var stoneQuantity = kilogram.ToUnit(MassUnit.Stone); AssertEx.EqualTolerance(StoneInOneKilogram, (double)stoneQuantity.Value, StoneTolerance); Assert.Equal(MassUnit.Stone, stoneQuantity.Unit); @@ -291,6 +300,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Mass.FromPounds(kilogram.Pounds).Kilograms, PoundsTolerance); AssertEx.EqualTolerance(1, Mass.FromShortHundredweight(kilogram.ShortHundredweight).Kilograms, ShortHundredweightTolerance); AssertEx.EqualTolerance(1, Mass.FromShortTons(kilogram.ShortTons).Kilograms, ShortTonsTolerance); + AssertEx.EqualTolerance(1, Mass.FromSlugs(kilogram.Slugs).Kilograms, SlugsTolerance); AssertEx.EqualTolerance(1, Mass.FromStone(kilogram.Stone).Kilograms, StoneTolerance); AssertEx.EqualTolerance(1, Mass.FromTonnes(kilogram.Tonnes).Kilograms, TonnesTolerance); } diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassExtensions.g.cs index bf8fc30de0..2aa7ece227 100644 --- a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassExtensions.g.cs +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassExtensions.g.cs @@ -690,6 +690,40 @@ public static class NumberToMassExtensions #endregion + #region Slug + + /// + public static Mass Slugs(this int value) => Mass.FromSlugs(value); + + /// + public static Mass? Slugs(this int? value) => Mass.FromSlugs(value); + + /// + public static Mass Slugs(this long value) => Mass.FromSlugs(value); + + /// + public static Mass? Slugs(this long? value) => Mass.FromSlugs(value); + + /// + public static Mass Slugs(this double value) => Mass.FromSlugs(value); + + /// + public static Mass? Slugs(this double? value) => Mass.FromSlugs(value); + + /// + public static Mass Slugs(this float value) => Mass.FromSlugs(value); + + /// + public static Mass? Slugs(this float? value) => Mass.FromSlugs(value); + + /// + public static Mass Slugs(this decimal value) => Mass.FromSlugs(Convert.ToDouble(value)); + + /// + public static Mass? Slugs(this decimal? value) => Mass.FromSlugs(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + #region Stone /// diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassMomentOfInertiaExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassMomentOfInertiaExtensions.g.cs index 08206145eb..1f5269aec3 100644 --- a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassMomentOfInertiaExtensions.g.cs +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassMomentOfInertiaExtensions.g.cs @@ -792,6 +792,74 @@ public static class NumberToMassMomentOfInertiaExtensions #endregion + #region SlugSquareFoot + + /// + public static MassMomentOfInertia SlugSquareFeet(this int value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia? SlugSquareFeet(this int? value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia SlugSquareFeet(this long value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia? SlugSquareFeet(this long? value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia SlugSquareFeet(this double value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia? SlugSquareFeet(this double? value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia SlugSquareFeet(this float value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia? SlugSquareFeet(this float? value) => MassMomentOfInertia.FromSlugSquareFeet(value); + + /// + public static MassMomentOfInertia SlugSquareFeet(this decimal value) => MassMomentOfInertia.FromSlugSquareFeet(Convert.ToDouble(value)); + + /// + public static MassMomentOfInertia? SlugSquareFeet(this decimal? value) => MassMomentOfInertia.FromSlugSquareFeet(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region SlugSquareInch + + /// + public static MassMomentOfInertia SlugSquareInches(this int value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia? SlugSquareInches(this int? value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia SlugSquareInches(this long value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia? SlugSquareInches(this long? value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia SlugSquareInches(this double value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia? SlugSquareInches(this double? value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia SlugSquareInches(this float value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia? SlugSquareInches(this float? value) => MassMomentOfInertia.FromSlugSquareInches(value); + + /// + public static MassMomentOfInertia SlugSquareInches(this decimal value) => MassMomentOfInertia.FromSlugSquareInches(Convert.ToDouble(value)); + + /// + public static MassMomentOfInertia? SlugSquareInches(this decimal? value) => MassMomentOfInertia.FromSlugSquareInches(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + #region TonneSquareCentimeter /// diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs index a8c266798f..ab356ad1ee 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs @@ -214,6 +214,14 @@ public partial struct Mass : IComparable, IComparable return shorttons.HasValue ? FromShortTons(shorttons.Value) : default(Mass?); } + /// + /// Get nullable Mass from nullable Slugs. + /// + public static Mass? FromSlugs(QuantityValue? slugs) + { + return slugs.HasValue ? FromSlugs(slugs.Value) : default(Mass?); + } + /// /// Get nullable Mass from nullable Stone. /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs index 666fe20eb6..aa779e9853 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs @@ -238,6 +238,22 @@ public partial struct MassMomentOfInertia : IComparable, IComparable + /// Get nullable MassMomentOfInertia from nullable SlugSquareFeet. + /// + public static MassMomentOfInertia? FromSlugSquareFeet(QuantityValue? slugsquarefeet) + { + return slugsquarefeet.HasValue ? FromSlugSquareFeet(slugsquarefeet.Value) : default(MassMomentOfInertia?); + } + + /// + /// Get nullable MassMomentOfInertia from nullable SlugSquareInches. + /// + public static MassMomentOfInertia? FromSlugSquareInches(QuantityValue? slugsquareinches) + { + return slugsquareinches.HasValue ? FromSlugSquareInches(slugsquareinches.Value) : default(MassMomentOfInertia?); + } + /// /// Get nullable MassMomentOfInertia from nullable TonneSquareCentimeters. /// diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index b9058ba32d..bdaeb0fc62 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -2406,6 +2406,11 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "short tn"), new AbbreviationsForCulture("ru-RU", "тонна малая"), }), + new CulturesForEnumValue((int) MassUnit.Slug, + new[] + { + new AbbreviationsForCulture("en-US", "slug"), + }), new CulturesForEnumValue((int) MassUnit.Stone, new[] { @@ -2625,6 +2630,16 @@ private static readonly ReadOnlyCollection DefaultLocalization { new AbbreviationsForCulture("en-US", "lb·in²"), }), + new CulturesForEnumValue((int) MassMomentOfInertiaUnit.SlugSquareFoot, + new[] + { + new AbbreviationsForCulture("en-US", "slug·ft²"), + }), + new CulturesForEnumValue((int) MassMomentOfInertiaUnit.SlugSquareInch, + new[] + { + new AbbreviationsForCulture("en-US", "slug·in²"), + }), new CulturesForEnumValue((int) MassMomentOfInertiaUnit.TonneSquareCentimeter, new[] { diff --git a/UnitsNet/GeneratedCode/Units/MassMomentOfInertiaUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassMomentOfInertiaUnit.g.cs index 070a629261..8e6271e512 100644 --- a/UnitsNet/GeneratedCode/Units/MassMomentOfInertiaUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MassMomentOfInertiaUnit.g.cs @@ -64,6 +64,8 @@ public enum MassMomentOfInertiaUnit MilligramSquareMillimeter, PoundSquareFoot, PoundSquareInch, + SlugSquareFoot, + SlugSquareInch, TonneSquareCentimeter, TonneSquareDecimeter, TonneSquareMeter, diff --git a/UnitsNet/GeneratedCode/Units/MassUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassUnit.g.cs index 9de4746bcf..ac0557b599 100644 --- a/UnitsNet/GeneratedCode/Units/MassUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MassUnit.g.cs @@ -91,6 +91,12 @@ public enum MassUnit /// http://en.wikipedia.org/wiki/Short_ton ShortTon, + /// + /// The slug (abbreviation slug) is a unit of mass that is accelerated by 1 ft/s² when a force of one pound (lbf) is exerted on it. + /// + /// http://en.wikipedia.org/wiki/Slug_(unit) + Slug, + /// /// The stone (abbreviation st) is a unit of mass equal to 14 pounds avoirdupois (about 6.35 kilograms) used in Great Britain and Ireland for measuring human body weight. /// From 69cb0f6694eedc00179952296d378e68e99b60ef Mon Sep 17 00:00:00 2001 From: Neil McNeight Date: Mon, 4 Sep 2023 00:49:19 -0400 Subject: [PATCH 3/3] WIP Initial attempt at removing ElectricPotentialAc and ElectricPotentialDc and replacing them with a Reference type for ElectricPotential. Reference type initially implemented for ElectricCurrent. --- .../UnitDefinitions/ElectricPotentialAc.json | 20 - .../UnitDefinitions/ElectricPotentialDc.json | 20 - .../ElectricPotentialAc.nfproj | 42 - ...t.NanoFramework.ElectricPotentialAc.nuspec | 26 - .../ElectricPotentialAc/packages.config | 4 - .../ElectricPotentialDc.nfproj | 42 - ...t.NanoFramework.ElectricPotentialDc.nuspec | 26 - .../ElectricPotentialDc/packages.config | 4 - .../GeneratedCode/UnitsNet.nanoFramework.sln | 16 - ...NumberToElectricPotentialAcExtensions.g.cs | 76 -- ...NumberToElectricPotentialDcExtensions.g.cs | 76 -- .../CustomCode/ElectricPotentialAcTests.cs | 41 - .../CustomCode/ElectricPotentialDcTests.cs | 41 - .../GeneratedCode/IQuantityTests.g.cs | 6 - .../ElectricPotentialAcTestsBase.g.cs | 757 ------------ .../ElectricPotentialDcTestsBase.g.cs | 757 ------------ UnitsNet/CustomCode/Quantities/Power.extra.cs | 2 +- .../Units/ElectricCurrentFlowReference.cs} | 17 +- .../Wrappers/ElectricCurrentFlow.cs | 203 ++++ .../Quantities/ElectricPotentialAc.g.cs | 1010 ----------------- .../Quantities/ElectricPotentialDc.g.cs | 1010 ----------------- UnitsNet/GeneratedCode/Quantity.g.cs | 10 - .../Resources/ElectricPotentialAc.restext | 5 - .../Resources/ElectricPotentialDc.restext | 5 - .../Units/ElectricPotentialDcUnit.g.cs | 36 - UnitsNet/UnitsNet.csproj | 5 + 26 files changed, 216 insertions(+), 4041 deletions(-) delete mode 100644 Common/UnitDefinitions/ElectricPotentialAc.json delete mode 100644 Common/UnitDefinitions/ElectricPotentialDc.json delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/ElectricPotentialAc.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/UnitsNet.NanoFramework.ElectricPotentialAc.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/packages.config delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/ElectricPotentialDc.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/UnitsNet.NanoFramework.ElectricPotentialDc.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/packages.config delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialDcExtensions.g.cs delete mode 100644 UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs rename UnitsNet/{GeneratedCode/Units/ElectricPotentialAcUnit.g.cs => CustomCode/Units/ElectricCurrentFlowReference.cs} (78%) create mode 100644 UnitsNet/CustomCode/Wrappers/ElectricCurrentFlow.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs delete mode 100644 UnitsNet/GeneratedCode/Resources/ElectricPotentialAc.restext delete mode 100644 UnitsNet/GeneratedCode/Resources/ElectricPotentialDc.restext delete mode 100644 UnitsNet/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs diff --git a/Common/UnitDefinitions/ElectricPotentialAc.json b/Common/UnitDefinitions/ElectricPotentialAc.json deleted file mode 100644 index 4fd5eb435d..0000000000 --- a/Common/UnitDefinitions/ElectricPotentialAc.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Name": "ElectricPotentialAc", - "BaseUnit": "VoltAc", - "XmlDocSummary": "The Electric Potential of a system known to use Alternating Current.", - "Units": [ - { - "SingularName": "VoltAc", - "PluralName": "VoltsAc", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "Vac" ] - } - ] - } - ] -} diff --git a/Common/UnitDefinitions/ElectricPotentialDc.json b/Common/UnitDefinitions/ElectricPotentialDc.json deleted file mode 100644 index 734ac8bf70..0000000000 --- a/Common/UnitDefinitions/ElectricPotentialDc.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Name": "ElectricPotentialDc", - "BaseUnit": "VoltDc", - "XmlDocSummary": "The Electric Potential of a system known to use Direct Current.", - "Units": [ - { - "SingularName": "VoltDc", - "PluralName": "VoltsDc", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "Vdc" ] - } - ] - } - ] -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/ElectricPotentialAc.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/ElectricPotentialAc.nfproj deleted file mode 100644 index a31f9444b5..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/ElectricPotentialAc.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {ab1339ec-f1d8-6abf-093e-1525ee231a9d} - Library - Properties - 512 - UnitsNet - UnitsNet.ElectricPotentialAc - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/UnitsNet.NanoFramework.ElectricPotentialAc.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/UnitsNet.NanoFramework.ElectricPotentialAc.nuspec deleted file mode 100644 index 9d8f98b913..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/UnitsNet.NanoFramework.ElectricPotentialAc.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ElectricPotentialAc - 5.31.0 - Units.NET ElectricPotentialAc - nanoFramework - Andreas Gullberg Larsen,nanoFramework project contributors - UnitsNet - MIT - https://github.com/angularsen/UnitsNet - false - Adds ElectricPotentialAc units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead. - https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png - - - Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). - en-US - nanoframework electricpotentialac unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/packages.config deleted file mode 100644 index faccd72a98..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/ElectricPotentialDc.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/ElectricPotentialDc.nfproj deleted file mode 100644 index 9e7a33f6bf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/ElectricPotentialDc.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {27ebf863-3ee7-ddb0-08ab-8577438a8f1c} - Library - Properties - 512 - UnitsNet - UnitsNet.ElectricPotentialDc - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/UnitsNet.NanoFramework.ElectricPotentialDc.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/UnitsNet.NanoFramework.ElectricPotentialDc.nuspec deleted file mode 100644 index fa8c835b11..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/UnitsNet.NanoFramework.ElectricPotentialDc.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ElectricPotentialDc - 5.31.0 - Units.NET ElectricPotentialDc - nanoFramework - Andreas Gullberg Larsen,nanoFramework project contributors - UnitsNet - MIT - https://github.com/angularsen/UnitsNet - false - Adds ElectricPotentialDc units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead. - https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png - - - Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). - en-US - nanoframework electricpotentialdc unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/packages.config deleted file mode 100644 index faccd72a98..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index f89c957a9e..a74a8d2137 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -60,12 +60,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricInductance", "Elect EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricPotential", "ElectricPotential\ElectricPotential.nfproj", "{66c94dc2-e546-9737-a45b-4bc60fe0e536}" EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricPotentialAc", "ElectricPotentialAc\ElectricPotentialAc.nfproj", "{ab1339ec-f1d8-6abf-093e-1525ee231a9d}" -EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricPotentialChangeRate", "ElectricPotentialChangeRate\ElectricPotentialChangeRate.nfproj", "{679517ca-9d0b-0ec2-35ae-95230281cfba}" EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricPotentialDc", "ElectricPotentialDc\ElectricPotentialDc.nfproj", "{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}" -EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricResistance", "ElectricResistance\ElectricResistance.nfproj", "{78d59e90-3339-54d6-3803-f68623b72eff}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricResistivity", "ElectricResistivity\ElectricResistivity.nfproj", "{6a4a0f45-c2b4-6be4-e44a-e78d3282359f}" @@ -422,24 +418,12 @@ Global {66c94dc2-e546-9737-a45b-4bc60fe0e536}.Release|Any CPU.ActiveCfg = Release|Any CPU {66c94dc2-e546-9737-a45b-4bc60fe0e536}.Release|Any CPU.Build.0 = Release|Any CPU {66c94dc2-e546-9737-a45b-4bc60fe0e536}.Release|Any CPU.Deploy.0 = Release|Any CPU -{ab1339ec-f1d8-6abf-093e-1525ee231a9d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{ab1339ec-f1d8-6abf-093e-1525ee231a9d}.Debug|Any CPU.Build.0 = Debug|Any CPU -{ab1339ec-f1d8-6abf-093e-1525ee231a9d}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{ab1339ec-f1d8-6abf-093e-1525ee231a9d}.Release|Any CPU.ActiveCfg = Release|Any CPU -{ab1339ec-f1d8-6abf-093e-1525ee231a9d}.Release|Any CPU.Build.0 = Release|Any CPU -{ab1339ec-f1d8-6abf-093e-1525ee231a9d}.Release|Any CPU.Deploy.0 = Release|Any CPU {679517ca-9d0b-0ec2-35ae-95230281cfba}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {679517ca-9d0b-0ec2-35ae-95230281cfba}.Debug|Any CPU.Build.0 = Debug|Any CPU {679517ca-9d0b-0ec2-35ae-95230281cfba}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {679517ca-9d0b-0ec2-35ae-95230281cfba}.Release|Any CPU.ActiveCfg = Release|Any CPU {679517ca-9d0b-0ec2-35ae-95230281cfba}.Release|Any CPU.Build.0 = Release|Any CPU {679517ca-9d0b-0ec2-35ae-95230281cfba}.Release|Any CPU.Deploy.0 = Release|Any CPU -{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}.Debug|Any CPU.Build.0 = Debug|Any CPU -{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}.Release|Any CPU.ActiveCfg = Release|Any CPU -{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}.Release|Any CPU.Build.0 = Release|Any CPU -{27ebf863-3ee7-ddb0-08ab-8577438a8f1c}.Release|Any CPU.Deploy.0 = Release|Any CPU {78d59e90-3339-54d6-3803-f68623b72eff}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {78d59e90-3339-54d6-3803-f68623b72eff}.Debug|Any CPU.Build.0 = Debug|Any CPU {78d59e90-3339-54d6-3803-f68623b72eff}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs deleted file mode 100644 index 24cb4db585..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; - -#if NET7_0_OR_GREATER -using System.Numerics; -#endif - -#nullable enable - -namespace UnitsNet.NumberExtensions.NumberToElectricPotentialAc -{ - /// - /// A number to ElectricPotentialAc Extensions - /// - public static class NumberToElectricPotentialAcExtensions - { - /// - public static ElectricPotentialAc KilovoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromKilovoltsAc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialAc MegavoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromMegavoltsAc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialAc MicrovoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromMicrovoltsAc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialAc MillivoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromMillivoltsAc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialAc VoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromVoltsAc(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialDcExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialDcExtensions.g.cs deleted file mode 100644 index 62ab533375..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialDcExtensions.g.cs +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; - -#if NET7_0_OR_GREATER -using System.Numerics; -#endif - -#nullable enable - -namespace UnitsNet.NumberExtensions.NumberToElectricPotentialDc -{ - /// - /// A number to ElectricPotentialDc Extensions - /// - public static class NumberToElectricPotentialDcExtensions - { - /// - public static ElectricPotentialDc KilovoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromKilovoltsDc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialDc MegavoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromMegavoltsDc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialDc MicrovoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromMicrovoltsDc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialDc MillivoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromMillivoltsDc(Convert.ToDouble(value)); - - /// - public static ElectricPotentialDc VoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromVoltsDc(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs deleted file mode 100644 index b001ca7f65..0000000000 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs +++ /dev/null @@ -1,41 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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 unit class 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\UnitClasses\MyQuantity.extra.cs files to add code to generated unit classes. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or unit classes. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - - -using System; - -namespace UnitsNet.Tests.CustomCode -{ - public class ElectricPotentialAcTests : ElectricPotentialAcTestsBase - { - protected override bool SupportsSIUnitSystem => false; - protected override double KilovoltsAcInOneVoltAc => 1e-3; - - protected override double MegavoltsAcInOneVoltAc => 1e-6; - - protected override double MicrovoltsAcInOneVoltAc => 1e+6; - - protected override double MillivoltsAcInOneVoltAc => 1000; - - protected override double VoltsAcInOneVoltAc => 1; - } -} diff --git a/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs b/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs deleted file mode 100644 index 9fa9db32c6..0000000000 --- a/UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs +++ /dev/null @@ -1,41 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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 unit class 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\UnitClasses\MyQuantity.extra.cs files to add code to generated unit classes. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or unit classes. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - - -using System; - -namespace UnitsNet.Tests.CustomCode -{ - public class ElectricPotentialDcTests : ElectricPotentialDcTestsBase - { - protected override bool SupportsSIUnitSystem => false; - protected override double KilovoltsDcInOneVoltDc => 1e-3; - - protected override double MegavoltsDcInOneVoltDc => 1e-6; - - protected override double MicrovoltsDcInOneVoltDc => 1e+6; - - protected override double MillivoltsDcInOneVoltDc => 1000; - - protected override double VoltsDcInOneVoltDc => 1; - } -} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 50b1767879..6a424ff056 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -63,9 +63,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, ElectricFieldUnit.VoltPerMeter, Quantity.From(3, ElectricFieldUnit.VoltPerMeter)); Assertion(3, ElectricInductanceUnit.Picohenry, Quantity.From(3, ElectricInductanceUnit.Picohenry)); Assertion(3, ElectricPotentialUnit.Volt, Quantity.From(3, ElectricPotentialUnit.Volt)); - Assertion(3, ElectricPotentialAcUnit.VoltAc, Quantity.From(3, ElectricPotentialAcUnit.VoltAc)); Assertion(3, ElectricPotentialChangeRateUnit.VoltPerSecond, Quantity.From(3, ElectricPotentialChangeRateUnit.VoltPerSecond)); - Assertion(3, ElectricPotentialDcUnit.VoltDc, Quantity.From(3, ElectricPotentialDcUnit.VoltDc)); Assertion(3, ElectricResistanceUnit.Teraohm, Quantity.From(3, ElectricResistanceUnit.Teraohm)); Assertion(3, ElectricResistivityUnit.PicoohmMeter, Quantity.From(3, ElectricResistivityUnit.PicoohmMeter)); Assertion(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, Quantity.From(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)); @@ -190,9 +188,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(ElectricField.Info, ElectricField.Zero); Assertion(ElectricInductance.Info, ElectricInductance.Zero); Assertion(ElectricPotential.Info, ElectricPotential.Zero); - Assertion(ElectricPotentialAc.Info, ElectricPotentialAc.Zero); Assertion(ElectricPotentialChangeRate.Info, ElectricPotentialChangeRate.Zero); - Assertion(ElectricPotentialDc.Info, ElectricPotentialDc.Zero); Assertion(ElectricResistance.Info, ElectricResistance.Zero); Assertion(ElectricResistivity.Info, ElectricResistivity.Zero); Assertion(ElectricSurfaceChargeDensity.Info, ElectricSurfaceChargeDensity.Zero); @@ -317,9 +313,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(ElectricField.BaseDimensions, ElectricField.Zero); Assertion(ElectricInductance.BaseDimensions, ElectricInductance.Zero); Assertion(ElectricPotential.BaseDimensions, ElectricPotential.Zero); - Assertion(ElectricPotentialAc.BaseDimensions, ElectricPotentialAc.Zero); Assertion(ElectricPotentialChangeRate.BaseDimensions, ElectricPotentialChangeRate.Zero); - Assertion(ElectricPotentialDc.BaseDimensions, ElectricPotentialDc.Zero); Assertion(ElectricResistance.BaseDimensions, ElectricResistance.Zero); Assertion(ElectricResistivity.BaseDimensions, ElectricResistivity.Zero); Assertion(ElectricSurfaceChargeDensity.BaseDimensions, ElectricSurfaceChargeDensity.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs deleted file mode 100644 index d1219793c5..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs +++ /dev/null @@ -1,757 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading; -using UnitsNet.Tests.TestsBase; -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 ElectricPotentialAc. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialAcTestsBase : QuantityTestsBase - { - protected abstract double KilovoltsAcInOneVoltAc { get; } - protected abstract double MegavoltsAcInOneVoltAc { get; } - protected abstract double MicrovoltsAcInOneVoltAc { get; } - protected abstract double MillivoltsAcInOneVoltAc { get; } - protected abstract double VoltsAcInOneVoltAc { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltsAcTolerance { get { return 1e-5; } } - protected virtual double MegavoltsAcTolerance { get { return 1e-5; } } - protected virtual double MicrovoltsAcTolerance { get { return 1e-5; } } - protected virtual double MillivoltsAcTolerance { get { return 1e-5; } } - protected virtual double VoltsAcTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricPotentialAcUnit unit) - { - return unit switch - { - ElectricPotentialAcUnit.KilovoltAc => (KilovoltsAcInOneVoltAc, KilovoltsAcTolerance), - ElectricPotentialAcUnit.MegavoltAc => (MegavoltsAcInOneVoltAc, MegavoltsAcTolerance), - ElectricPotentialAcUnit.MicrovoltAc => (MicrovoltsAcInOneVoltAc, MicrovoltsAcTolerance), - ElectricPotentialAcUnit.MillivoltAc => (MillivoltsAcInOneVoltAc, MillivoltsAcTolerance), - ElectricPotentialAcUnit.VoltAc => (VoltsAcInOneVoltAc, VoltsAcTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { ElectricPotentialAcUnit.KilovoltAc }, - new object[] { ElectricPotentialAcUnit.MegavoltAc }, - new object[] { ElectricPotentialAcUnit.MicrovoltAc }, - new object[] { ElectricPotentialAcUnit.MillivoltAc }, - new object[] { ElectricPotentialAcUnit.VoltAc }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new ElectricPotentialAc(); - Assert.Equal(0, quantity.Value); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialAc(double.PositiveInfinity, ElectricPotentialAcUnit.VoltAc)); - Assert.Throws(() => new ElectricPotentialAc(double.NegativeInfinity, ElectricPotentialAcUnit.VoltAc)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialAc(double.NaN, ElectricPotentialAcUnit.VoltAc)); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new ElectricPotentialAc(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new ElectricPotentialAc(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricPotentialAc) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void ElectricPotentialAc_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new ElectricPotentialAc(1, ElectricPotentialAcUnit.VoltAc); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(ElectricPotentialAc.Zero, quantityInfo.Zero); - Assert.Equal("ElectricPotentialAc", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void VoltAcToElectricPotentialAcUnits() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(KilovoltsAcInOneVoltAc, voltac.KilovoltsAc, KilovoltsAcTolerance); - AssertEx.EqualTolerance(MegavoltsAcInOneVoltAc, voltac.MegavoltsAc, MegavoltsAcTolerance); - AssertEx.EqualTolerance(MicrovoltsAcInOneVoltAc, voltac.MicrovoltsAc, MicrovoltsAcTolerance); - AssertEx.EqualTolerance(MillivoltsAcInOneVoltAc, voltac.MillivoltsAc, MillivoltsAcTolerance); - AssertEx.EqualTolerance(VoltsAcInOneVoltAc, voltac.VoltsAc, VoltsAcTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = ElectricPotentialAc.From(1, ElectricPotentialAcUnit.KilovoltAc); - AssertEx.EqualTolerance(1, quantity00.KilovoltsAc, KilovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, quantity00.Unit); - - var quantity01 = ElectricPotentialAc.From(1, ElectricPotentialAcUnit.MegavoltAc); - AssertEx.EqualTolerance(1, quantity01.MegavoltsAc, MegavoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MegavoltAc, quantity01.Unit); - - var quantity02 = ElectricPotentialAc.From(1, ElectricPotentialAcUnit.MicrovoltAc); - AssertEx.EqualTolerance(1, quantity02.MicrovoltsAc, MicrovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, quantity02.Unit); - - var quantity03 = ElectricPotentialAc.From(1, ElectricPotentialAcUnit.MillivoltAc); - AssertEx.EqualTolerance(1, quantity03.MillivoltsAc, MillivoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MillivoltAc, quantity03.Unit); - - var quantity04 = ElectricPotentialAc.From(1, ElectricPotentialAcUnit.VoltAc); - AssertEx.EqualTolerance(1, quantity04.VoltsAc, VoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, quantity04.Unit); - - } - - [Fact] - public void FromVoltsAc_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialAc.FromVoltsAc(double.PositiveInfinity)); - Assert.Throws(() => ElectricPotentialAc.FromVoltsAc(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltsAc_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialAc.FromVoltsAc(double.NaN)); - } - - [Fact] - public void As() - { - var voltac = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(KilovoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.KilovoltAc), KilovoltsAcTolerance); - AssertEx.EqualTolerance(MegavoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.MegavoltAc), MegavoltsAcTolerance); - AssertEx.EqualTolerance(MicrovoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.MicrovoltAc), MicrovoltsAcTolerance); - AssertEx.EqualTolerance(MillivoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.MillivoltAc), MillivoltsAcTolerance); - AssertEx.EqualTolerance(VoltsAcInOneVoltAc, voltac.As(ElectricPotentialAcUnit.VoltAc), VoltsAcTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new ElectricPotentialAc(value: 1, unit: ElectricPotentialAc.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); - - if (SupportsSIUnitSystem) - { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else - { - Assert.Throws(AsWithSIUnitSystem); - } - } - - [Fact] - public void Parse() - { - try - { - var parsed = ElectricPotentialAc.Parse("1 kVac", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltsAc, KilovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialAc.Parse("1 MVac", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltsAc, MegavoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MegavoltAc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialAc.Parse("1 µVac", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrovoltsAc, MicrovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialAc.Parse("1 mVac", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillivoltsAc, MillivoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MillivoltAc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialAc.Parse("1 Vac", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsAc, VoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(ElectricPotentialAc.TryParse("1 kVac", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltsAc, KilovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, parsed.Unit); - } - - { - Assert.True(ElectricPotentialAc.TryParse("1 µVac", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrovoltsAc, MicrovoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, parsed.Unit); - } - - { - Assert.True(ElectricPotentialAc.TryParse("1 Vac", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsAc, VoltsAcTolerance); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, parsed.Unit); - } - - } - - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("kVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("MVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.MegavoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("µVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("mVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.MillivoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("Vac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParseUnit() - { - { - Assert.True(ElectricPotentialAc.TryParseUnit("kVac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, parsedUnit); - } - - { - Assert.True(ElectricPotentialAc.TryParseUnit("µVac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, parsedUnit); - } - - { - Assert.True(ElectricPotentialAc.TryParseUnit("Vac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, parsedUnit); - } - - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(ElectricPotentialAcUnit unit) - { - var inBaseUnits = ElectricPotentialAc.From(1.0, ElectricPotentialAc.BaseUnit); - var converted = inBaseUnits.ToUnit(unit); - - var conversionFactor = GetConversionFactor(unit); - AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, converted.Value, conversionFactor.Tolerence); - Assert.Equal(unit, converted.Unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_WithSameUnits_AreEqual(ElectricPotentialAcUnit unit) - { - var quantity = ElectricPotentialAc.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricPotentialAcUnit unit) - { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricPotentialAc.Units.First(u => u != ElectricPotentialAc.BaseUnit); - - var quantity = ElectricPotentialAc.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricPotentialAcUnit unit) - { - var quantity = default(ElectricPotentialAc); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromKilovoltsAc(voltac.KilovoltsAc).VoltsAc, KilovoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromMegavoltsAc(voltac.MegavoltsAc).VoltsAc, MegavoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromMicrovoltsAc(voltac.MicrovoltsAc).VoltsAc, MicrovoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromMillivoltsAc(voltac.MillivoltsAc).VoltsAc, MillivoltsAcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialAc.FromVoltsAc(voltac.VoltsAc).VoltsAc, VoltsAcTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricPotentialAc v = ElectricPotentialAc.FromVoltsAc(1); - AssertEx.EqualTolerance(-1, -v.VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialAc.FromVoltsAc(3)-v).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialAc.FromVoltsAc(10)/5).VoltsAc, VoltsAcTolerance); - AssertEx.EqualTolerance(2, ElectricPotentialAc.FromVoltsAc(10)/ElectricPotentialAc.FromVoltsAc(5), VoltsAcTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricPotentialAc oneVoltAc = ElectricPotentialAc.FromVoltsAc(1); - ElectricPotentialAc twoVoltsAc = ElectricPotentialAc.FromVoltsAc(2); - - Assert.True(oneVoltAc < twoVoltsAc); - Assert.True(oneVoltAc <= twoVoltsAc); - Assert.True(twoVoltsAc > oneVoltAc); - Assert.True(twoVoltsAc >= oneVoltAc); - - Assert.False(oneVoltAc > twoVoltsAc); - Assert.False(oneVoltAc >= twoVoltsAc); - Assert.False(twoVoltsAc < oneVoltAc); - Assert.False(twoVoltsAc <= oneVoltAc); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.Equal(0, voltac.CompareTo(voltac)); - Assert.True(voltac.CompareTo(ElectricPotentialAc.Zero) > 0); - Assert.True(ElectricPotentialAc.Zero.CompareTo(voltac) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.Throws(() => voltac.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.Throws(() => voltac.CompareTo(null)); - } - - [Theory] - [InlineData(1, ElectricPotentialAcUnit.VoltAc, 1, ElectricPotentialAcUnit.VoltAc, true)] // Same value and unit. - [InlineData(1, ElectricPotentialAcUnit.VoltAc, 2, ElectricPotentialAcUnit.VoltAc, false)] // Different value. - [InlineData(2, ElectricPotentialAcUnit.VoltAc, 1, ElectricPotentialAcUnit.KilovoltAc, false)] // Different value and unit. - [InlineData(1, ElectricPotentialAcUnit.VoltAc, 1, ElectricPotentialAcUnit.KilovoltAc, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricPotentialAcUnit unitA, double valueB, ElectricPotentialAcUnit unitB, bool expectEqual) - { - var a = new ElectricPotentialAc(valueA, unitA); - var b = new ElectricPotentialAc(valueB, unitB); - - // Operator overloads. - Assert.Equal(expectEqual, a == b); - Assert.Equal(expectEqual, b == a); - Assert.Equal(!expectEqual, a != b); - Assert.Equal(!expectEqual, b != a); - - // IEquatable - Assert.Equal(expectEqual, a.Equals(b)); - Assert.Equal(expectEqual, b.Equals(a)); - - // IEquatable - Assert.Equal(expectEqual, a.Equals((object)b)); - Assert.Equal(expectEqual, b.Equals((object)a)); - } - - [Fact] - public void Equals_Null_ReturnsFalse() - { - var a = ElectricPotentialAc.Zero; - - Assert.False(a.Equals((object)null)); - - // "The result of the expression is always 'false'..." - #pragma warning disable CS8073 - Assert.False(a == null); - Assert.False(null == a); - Assert.True(a != null); - Assert.True(null != a); - #pragma warning restore CS8073 - } - - [Fact] - public void Equals_RelativeTolerance_IsImplemented() - { - var v = ElectricPotentialAc.FromVoltsAc(1); - Assert.True(v.Equals(ElectricPotentialAc.FromVoltsAc(1), VoltsAcTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricPotentialAc.Zero, VoltsAcTolerance, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = ElectricPotentialAc.FromVoltsAc(1); - Assert.Throws(() => v.Equals(ElectricPotentialAc.FromVoltsAc(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.False(voltac.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricPotentialAc voltac = ElectricPotentialAc.FromVoltsAc(1); - Assert.False(voltac.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricPotentialAcUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ElectricPotentialAc.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - var prevCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); - try { - Assert.Equal("1 kVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.KilovoltAc).ToString()); - Assert.Equal("1 MVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.MegavoltAc).ToString()); - Assert.Equal("1 µVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.MicrovoltAc).ToString()); - Assert.Equal("1 mVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.MillivoltAc).ToString()); - Assert.Equal("1 Vac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.VoltAc).ToString()); - } - finally - { - Thread.CurrentThread.CurrentCulture = prevCulture; - } - } - - [Fact] - public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() - { - // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. - var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); - - Assert.Equal("1 kVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.KilovoltAc).ToString(swedishCulture)); - Assert.Equal("1 MVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.MegavoltAc).ToString(swedishCulture)); - Assert.Equal("1 µVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.MicrovoltAc).ToString(swedishCulture)); - Assert.Equal("1 mVac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.MillivoltAc).ToString(swedishCulture)); - Assert.Equal("1 Vac", new ElectricPotentialAc(1, ElectricPotentialAcUnit.VoltAc).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var oldCulture = CultureInfo.CurrentCulture; - try - { - CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s1")); - Assert.Equal("0.12 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s2")); - Assert.Equal("0.123 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s3")); - Assert.Equal("0.1235 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s4")); - } - finally - { - CultureInfo.CurrentCulture = oldCulture; - } - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s1", culture)); - Assert.Equal("0.12 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s2", culture)); - Assert.Equal("0.123 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s3", culture)); - Assert.Equal("0.1235 Vac", new ElectricPotentialAc(0.123456, ElectricPotentialAcUnit.VoltAc).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - CultureInfo formatProvider = cultureName == null - ? null - : CultureInfo.GetCultureInfo(cultureName); - - Assert.Equal(quantity.ToString("g", formatProvider), quantity.ToString(null, formatProvider)); - } - - [Theory] - [InlineData(null)] - [InlineData("g")] - public void ToString_NullProvider_EqualsCurrentCulture(string format) - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricPotentialAc))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricPotentialAcUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(ElectricPotentialAc.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(ElectricPotentialAc.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = ElectricPotentialAc.FromVoltsAc(1.0); - Assert.Equal(new {ElectricPotentialAc.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); - } - - [Theory] - [InlineData(1.0)] - [InlineData(-1.0)] - public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) - { - var quantity = ElectricPotentialAc.FromVoltsAc(value); - Assert.Equal(ElectricPotentialAc.FromVoltsAc(-value), -quantity); - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs deleted file mode 100644 index 15669faa28..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs +++ /dev/null @@ -1,757 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading; -using UnitsNet.Tests.TestsBase; -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 ElectricPotentialDc. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ElectricPotentialDcTestsBase : QuantityTestsBase - { - protected abstract double KilovoltsDcInOneVoltDc { get; } - protected abstract double MegavoltsDcInOneVoltDc { get; } - protected abstract double MicrovoltsDcInOneVoltDc { get; } - protected abstract double MillivoltsDcInOneVoltDc { get; } - protected abstract double VoltsDcInOneVoltDc { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltsDcTolerance { get { return 1e-5; } } - protected virtual double MegavoltsDcTolerance { get { return 1e-5; } } - protected virtual double MicrovoltsDcTolerance { get { return 1e-5; } } - protected virtual double MillivoltsDcTolerance { get { return 1e-5; } } - protected virtual double VoltsDcTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricPotentialDcUnit unit) - { - return unit switch - { - ElectricPotentialDcUnit.KilovoltDc => (KilovoltsDcInOneVoltDc, KilovoltsDcTolerance), - ElectricPotentialDcUnit.MegavoltDc => (MegavoltsDcInOneVoltDc, MegavoltsDcTolerance), - ElectricPotentialDcUnit.MicrovoltDc => (MicrovoltsDcInOneVoltDc, MicrovoltsDcTolerance), - ElectricPotentialDcUnit.MillivoltDc => (MillivoltsDcInOneVoltDc, MillivoltsDcTolerance), - ElectricPotentialDcUnit.VoltDc => (VoltsDcInOneVoltDc, VoltsDcTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { ElectricPotentialDcUnit.KilovoltDc }, - new object[] { ElectricPotentialDcUnit.MegavoltDc }, - new object[] { ElectricPotentialDcUnit.MicrovoltDc }, - new object[] { ElectricPotentialDcUnit.MillivoltDc }, - new object[] { ElectricPotentialDcUnit.VoltDc }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new ElectricPotentialDc(); - Assert.Equal(0, quantity.Value); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialDc(double.PositiveInfinity, ElectricPotentialDcUnit.VoltDc)); - Assert.Throws(() => new ElectricPotentialDc(double.NegativeInfinity, ElectricPotentialDcUnit.VoltDc)); - } - - [Fact] - public void Ctor_WithNaNValue_ThrowsArgumentException() - { - Assert.Throws(() => new ElectricPotentialDc(double.NaN, ElectricPotentialDcUnit.VoltDc)); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new ElectricPotentialDc(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new ElectricPotentialDc(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ElectricPotentialDc) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void ElectricPotentialDc_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new ElectricPotentialDc(1, ElectricPotentialDcUnit.VoltDc); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(ElectricPotentialDc.Zero, quantityInfo.Zero); - Assert.Equal("ElectricPotentialDc", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void VoltDcToElectricPotentialDcUnits() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(KilovoltsDcInOneVoltDc, voltdc.KilovoltsDc, KilovoltsDcTolerance); - AssertEx.EqualTolerance(MegavoltsDcInOneVoltDc, voltdc.MegavoltsDc, MegavoltsDcTolerance); - AssertEx.EqualTolerance(MicrovoltsDcInOneVoltDc, voltdc.MicrovoltsDc, MicrovoltsDcTolerance); - AssertEx.EqualTolerance(MillivoltsDcInOneVoltDc, voltdc.MillivoltsDc, MillivoltsDcTolerance); - AssertEx.EqualTolerance(VoltsDcInOneVoltDc, voltdc.VoltsDc, VoltsDcTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = ElectricPotentialDc.From(1, ElectricPotentialDcUnit.KilovoltDc); - AssertEx.EqualTolerance(1, quantity00.KilovoltsDc, KilovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, quantity00.Unit); - - var quantity01 = ElectricPotentialDc.From(1, ElectricPotentialDcUnit.MegavoltDc); - AssertEx.EqualTolerance(1, quantity01.MegavoltsDc, MegavoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MegavoltDc, quantity01.Unit); - - var quantity02 = ElectricPotentialDc.From(1, ElectricPotentialDcUnit.MicrovoltDc); - AssertEx.EqualTolerance(1, quantity02.MicrovoltsDc, MicrovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, quantity02.Unit); - - var quantity03 = ElectricPotentialDc.From(1, ElectricPotentialDcUnit.MillivoltDc); - AssertEx.EqualTolerance(1, quantity03.MillivoltsDc, MillivoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MillivoltDc, quantity03.Unit); - - var quantity04 = ElectricPotentialDc.From(1, ElectricPotentialDcUnit.VoltDc); - AssertEx.EqualTolerance(1, quantity04.VoltsDc, VoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, quantity04.Unit); - - } - - [Fact] - public void FromVoltsDc_WithInfinityValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialDc.FromVoltsDc(double.PositiveInfinity)); - Assert.Throws(() => ElectricPotentialDc.FromVoltsDc(double.NegativeInfinity)); - } - - [Fact] - public void FromVoltsDc_WithNanValue_ThrowsArgumentException() - { - Assert.Throws(() => ElectricPotentialDc.FromVoltsDc(double.NaN)); - } - - [Fact] - public void As() - { - var voltdc = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(KilovoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.KilovoltDc), KilovoltsDcTolerance); - AssertEx.EqualTolerance(MegavoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.MegavoltDc), MegavoltsDcTolerance); - AssertEx.EqualTolerance(MicrovoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.MicrovoltDc), MicrovoltsDcTolerance); - AssertEx.EqualTolerance(MillivoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.MillivoltDc), MillivoltsDcTolerance); - AssertEx.EqualTolerance(VoltsDcInOneVoltDc, voltdc.As(ElectricPotentialDcUnit.VoltDc), VoltsDcTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new ElectricPotentialDc(value: 1, unit: ElectricPotentialDc.BaseUnit); - Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); - - if (SupportsSIUnitSystem) - { - var value = Convert.ToDouble(AsWithSIUnitSystem()); - Assert.Equal(1, value); - } - else - { - Assert.Throws(AsWithSIUnitSystem); - } - } - - [Fact] - public void Parse() - { - try - { - var parsed = ElectricPotentialDc.Parse("1 kVdc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltsDc, KilovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialDc.Parse("1 MVdc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltsDc, MegavoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MegavoltDc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialDc.Parse("1 µVdc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MicrovoltsDc, MicrovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialDc.Parse("1 mVdc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MillivoltsDc, MillivoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MillivoltDc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ElectricPotentialDc.Parse("1 Vdc", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltsDc, VoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(ElectricPotentialDc.TryParse("1 kVdc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltsDc, KilovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, parsed.Unit); - } - - { - Assert.True(ElectricPotentialDc.TryParse("1 µVdc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MicrovoltsDc, MicrovoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, parsed.Unit); - } - - { - Assert.True(ElectricPotentialDc.TryParse("1 Vdc", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltsDc, VoltsDcTolerance); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, parsed.Unit); - } - - } - - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("kVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("MVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.MegavoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("µVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("mVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.MillivoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("Vdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParseUnit() - { - { - Assert.True(ElectricPotentialDc.TryParseUnit("kVdc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, parsedUnit); - } - - { - Assert.True(ElectricPotentialDc.TryParseUnit("µVdc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, parsedUnit); - } - - { - Assert.True(ElectricPotentialDc.TryParseUnit("Vdc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, parsedUnit); - } - - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(ElectricPotentialDcUnit unit) - { - var inBaseUnits = ElectricPotentialDc.From(1.0, ElectricPotentialDc.BaseUnit); - var converted = inBaseUnits.ToUnit(unit); - - var conversionFactor = GetConversionFactor(unit); - AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, converted.Value, conversionFactor.Tolerence); - Assert.Equal(unit, converted.Unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_WithSameUnits_AreEqual(ElectricPotentialDcUnit unit) - { - var quantity = ElectricPotentialDc.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricPotentialDcUnit unit) - { - // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. - var fromUnit = ElectricPotentialDc.Units.First(u => u != ElectricPotentialDc.BaseUnit); - - var quantity = ElectricPotentialDc.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricPotentialDcUnit unit) - { - var quantity = default(ElectricPotentialDc); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromKilovoltsDc(voltdc.KilovoltsDc).VoltsDc, KilovoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromMegavoltsDc(voltdc.MegavoltsDc).VoltsDc, MegavoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromMicrovoltsDc(voltdc.MicrovoltsDc).VoltsDc, MicrovoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromMillivoltsDc(voltdc.MillivoltsDc).VoltsDc, MillivoltsDcTolerance); - AssertEx.EqualTolerance(1, ElectricPotentialDc.FromVoltsDc(voltdc.VoltsDc).VoltsDc, VoltsDcTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ElectricPotentialDc v = ElectricPotentialDc.FromVoltsDc(1); - AssertEx.EqualTolerance(-1, -v.VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialDc.FromVoltsDc(3)-v).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, (ElectricPotentialDc.FromVoltsDc(10)/5).VoltsDc, VoltsDcTolerance); - AssertEx.EqualTolerance(2, ElectricPotentialDc.FromVoltsDc(10)/ElectricPotentialDc.FromVoltsDc(5), VoltsDcTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ElectricPotentialDc oneVoltDc = ElectricPotentialDc.FromVoltsDc(1); - ElectricPotentialDc twoVoltsDc = ElectricPotentialDc.FromVoltsDc(2); - - Assert.True(oneVoltDc < twoVoltsDc); - Assert.True(oneVoltDc <= twoVoltsDc); - Assert.True(twoVoltsDc > oneVoltDc); - Assert.True(twoVoltsDc >= oneVoltDc); - - Assert.False(oneVoltDc > twoVoltsDc); - Assert.False(oneVoltDc >= twoVoltsDc); - Assert.False(twoVoltsDc < oneVoltDc); - Assert.False(twoVoltsDc <= oneVoltDc); - } - - [Fact] - public void CompareToIsImplemented() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.Equal(0, voltdc.CompareTo(voltdc)); - Assert.True(voltdc.CompareTo(ElectricPotentialDc.Zero) > 0); - Assert.True(ElectricPotentialDc.Zero.CompareTo(voltdc) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.Throws(() => voltdc.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.Throws(() => voltdc.CompareTo(null)); - } - - [Theory] - [InlineData(1, ElectricPotentialDcUnit.VoltDc, 1, ElectricPotentialDcUnit.VoltDc, true)] // Same value and unit. - [InlineData(1, ElectricPotentialDcUnit.VoltDc, 2, ElectricPotentialDcUnit.VoltDc, false)] // Different value. - [InlineData(2, ElectricPotentialDcUnit.VoltDc, 1, ElectricPotentialDcUnit.KilovoltDc, false)] // Different value and unit. - [InlineData(1, ElectricPotentialDcUnit.VoltDc, 1, ElectricPotentialDcUnit.KilovoltDc, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricPotentialDcUnit unitA, double valueB, ElectricPotentialDcUnit unitB, bool expectEqual) - { - var a = new ElectricPotentialDc(valueA, unitA); - var b = new ElectricPotentialDc(valueB, unitB); - - // Operator overloads. - Assert.Equal(expectEqual, a == b); - Assert.Equal(expectEqual, b == a); - Assert.Equal(!expectEqual, a != b); - Assert.Equal(!expectEqual, b != a); - - // IEquatable - Assert.Equal(expectEqual, a.Equals(b)); - Assert.Equal(expectEqual, b.Equals(a)); - - // IEquatable - Assert.Equal(expectEqual, a.Equals((object)b)); - Assert.Equal(expectEqual, b.Equals((object)a)); - } - - [Fact] - public void Equals_Null_ReturnsFalse() - { - var a = ElectricPotentialDc.Zero; - - Assert.False(a.Equals((object)null)); - - // "The result of the expression is always 'false'..." - #pragma warning disable CS8073 - Assert.False(a == null); - Assert.False(null == a); - Assert.True(a != null); - Assert.True(null != a); - #pragma warning restore CS8073 - } - - [Fact] - public void Equals_RelativeTolerance_IsImplemented() - { - var v = ElectricPotentialDc.FromVoltsDc(1); - Assert.True(v.Equals(ElectricPotentialDc.FromVoltsDc(1), VoltsDcTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ElectricPotentialDc.Zero, VoltsDcTolerance, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = ElectricPotentialDc.FromVoltsDc(1); - Assert.Throws(() => v.Equals(ElectricPotentialDc.FromVoltsDc(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.False(voltdc.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ElectricPotentialDc voltdc = ElectricPotentialDc.FromVoltsDc(1); - Assert.False(voltdc.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ElectricPotentialDcUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ElectricPotentialDc.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - var prevCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); - try { - Assert.Equal("1 kVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.KilovoltDc).ToString()); - Assert.Equal("1 MVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.MegavoltDc).ToString()); - Assert.Equal("1 µVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.MicrovoltDc).ToString()); - Assert.Equal("1 mVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.MillivoltDc).ToString()); - Assert.Equal("1 Vdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.VoltDc).ToString()); - } - finally - { - Thread.CurrentThread.CurrentCulture = prevCulture; - } - } - - [Fact] - public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() - { - // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. - var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); - - Assert.Equal("1 kVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.KilovoltDc).ToString(swedishCulture)); - Assert.Equal("1 MVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.MegavoltDc).ToString(swedishCulture)); - Assert.Equal("1 µVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.MicrovoltDc).ToString(swedishCulture)); - Assert.Equal("1 mVdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.MillivoltDc).ToString(swedishCulture)); - Assert.Equal("1 Vdc", new ElectricPotentialDc(1, ElectricPotentialDcUnit.VoltDc).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var oldCulture = CultureInfo.CurrentCulture; - try - { - CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s1")); - Assert.Equal("0.12 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s2")); - Assert.Equal("0.123 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s3")); - Assert.Equal("0.1235 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s4")); - } - finally - { - CultureInfo.CurrentCulture = oldCulture; - } - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s1", culture)); - Assert.Equal("0.12 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s2", culture)); - Assert.Equal("0.123 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s3", culture)); - Assert.Equal("0.1235 Vdc", new ElectricPotentialDc(0.123456, ElectricPotentialDcUnit.VoltDc).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - CultureInfo formatProvider = cultureName == null - ? null - : CultureInfo.GetCultureInfo(cultureName); - - Assert.Equal(quantity.ToString("g", formatProvider), quantity.ToString(null, formatProvider)); - } - - [Theory] - [InlineData(null)] - [InlineData("g")] - public void ToString_NullProvider_EqualsCurrentCulture(string format) - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricPotentialDc))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricPotentialDcUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(ElectricPotentialDc.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(ElectricPotentialDc.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = ElectricPotentialDc.FromVoltsDc(1.0); - Assert.Equal(new {ElectricPotentialDc.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); - } - - [Theory] - [InlineData(1.0)] - [InlineData(-1.0)] - public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) - { - var quantity = ElectricPotentialDc.FromVoltsDc(value); - Assert.Equal(ElectricPotentialDc.FromVoltsDc(-value), -quantity); - } - } -} diff --git a/UnitsNet/CustomCode/Quantities/Power.extra.cs b/UnitsNet/CustomCode/Quantities/Power.extra.cs index 562192b2f4..605bc940b3 100644 --- a/UnitsNet/CustomCode/Quantities/Power.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Power.extra.cs @@ -101,7 +101,7 @@ public PowerRatio ToPowerRatio() } /// Calculate from divided by . - /// Electric power is defined as P = U * I, so I = P / U. + /// Electric power is defined as P = U * I, so U = P / I. public static ElectricPotential operator /(Power power, ElectricCurrent current) { return ElectricPotential.FromVolts((double)power.Watts / current.Amperes); diff --git a/UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs b/UnitsNet/CustomCode/Units/ElectricCurrentFlowReference.cs similarity index 78% rename from UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs rename to UnitsNet/CustomCode/Units/ElectricCurrentFlowReference.cs index ada8068172..faa498b3ed 100644 --- a/UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs +++ b/UnitsNet/CustomCode/Units/ElectricCurrentFlowReference.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by \generate-code.bat. // @@ -18,19 +18,16 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. // ReSharper disable once CheckNamespace -namespace UnitsNet.Units +namespace UnitsNet.CustomCode.Units { // Disable missing XML comment warnings for the generated unit enums. #pragma warning disable 1591 - public enum ElectricPotentialAcUnit + public enum ElectricCurrentFlowReference { - KilovoltAc = 1, - MegavoltAc = 2, - MicrovoltAc = 3, - MillivoltAc = 4, - VoltAc = 5, + DirectOrRms, + AlternatingPeak, + AlternatingPeakToPeak, } - - #pragma warning restore 1591 +#pragma warning restore 1591 } diff --git a/UnitsNet/CustomCode/Wrappers/ElectricCurrentFlow.cs b/UnitsNet/CustomCode/Wrappers/ElectricCurrentFlow.cs new file mode 100644 index 0000000000..a89cb03d00 --- /dev/null +++ b/UnitsNet/CustomCode/Wrappers/ElectricCurrentFlow.cs @@ -0,0 +1,203 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Linq; + +using UnitsNet.CustomCode.Units; +using UnitsNet.Units; + +namespace UnitsNet.Wrappers +{ + /// + /// The fundamental difference between alternating current (AC) and direct current (DC) is the direction of flow over time. + /// “A simple way to visualize the difference is that, when graphed, a DC current looks like a flat line, whereas the flow of AC on a graph makes a sinusoid or wave-like pattern.” + /// - Karl K. Berggren, professor of electrical engineering at MIT + /// + /// + /// Alternating current changes over time in an oscillating repetition — the up curve indicates the current flowing in a positive direction and the down curve signifies the alternate cycle where the current moves in a negative direction. This back and forth is what gives AC its name. + /// + /// + /// Direct current is constant and moves in one direction. + /// + /// + /// + /// + /// MIT School of Engineering | What’s the difference between AC and DC? + /// + public struct ElectricCurrentFlow + { + /// + /// Represents the frequency at which _current is referenced (0 Hz default) + /// + public Frequency Frequency { get; set; } + + private static readonly Frequency DefaultFrequency = Frequency.Zero; + + /// + /// Gets a list of options: , + /// , and + /// + public static ElectricCurrentFlowReference[] Directions { get; } = + Enum.GetValues(typeof(ElectricCurrentFlowReference)).Cast().ToArray(); + + /// + /// Initializes a new instance of the struct requiring measured + /// + /// parameter. Assumes the to , with 0 Hz as + /// the . + /// + /// The measured absolute + public ElectricCurrentFlow(ElectricCurrent current) : this(current, BaseReference) + { + } + + /// + /// Initializes a new instance of the struct requiring + /// measured and parameters. Assumes 0 Hz as the + /// . + /// + /// The measured + /// + /// The referenced for the measured + /// + public ElectricCurrentFlow(ElectricCurrent current, ElectricCurrentFlowReference reference) : this(current, reference, DefaultFrequency) + { + } + + /// + /// Initializes a new instance of the struct requiring + /// measured , , and + /// parameters + /// + /// The measured + /// + /// The referenced for the measured + /// + /// The of the measurement taken. + public ElectricCurrentFlow(ElectricCurrent current, ElectricCurrentFlowReference reference, Frequency frequency) + { + Current = current; + Reference = reference; + Frequency = frequency; + } + + /// + /// Gets the of the + /// + public ElectricCurrentFlowReference Reference { get; } + + /// + /// The base reference representation of for the numeric value stored internally. All + /// conversions go via this value. + /// + public const ElectricCurrentFlowReference BaseReference = ElectricCurrentFlowReference.DirectOrRms; + + /// + /// The at the given . + /// + /// + /// If the waveform is a pure sine wave, the relationships between amplitudes (peak-to-peak, peak) and RMS are fixed and known, as they are for any continuous periodic wave. + /// + public ElectricCurrent Current { get; } + + /// + /// Get Direct or RMS . + /// For alternating electric current, RMS is equal to the value of the constant direct current that would produce the same power dissipation in a resistive load. + /// + public ElectricCurrent DirectOrRms => As(ElectricCurrentFlowReference.DirectOrRms); + + /// + /// Get Alternating Peak . + /// It is zero-referenced pressure to the perfect vacuum. + /// + public ElectricCurrent AlternatingPeak => As(ElectricCurrentFlowReference.AlternatingPeak); + + /// + /// Get Alternating Peak To Peak . + /// It is a negative Gauge pressure when Absolute pressure is below Atmospheric pressure. + /// + public ElectricCurrent AlternatingPeakToPeak => As(ElectricCurrentFlowReference.AlternatingPeakToPeak); + + /// + /// Converts to at + /// + /// The to convert to. + /// The at the specified + private ElectricCurrent As(ElectricCurrentFlowReference reference) + { + var converted = AsBaseNumericType(reference); + + return new ElectricCurrent(converted, Current.Unit); + } + + /// + /// Converts to at + /// + /// The to convert to. + /// The value of pressure at + private double AsBaseNumericType(ElectricCurrentFlowReference reference) + { + var baseReferenceValue = AsBaseReference(); + + if (Reference == reference) + { + return Current.Value; + } + + switch (reference) + { + case ElectricCurrentFlowReference.DirectOrRms: return baseReferenceValue; + // Vp = Vrms * sqrt(2) + case ElectricCurrentFlowReference.AlternatingPeak: return baseReferenceValue * 1.4142135623730950488016887242097; + // Vp-p = Vrms * (2 * sqrt(2)) + case ElectricCurrentFlowReference.AlternatingPeakToPeak: return baseReferenceValue * 2.8284271247461900976033774484194; + default: + throw new NotImplementedException($"Can not convert {Reference} to {reference}."); + } + } + + /// + /// Converts at to at + /// + /// + /// The value of current at the + private double AsBaseReference() + { + switch (Reference) + { + case ElectricCurrentFlowReference.DirectOrRms: + { + if (Current.Value < 0) + { + throw new ArgumentOutOfRangeException(nameof(Current), "Direct or RMS current cannot be less than zero."); + } + + return Current.Value; + } + case ElectricCurrentFlowReference.AlternatingPeak: + { + if (Current.Value < 0) + { + throw new ArgumentOutOfRangeException(nameof(Current), "Alternating peak current cannot be less than zero."); + } + + // Vrms = (1 / sqrt(2)) * Vp + return Current.Value * 0.70710678118654752440084436210485; + } + case ElectricCurrentFlowReference.AlternatingPeakToPeak: + { + if (Current.Value < 0) + { + throw new ArgumentOutOfRangeException(nameof(Current), "Alternating peak-to-peak current cannot be less than zero."); + } + + // Vrms = (1 / (2 * sqrt(2))) * Vp-p + return Current.Value * 0.35355339059327376220042218105242; + } + default: + throw new NotImplementedException($"Can not convert {Reference} to base reference."); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs deleted file mode 100644 index a03ff4520c..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ /dev/null @@ -1,1010 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.InternalHelpers; -using UnitsNet.Units; - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// The Electric Potential of a system known to use Alternating Current. - /// - [DataContract] - public readonly partial struct ElectricPotentialAc : - IArithmeticQuantity, - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 0)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 1)] - private readonly ElectricPotentialAcUnit? _unit; - - static ElectricPotentialAc() - { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = ElectricPotentialAcUnit.VoltAc; - Units = Enum.GetValues(typeof(ElectricPotentialAcUnit)).Cast().ToArray(); - Zero = new ElectricPotentialAc(0, BaseUnit); - Info = new QuantityInfo("ElectricPotentialAc", - new UnitInfo[] - { - new UnitInfo(ElectricPotentialAcUnit.KilovoltAc, "KilovoltsAc", BaseUnits.Undefined, "ElectricPotentialAc"), - new UnitInfo(ElectricPotentialAcUnit.MegavoltAc, "MegavoltsAc", BaseUnits.Undefined, "ElectricPotentialAc"), - new UnitInfo(ElectricPotentialAcUnit.MicrovoltAc, "MicrovoltsAc", BaseUnits.Undefined, "ElectricPotentialAc"), - new UnitInfo(ElectricPotentialAcUnit.MillivoltAc, "MillivoltsAc", BaseUnits.Undefined, "ElectricPotentialAc"), - new UnitInfo(ElectricPotentialAcUnit.VoltAc, "VoltsAc", BaseUnits.Undefined, "ElectricPotentialAc"), - }, - BaseUnit, Zero, BaseDimensions); - - DefaultConversionFunctions = new UnitConverter(); - RegisterDefaultConversions(DefaultConversionFunctions); - } - - /// - /// Creates the quantity with the given numeric value and unit. - /// - /// The numeric value to construct this quantity with. - /// The unit representation to construct this quantity with. - /// If value is NaN or Infinity. - public ElectricPotentialAc(double value, ElectricPotentialAcUnit unit) - { - _value = Guard.EnsureValidNumber(value, nameof(value)); - _unit = unit; - } - - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public ElectricPotentialAc(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = Guard.EnsureValidNumber(value, nameof(value)); - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - - #region Static Properties - - /// - /// The containing the default generated conversion functions for instances. - /// - public static UnitConverter DefaultConversionFunctions { get; } - - /// - public static QuantityInfo Info { get; } - - /// - /// The of this quantity. - /// - public static BaseDimensions BaseDimensions { get; } - - /// - /// The base unit of ElectricPotentialAc, which is VoltAc. All conversions go via this value. - /// - public static ElectricPotentialAcUnit BaseUnit { get; } - - /// - /// All units of measurement for the ElectricPotentialAc quantity. - /// - public static ElectricPotentialAcUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit VoltAc. - /// - public static ElectricPotentialAc Zero { get; } - - /// - public static ElectricPotentialAc AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - QuantityValue IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public ElectricPotentialAcUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => ElectricPotentialAc.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltsAc => As(ElectricPotentialAcUnit.KilovoltAc); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltsAc => As(ElectricPotentialAcUnit.MegavoltAc); - - /// - /// Gets a value of this quantity converted into - /// - public double MicrovoltsAc => As(ElectricPotentialAcUnit.MicrovoltAc); - - /// - /// Gets a value of this quantity converted into - /// - public double MillivoltsAc => As(ElectricPotentialAcUnit.MillivoltAc); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltsAc => As(ElectricPotentialAcUnit.VoltAc); - - #endregion - - #region Static Methods - - /// - /// Registers the default conversion functions in the given instance. - /// - /// The to register the default conversion functions in. - internal static void RegisterDefaultConversions(UnitConverter unitConverter) - { - // Register in unit converter: ElectricPotentialAcUnit -> BaseUnit - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.KilovoltAc, ElectricPotentialAcUnit.VoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.VoltAc)); - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.MegavoltAc, ElectricPotentialAcUnit.VoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.VoltAc)); - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.MicrovoltAc, ElectricPotentialAcUnit.VoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.VoltAc)); - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.MillivoltAc, ElectricPotentialAcUnit.VoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.VoltAc)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.VoltAc, quantity => quantity); - - // Register in unit converter: BaseUnit -> ElectricPotentialAcUnit - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.KilovoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.KilovoltAc)); - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.MegavoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.MegavoltAc)); - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.MicrovoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.MicrovoltAc)); - unitConverter.SetConversionFunction(ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.MillivoltAc, quantity => quantity.ToUnit(ElectricPotentialAcUnit.MillivoltAc)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(ElectricPotentialAcUnit unit) - { - return GetAbbreviation(unit, null); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricPotentialAcUnit unit, IFormatProvider? provider) - { - return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialAc FromKilovoltsAc(QuantityValue kilovoltsac) - { - double value = (double) kilovoltsac; - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.KilovoltAc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialAc FromMegavoltsAc(QuantityValue megavoltsac) - { - double value = (double) megavoltsac; - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MegavoltAc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialAc FromMicrovoltsAc(QuantityValue microvoltsac) - { - double value = (double) microvoltsac; - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MicrovoltAc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialAc FromMillivoltsAc(QuantityValue millivoltsac) - { - double value = (double) millivoltsac; - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MillivoltAc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialAc FromVoltsAc(QuantityValue voltsac) - { - double value = (double) voltsac; - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.VoltAc); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ElectricPotentialAc unit value. - public static ElectricPotentialAc From(QuantityValue value, ElectricPotentialAcUnit fromUnit) - { - return new ElectricPotentialAc((double)value, fromUnit); - } - - #endregion - - #region Static Parse Methods - - /// - /// Parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("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 ElectricPotentialAc Parse(string str) - { - return Parse(str, null); - } - - /// - /// Parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); - /// - /// The value of 'str' cannot be null. - /// - /// Expected string to have one or two pairs of quantity and unit in the format - /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" - /// - /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . - /// - /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. - /// - /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricPotentialAc Parse(string str, IFormatProvider? provider) - { - return QuantityParser.Default.Parse( - str, - provider, - From); - } - - /// - /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// Resulting unit quantity if successful. - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); - /// - public static bool TryParse(string? str, out ElectricPotentialAc result) - { - return TryParse(str, null, out result); - } - - /// - /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// Resulting unit quantity if successful. - /// True if successful, otherwise false. - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); - /// - /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse(string? str, IFormatProvider? provider, out ElectricPotentialAc result) - { - return QuantityParser.Default.TryParse( - str, - provider, - From, - out result); - } - - /// - /// Parse a unit string. - /// - /// String to parse. Typically in the form: {number} {unit} - /// - /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - /// - /// The value of 'str' cannot be null. - /// Error parsing string. - public static ElectricPotentialAcUnit ParseUnit(string str) - { - return ParseUnit(str, null); - } - - /// - /// Parse a unit string. - /// - /// String to parse. Typically in the form: {number} {unit} - /// Format to use when parsing number and unit. Defaults to if null. - /// - /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - /// - /// The value of 'str' cannot be null. - /// Error parsing string. - public static ElectricPotentialAcUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitParser.Default.Parse(str, provider); - } - - /// - public static bool TryParseUnit(string str, out ElectricPotentialAcUnit unit) - { - return TryParseUnit(str, null, out unit); - } - - /// - /// Parse a unit string. - /// - /// String to parse. Typically in the form: {number} {unit} - /// The parsed unit if successful. - /// True if successful, otherwise false. - /// - /// Length.TryParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - /// - /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricPotentialAcUnit unit) - { - return UnitParser.Default.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static ElectricPotentialAc operator -(ElectricPotentialAc right) - { - return new ElectricPotentialAc(-right.Value, right.Unit); - } - - /// Get from adding two . - public static ElectricPotentialAc operator +(ElectricPotentialAc left, ElectricPotentialAc right) - { - return new ElectricPotentialAc(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static ElectricPotentialAc operator -(ElectricPotentialAc left, ElectricPotentialAc right) - { - return new ElectricPotentialAc(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static ElectricPotentialAc operator *(double left, ElectricPotentialAc right) - { - return new ElectricPotentialAc(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static ElectricPotentialAc operator *(ElectricPotentialAc left, double right) - { - return new ElectricPotentialAc(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static ElectricPotentialAc operator /(ElectricPotentialAc left, double right) - { - return new ElectricPotentialAc(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(ElectricPotentialAc left, ElectricPotentialAc right) - { - return left.VoltsAc / right.VoltsAc; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(ElectricPotentialAc left, ElectricPotentialAc right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(ElectricPotentialAc left, ElectricPotentialAc right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(ElectricPotentialAc left, ElectricPotentialAc right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(ElectricPotentialAc left, ElectricPotentialAc right) - { - return left.Value > right.ToUnit(left.Unit).Value; - } - - // We use obsolete attribute to communicate the preferred equality members to use. - // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. - #pragma warning disable CS0809 - - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public static bool operator ==(ElectricPotentialAc left, ElectricPotentialAc right) - { - return left.Equals(right); - } - - /// Indicates strict inequality of two quantities, where both and are exactly equal. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public static bool operator !=(ElectricPotentialAc left, ElectricPotentialAc right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public override bool Equals(object? obj) - { - if (obj is null || !(obj is ElectricPotentialAc otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public bool Equals(ElectricPotentialAc other) - { - return new { Value, Unit }.Equals(new { other.Value, other.Unit }); - } - - #pragma warning restore CS0809 - - /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. - /// An object to compare with this instance. - /// - /// is not the same type as this instance. - /// - /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: - /// - /// Value Meaning - /// Less than zero This instance precedes in the sort order. - /// Zero This instance occurs in the same position in the sort order as . - /// Greater than zero This instance follows in the sort order. - /// - /// - public int CompareTo(object? obj) - { - if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricPotentialAc otherQuantity)) throw new ArgumentException("Expected type ElectricPotentialAc.", nameof(obj)); - - return CompareTo(otherQuantity); - } - - /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. - /// A quantity to compare with this instance. - /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: - /// - /// Value Meaning - /// Less than zero This instance precedes in the sort order. - /// Zero This instance occurs in the same position in the sort order as . - /// Greater than zero This instance follows in the sort order. - /// - /// - public int CompareTo(ElectricPotentialAc other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another ElectricPotentialAc within the given absolute or relative tolerance. - /// - /// - /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and - /// as a percentage of this quantity's value. will be converted into - /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of - /// this quantity's value to be considered equal. - /// - /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). - /// - /// var a = Length.FromMeters(2.0); - /// var b = Length.FromInches(50.0); - /// a.Equals(b, 0.01, ComparisonType.Relative); - /// - /// - /// - /// - /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and - /// as a fixed number in this quantity's unit. will be converted into - /// this quantity's unit for comparison. - /// - /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). - /// - /// var a = Length.FromMeters(2.0); - /// var b = Length.FromInches(50.0); - /// a.Equals(b, 0.01, ComparisonType.Absolute); - /// - /// - /// - /// - /// Note that it is advised against specifying zero difference, due to the nature - /// of floating-point operations and using double internally. - /// - /// - /// The other quantity to compare to. - /// The absolute or relative tolerance value. Must be greater than or equal to 0. - /// The comparison type: either relative or absolute. - /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. - [Obsolete("Use Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public bool Equals(ElectricPotentialAc other, double tolerance, ComparisonType comparisonType) - { - if (tolerance < 0) - throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - - return UnitsNet.Comparison.Equals( - referenceValue: this.Value, - otherValue: other.As(this.Unit), - tolerance: tolerance, - comparisonType: ComparisonType.Absolute); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is ElectricPotentialAc otherTyped - && (tolerance is ElectricPotentialAc toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricPotentialAc'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(ElectricPotentialAc other, ElectricPotentialAc tolerance) - { - return UnitsNet.Comparison.Equals( - referenceValue: this.Value, - otherValue: other.As(this.Unit), - tolerance: tolerance.As(this.Unit), - comparisonType: ComparisonType.Absolute); - } - - /// - /// Returns the hash code for this instance. - /// - /// A hash code for the current ElectricPotentialAc. - public override int GetHashCode() - { - return new { Info.Name, Value, Unit }.GetHashCode(); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ElectricPotentialAcUnit unit) - { - if (Unit == unit) - return Value; - - return ToUnit(unit).Value; - } - - /// - public double As(UnitSystem unitSystem) - { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricPotentialAcUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialAcUnit)} is supported.", nameof(unit)); - - return (double)As(typedUnit); - } - - /// - double IValueQuantity.As(Enum unit) - { - if (!(unit is ElectricPotentialAcUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialAcUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this ElectricPotentialAc to another ElectricPotentialAc with the unit representation . - /// - /// The unit to convert to. - /// A ElectricPotentialAc with the specified unit. - public ElectricPotentialAc ToUnit(ElectricPotentialAcUnit unit) - { - return ToUnit(unit, DefaultConversionFunctions); - } - - /// - /// Converts this to another using the given with the unit representation . - /// - /// The unit to convert to. - /// The to use for the conversion. - /// A ElectricPotentialAc with the specified unit. - public ElectricPotentialAc ToUnit(ElectricPotentialAcUnit unit, UnitConverter unitConverter) - { - if (TryToUnit(unit, out var converted)) - { - // Try to convert using the auto-generated conversion methods. - return converted!.Value; - } - else if (unitConverter.TryGetConversionFunction((typeof(ElectricPotentialAc), Unit, typeof(ElectricPotentialAc), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (ElectricPotentialAc)conversionFunction(this); - } - else if (Unit != BaseUnit) - { - // Conversion to requested unit NOT found. Try to convert to BaseUnit, and then from BaseUnit to requested unit. - var inBaseUnits = ToUnit(BaseUnit); - return inBaseUnits.ToUnit(unit); - } - else - { - // No possible conversion - throw new NotImplementedException($"Can not convert {Unit} to {unit}."); - } - } - - /// - /// Attempts to convert this to another with the unit representation . - /// - /// The unit to convert to. - /// The converted in , if successful. - /// True if successful, otherwise false. - private bool TryToUnit(ElectricPotentialAcUnit unit, [NotNullWhen(true)] out ElectricPotentialAc? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - ElectricPotentialAc? convertedOrNull = (Unit, unit) switch - { - // ElectricPotentialAcUnit -> BaseUnit - (ElectricPotentialAcUnit.KilovoltAc, ElectricPotentialAcUnit.VoltAc) => new ElectricPotentialAc((_value) * 1e3d, ElectricPotentialAcUnit.VoltAc), - (ElectricPotentialAcUnit.MegavoltAc, ElectricPotentialAcUnit.VoltAc) => new ElectricPotentialAc((_value) * 1e6d, ElectricPotentialAcUnit.VoltAc), - (ElectricPotentialAcUnit.MicrovoltAc, ElectricPotentialAcUnit.VoltAc) => new ElectricPotentialAc((_value) * 1e-6d, ElectricPotentialAcUnit.VoltAc), - (ElectricPotentialAcUnit.MillivoltAc, ElectricPotentialAcUnit.VoltAc) => new ElectricPotentialAc((_value) * 1e-3d, ElectricPotentialAcUnit.VoltAc), - - // BaseUnit -> ElectricPotentialAcUnit - (ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.KilovoltAc) => new ElectricPotentialAc((_value) / 1e3d, ElectricPotentialAcUnit.KilovoltAc), - (ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.MegavoltAc) => new ElectricPotentialAc((_value) / 1e6d, ElectricPotentialAcUnit.MegavoltAc), - (ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.MicrovoltAc) => new ElectricPotentialAc((_value) / 1e-6d, ElectricPotentialAcUnit.MicrovoltAc), - (ElectricPotentialAcUnit.VoltAc, ElectricPotentialAcUnit.MillivoltAc) => new ElectricPotentialAc((_value) / 1e-3d, ElectricPotentialAcUnit.MillivoltAc), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is ElectricPotentialAcUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialAcUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public ElectricPotentialAc ToUnit(UnitSystem unitSystem) - { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return ToUnit(firstUnitInfo.Value); - } - - /// - IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); - - /// - IQuantity IQuantity.ToUnit(ElectricPotentialAcUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); - - /// - IValueQuantity IValueQuantity.ToUnit(Enum unit) - { - if (unit is not ElectricPotentialAcUnit typedUnit) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialAcUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit); - } - - /// - IValueQuantity IValueQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); - - #endregion - - #region ToString Methods - - /// - /// Gets the default string representation of value and unit. - /// - /// String representation. - public override string ToString() - { - return ToString("g"); - } - - /// - /// Gets the default string representation of value and unit using the given format provider. - /// - /// String representation. - /// Format to use for localization and number formatting. Defaults to if null. - public string ToString(IFormatProvider? provider) - { - return ToString("g", provider); - } - - /// - /// - /// Gets the string representation of this instance in the specified format string using . - /// - /// The format string. - /// The string representation. - public string ToString(string? format) - { - return ToString(format, CultureInfo.CurrentCulture); - } - - /// - /// - /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. - /// - /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. - /// The string representation. - public string ToString(string? format, IFormatProvider? provider) - { - return QuantityFormatter.Format(this, format, provider); - } - - #endregion - - #region IConvertible Methods - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ElectricPotentialAc)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ElectricPotentialAc)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ElectricPotentialAc)} to DateTime is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider? provider) - { - return Convert.ToDecimal(_value); - } - - double IConvertible.ToDouble(IFormatProvider? provider) - { - return Convert.ToDouble(_value); - } - - short IConvertible.ToInt16(IFormatProvider? provider) - { - return Convert.ToInt16(_value); - } - - int IConvertible.ToInt32(IFormatProvider? provider) - { - return Convert.ToInt32(_value); - } - - long IConvertible.ToInt64(IFormatProvider? provider) - { - return Convert.ToInt64(_value); - } - - sbyte IConvertible.ToSByte(IFormatProvider? provider) - { - return Convert.ToSByte(_value); - } - - float IConvertible.ToSingle(IFormatProvider? provider) - { - return Convert.ToSingle(_value); - } - - string IConvertible.ToString(IFormatProvider? provider) - { - return ToString("g", provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(ElectricPotentialAc)) - return this; - else if (conversionType == typeof(ElectricPotentialAcUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return ElectricPotentialAc.Info; - else if (conversionType == typeof(BaseDimensions)) - return ElectricPotentialAc.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(ElectricPotentialAc)} to {conversionType} is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider? provider) - { - return Convert.ToUInt16(_value); - } - - uint IConvertible.ToUInt32(IFormatProvider? provider) - { - return Convert.ToUInt32(_value); - } - - ulong IConvertible.ToUInt64(IFormatProvider? provider) - { - return Convert.ToUInt64(_value); - } - - #endregion - } -} diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs deleted file mode 100644 index a4c48d4abc..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ /dev/null @@ -1,1010 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.InternalHelpers; -using UnitsNet.Units; - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// The Electric Potential of a system known to use Direct Current. - /// - [DataContract] - public readonly partial struct ElectricPotentialDc : - IArithmeticQuantity, - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 0)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 1)] - private readonly ElectricPotentialDcUnit? _unit; - - static ElectricPotentialDc() - { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = ElectricPotentialDcUnit.VoltDc; - Units = Enum.GetValues(typeof(ElectricPotentialDcUnit)).Cast().ToArray(); - Zero = new ElectricPotentialDc(0, BaseUnit); - Info = new QuantityInfo("ElectricPotentialDc", - new UnitInfo[] - { - new UnitInfo(ElectricPotentialDcUnit.KilovoltDc, "KilovoltsDc", BaseUnits.Undefined, "ElectricPotentialDc"), - new UnitInfo(ElectricPotentialDcUnit.MegavoltDc, "MegavoltsDc", BaseUnits.Undefined, "ElectricPotentialDc"), - new UnitInfo(ElectricPotentialDcUnit.MicrovoltDc, "MicrovoltsDc", BaseUnits.Undefined, "ElectricPotentialDc"), - new UnitInfo(ElectricPotentialDcUnit.MillivoltDc, "MillivoltsDc", BaseUnits.Undefined, "ElectricPotentialDc"), - new UnitInfo(ElectricPotentialDcUnit.VoltDc, "VoltsDc", BaseUnits.Undefined, "ElectricPotentialDc"), - }, - BaseUnit, Zero, BaseDimensions); - - DefaultConversionFunctions = new UnitConverter(); - RegisterDefaultConversions(DefaultConversionFunctions); - } - - /// - /// Creates the quantity with the given numeric value and unit. - /// - /// The numeric value to construct this quantity with. - /// The unit representation to construct this quantity with. - /// If value is NaN or Infinity. - public ElectricPotentialDc(double value, ElectricPotentialDcUnit unit) - { - _value = Guard.EnsureValidNumber(value, nameof(value)); - _unit = unit; - } - - /// - /// Creates an instance of the quantity with the given numeric value in units compatible with the given . - /// If multiple compatible units were found, the first match is used. - /// - /// The numeric value to construct this quantity with. - /// The unit system to create the quantity with. - /// The given is null. - /// No unit was found for the given . - public ElectricPotentialDc(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = Guard.EnsureValidNumber(value, nameof(value)); - _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - } - - #region Static Properties - - /// - /// The containing the default generated conversion functions for instances. - /// - public static UnitConverter DefaultConversionFunctions { get; } - - /// - public static QuantityInfo Info { get; } - - /// - /// The of this quantity. - /// - public static BaseDimensions BaseDimensions { get; } - - /// - /// The base unit of ElectricPotentialDc, which is VoltDc. All conversions go via this value. - /// - public static ElectricPotentialDcUnit BaseUnit { get; } - - /// - /// All units of measurement for the ElectricPotentialDc quantity. - /// - public static ElectricPotentialDcUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit VoltDc. - /// - public static ElectricPotentialDc Zero { get; } - - /// - public static ElectricPotentialDc AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - QuantityValue IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public ElectricPotentialDcUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => ElectricPotentialDc.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltsDc => As(ElectricPotentialDcUnit.KilovoltDc); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltsDc => As(ElectricPotentialDcUnit.MegavoltDc); - - /// - /// Gets a value of this quantity converted into - /// - public double MicrovoltsDc => As(ElectricPotentialDcUnit.MicrovoltDc); - - /// - /// Gets a value of this quantity converted into - /// - public double MillivoltsDc => As(ElectricPotentialDcUnit.MillivoltDc); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltsDc => As(ElectricPotentialDcUnit.VoltDc); - - #endregion - - #region Static Methods - - /// - /// Registers the default conversion functions in the given instance. - /// - /// The to register the default conversion functions in. - internal static void RegisterDefaultConversions(UnitConverter unitConverter) - { - // Register in unit converter: ElectricPotentialDcUnit -> BaseUnit - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.KilovoltDc, ElectricPotentialDcUnit.VoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.VoltDc)); - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.MegavoltDc, ElectricPotentialDcUnit.VoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.VoltDc)); - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.MicrovoltDc, ElectricPotentialDcUnit.VoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.VoltDc)); - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.MillivoltDc, ElectricPotentialDcUnit.VoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.VoltDc)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.VoltDc, quantity => quantity); - - // Register in unit converter: BaseUnit -> ElectricPotentialDcUnit - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.KilovoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.KilovoltDc)); - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.MegavoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.MegavoltDc)); - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.MicrovoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.MicrovoltDc)); - unitConverter.SetConversionFunction(ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.MillivoltDc, quantity => quantity.ToUnit(ElectricPotentialDcUnit.MillivoltDc)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(ElectricPotentialDcUnit unit) - { - return GetAbbreviation(unit, null); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - /// Format to use for localization. Defaults to if null. - public static string GetAbbreviation(ElectricPotentialDcUnit unit, IFormatProvider? provider) - { - return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialDc FromKilovoltsDc(QuantityValue kilovoltsdc) - { - double value = (double) kilovoltsdc; - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.KilovoltDc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialDc FromMegavoltsDc(QuantityValue megavoltsdc) - { - double value = (double) megavoltsdc; - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MegavoltDc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialDc FromMicrovoltsDc(QuantityValue microvoltsdc) - { - double value = (double) microvoltsdc; - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MicrovoltDc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialDc FromMillivoltsDc(QuantityValue millivoltsdc) - { - double value = (double) millivoltsdc; - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MillivoltDc); - } - - /// - /// Creates a from . - /// - /// If value is NaN or Infinity. - public static ElectricPotentialDc FromVoltsDc(QuantityValue voltsdc) - { - double value = (double) voltsdc; - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.VoltDc); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ElectricPotentialDc unit value. - public static ElectricPotentialDc From(QuantityValue value, ElectricPotentialDcUnit fromUnit) - { - return new ElectricPotentialDc((double)value, fromUnit); - } - - #endregion - - #region Static Parse Methods - - /// - /// Parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("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 ElectricPotentialDc Parse(string str) - { - return Parse(str, null); - } - - /// - /// Parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); - /// - /// The value of 'str' cannot be null. - /// - /// Expected string to have one or two pairs of quantity and unit in the format - /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" - /// - /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . - /// - /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. - /// - /// Format to use when parsing number and unit. Defaults to if null. - public static ElectricPotentialDc Parse(string str, IFormatProvider? provider) - { - return QuantityParser.Default.Parse( - str, - provider, - From); - } - - /// - /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// Resulting unit quantity if successful. - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); - /// - public static bool TryParse(string? str, out ElectricPotentialDc result) - { - return TryParse(str, null, out result); - } - - /// - /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". - /// - /// String to parse. Typically in the form: {number} {unit} - /// Resulting unit quantity if successful. - /// True if successful, otherwise false. - /// - /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); - /// - /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParse(string? str, IFormatProvider? provider, out ElectricPotentialDc result) - { - return QuantityParser.Default.TryParse( - str, - provider, - From, - out result); - } - - /// - /// Parse a unit string. - /// - /// String to parse. Typically in the form: {number} {unit} - /// - /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - /// - /// The value of 'str' cannot be null. - /// Error parsing string. - public static ElectricPotentialDcUnit ParseUnit(string str) - { - return ParseUnit(str, null); - } - - /// - /// Parse a unit string. - /// - /// String to parse. Typically in the form: {number} {unit} - /// Format to use when parsing number and unit. Defaults to if null. - /// - /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - /// - /// The value of 'str' cannot be null. - /// Error parsing string. - public static ElectricPotentialDcUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitParser.Default.Parse(str, provider); - } - - /// - public static bool TryParseUnit(string str, out ElectricPotentialDcUnit unit) - { - return TryParseUnit(str, null, out unit); - } - - /// - /// Parse a unit string. - /// - /// String to parse. Typically in the form: {number} {unit} - /// The parsed unit if successful. - /// True if successful, otherwise false. - /// - /// Length.TryParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - /// - /// Format to use when parsing number and unit. Defaults to if null. - public static bool TryParseUnit(string str, IFormatProvider? provider, out ElectricPotentialDcUnit unit) - { - return UnitParser.Default.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static ElectricPotentialDc operator -(ElectricPotentialDc right) - { - return new ElectricPotentialDc(-right.Value, right.Unit); - } - - /// Get from adding two . - public static ElectricPotentialDc operator +(ElectricPotentialDc left, ElectricPotentialDc right) - { - return new ElectricPotentialDc(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static ElectricPotentialDc operator -(ElectricPotentialDc left, ElectricPotentialDc right) - { - return new ElectricPotentialDc(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static ElectricPotentialDc operator *(double left, ElectricPotentialDc right) - { - return new ElectricPotentialDc(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static ElectricPotentialDc operator *(ElectricPotentialDc left, double right) - { - return new ElectricPotentialDc(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static ElectricPotentialDc operator /(ElectricPotentialDc left, double right) - { - return new ElectricPotentialDc(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(ElectricPotentialDc left, ElectricPotentialDc right) - { - return left.VoltsDc / right.VoltsDc; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(ElectricPotentialDc left, ElectricPotentialDc right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(ElectricPotentialDc left, ElectricPotentialDc right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(ElectricPotentialDc left, ElectricPotentialDc right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(ElectricPotentialDc left, ElectricPotentialDc right) - { - return left.Value > right.ToUnit(left.Unit).Value; - } - - // We use obsolete attribute to communicate the preferred equality members to use. - // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. - #pragma warning disable CS0809 - - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public static bool operator ==(ElectricPotentialDc left, ElectricPotentialDc right) - { - return left.Equals(right); - } - - /// Indicates strict inequality of two quantities, where both and are exactly equal. - [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public static bool operator !=(ElectricPotentialDc left, ElectricPotentialDc right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public override bool Equals(object? obj) - { - if (obj is null || !(obj is ElectricPotentialDc otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public bool Equals(ElectricPotentialDc other) - { - return new { Value, Unit }.Equals(new { other.Value, other.Unit }); - } - - #pragma warning restore CS0809 - - /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. - /// An object to compare with this instance. - /// - /// is not the same type as this instance. - /// - /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: - /// - /// Value Meaning - /// Less than zero This instance precedes in the sort order. - /// Zero This instance occurs in the same position in the sort order as . - /// Greater than zero This instance follows in the sort order. - /// - /// - public int CompareTo(object? obj) - { - if (obj is null) throw new ArgumentNullException(nameof(obj)); - if (!(obj is ElectricPotentialDc otherQuantity)) throw new ArgumentException("Expected type ElectricPotentialDc.", nameof(obj)); - - return CompareTo(otherQuantity); - } - - /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. - /// A quantity to compare with this instance. - /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: - /// - /// Value Meaning - /// Less than zero This instance precedes in the sort order. - /// Zero This instance occurs in the same position in the sort order as . - /// Greater than zero This instance follows in the sort order. - /// - /// - public int CompareTo(ElectricPotentialDc other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another ElectricPotentialDc within the given absolute or relative tolerance. - /// - /// - /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and - /// as a percentage of this quantity's value. will be converted into - /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of - /// this quantity's value to be considered equal. - /// - /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). - /// - /// var a = Length.FromMeters(2.0); - /// var b = Length.FromInches(50.0); - /// a.Equals(b, 0.01, ComparisonType.Relative); - /// - /// - /// - /// - /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and - /// as a fixed number in this quantity's unit. will be converted into - /// this quantity's unit for comparison. - /// - /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). - /// - /// var a = Length.FromMeters(2.0); - /// var b = Length.FromInches(50.0); - /// a.Equals(b, 0.01, ComparisonType.Absolute); - /// - /// - /// - /// - /// Note that it is advised against specifying zero difference, due to the nature - /// of floating-point operations and using double internally. - /// - /// - /// The other quantity to compare to. - /// The absolute or relative tolerance value. Must be greater than or equal to 0. - /// The comparison type: either relative or absolute. - /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. - [Obsolete("Use Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] - public bool Equals(ElectricPotentialDc other, double tolerance, ComparisonType comparisonType) - { - if (tolerance < 0) - throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); - - return UnitsNet.Comparison.Equals( - referenceValue: this.Value, - otherValue: other.As(this.Unit), - tolerance: tolerance, - comparisonType: ComparisonType.Absolute); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is ElectricPotentialDc otherTyped - && (tolerance is ElectricPotentialDc toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricPotentialDc'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(ElectricPotentialDc other, ElectricPotentialDc tolerance) - { - return UnitsNet.Comparison.Equals( - referenceValue: this.Value, - otherValue: other.As(this.Unit), - tolerance: tolerance.As(this.Unit), - comparisonType: ComparisonType.Absolute); - } - - /// - /// Returns the hash code for this instance. - /// - /// A hash code for the current ElectricPotentialDc. - public override int GetHashCode() - { - return new { Info.Name, Value, Unit }.GetHashCode(); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ElectricPotentialDcUnit unit) - { - if (Unit == unit) - return Value; - - return ToUnit(unit).Value; - } - - /// - public double As(UnitSystem unitSystem) - { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return As(firstUnitInfo.Value); - } - - /// - double IQuantity.As(Enum unit) - { - if (!(unit is ElectricPotentialDcUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialDcUnit)} is supported.", nameof(unit)); - - return (double)As(typedUnit); - } - - /// - double IValueQuantity.As(Enum unit) - { - if (!(unit is ElectricPotentialDcUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialDcUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this ElectricPotentialDc to another ElectricPotentialDc with the unit representation . - /// - /// The unit to convert to. - /// A ElectricPotentialDc with the specified unit. - public ElectricPotentialDc ToUnit(ElectricPotentialDcUnit unit) - { - return ToUnit(unit, DefaultConversionFunctions); - } - - /// - /// Converts this to another using the given with the unit representation . - /// - /// The unit to convert to. - /// The to use for the conversion. - /// A ElectricPotentialDc with the specified unit. - public ElectricPotentialDc ToUnit(ElectricPotentialDcUnit unit, UnitConverter unitConverter) - { - if (TryToUnit(unit, out var converted)) - { - // Try to convert using the auto-generated conversion methods. - return converted!.Value; - } - else if (unitConverter.TryGetConversionFunction((typeof(ElectricPotentialDc), Unit, typeof(ElectricPotentialDc), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (ElectricPotentialDc)conversionFunction(this); - } - else if (Unit != BaseUnit) - { - // Conversion to requested unit NOT found. Try to convert to BaseUnit, and then from BaseUnit to requested unit. - var inBaseUnits = ToUnit(BaseUnit); - return inBaseUnits.ToUnit(unit); - } - else - { - // No possible conversion - throw new NotImplementedException($"Can not convert {Unit} to {unit}."); - } - } - - /// - /// Attempts to convert this to another with the unit representation . - /// - /// The unit to convert to. - /// The converted in , if successful. - /// True if successful, otherwise false. - private bool TryToUnit(ElectricPotentialDcUnit unit, [NotNullWhen(true)] out ElectricPotentialDc? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - ElectricPotentialDc? convertedOrNull = (Unit, unit) switch - { - // ElectricPotentialDcUnit -> BaseUnit - (ElectricPotentialDcUnit.KilovoltDc, ElectricPotentialDcUnit.VoltDc) => new ElectricPotentialDc((_value) * 1e3d, ElectricPotentialDcUnit.VoltDc), - (ElectricPotentialDcUnit.MegavoltDc, ElectricPotentialDcUnit.VoltDc) => new ElectricPotentialDc((_value) * 1e6d, ElectricPotentialDcUnit.VoltDc), - (ElectricPotentialDcUnit.MicrovoltDc, ElectricPotentialDcUnit.VoltDc) => new ElectricPotentialDc((_value) * 1e-6d, ElectricPotentialDcUnit.VoltDc), - (ElectricPotentialDcUnit.MillivoltDc, ElectricPotentialDcUnit.VoltDc) => new ElectricPotentialDc((_value) * 1e-3d, ElectricPotentialDcUnit.VoltDc), - - // BaseUnit -> ElectricPotentialDcUnit - (ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.KilovoltDc) => new ElectricPotentialDc((_value) / 1e3d, ElectricPotentialDcUnit.KilovoltDc), - (ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.MegavoltDc) => new ElectricPotentialDc((_value) / 1e6d, ElectricPotentialDcUnit.MegavoltDc), - (ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.MicrovoltDc) => new ElectricPotentialDc((_value) / 1e-6d, ElectricPotentialDcUnit.MicrovoltDc), - (ElectricPotentialDcUnit.VoltDc, ElectricPotentialDcUnit.MillivoltDc) => new ElectricPotentialDc((_value) / 1e-3d, ElectricPotentialDcUnit.MillivoltDc), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is ElectricPotentialDcUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialDcUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public ElectricPotentialDc ToUnit(UnitSystem unitSystem) - { - if (unitSystem is null) - throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - - var firstUnitInfo = unitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); - - return ToUnit(firstUnitInfo.Value); - } - - /// - IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); - - /// - IQuantity IQuantity.ToUnit(ElectricPotentialDcUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); - - /// - IValueQuantity IValueQuantity.ToUnit(Enum unit) - { - if (unit is not ElectricPotentialDcUnit typedUnit) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialDcUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit); - } - - /// - IValueQuantity IValueQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); - - #endregion - - #region ToString Methods - - /// - /// Gets the default string representation of value and unit. - /// - /// String representation. - public override string ToString() - { - return ToString("g"); - } - - /// - /// Gets the default string representation of value and unit using the given format provider. - /// - /// String representation. - /// Format to use for localization and number formatting. Defaults to if null. - public string ToString(IFormatProvider? provider) - { - return ToString("g", provider); - } - - /// - /// - /// Gets the string representation of this instance in the specified format string using . - /// - /// The format string. - /// The string representation. - public string ToString(string? format) - { - return ToString(format, CultureInfo.CurrentCulture); - } - - /// - /// - /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. - /// - /// The format string. - /// Format to use for localization and number formatting. Defaults to if null. - /// The string representation. - public string ToString(string? format, IFormatProvider? provider) - { - return QuantityFormatter.Format(this, format, provider); - } - - #endregion - - #region IConvertible Methods - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ElectricPotentialDc)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ElectricPotentialDc)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ElectricPotentialDc)} to DateTime is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider? provider) - { - return Convert.ToDecimal(_value); - } - - double IConvertible.ToDouble(IFormatProvider? provider) - { - return Convert.ToDouble(_value); - } - - short IConvertible.ToInt16(IFormatProvider? provider) - { - return Convert.ToInt16(_value); - } - - int IConvertible.ToInt32(IFormatProvider? provider) - { - return Convert.ToInt32(_value); - } - - long IConvertible.ToInt64(IFormatProvider? provider) - { - return Convert.ToInt64(_value); - } - - sbyte IConvertible.ToSByte(IFormatProvider? provider) - { - return Convert.ToSByte(_value); - } - - float IConvertible.ToSingle(IFormatProvider? provider) - { - return Convert.ToSingle(_value); - } - - string IConvertible.ToString(IFormatProvider? provider) - { - return ToString("g", provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(ElectricPotentialDc)) - return this; - else if (conversionType == typeof(ElectricPotentialDcUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return ElectricPotentialDc.Info; - else if (conversionType == typeof(BaseDimensions)) - return ElectricPotentialDc.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(ElectricPotentialDc)} to {conversionType} is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider? provider) - { - return Convert.ToUInt16(_value); - } - - uint IConvertible.ToUInt32(IFormatProvider? provider) - { - return Convert.ToUInt32(_value); - } - - ulong IConvertible.ToUInt64(IFormatProvider? provider) - { - return Convert.ToUInt64(_value); - } - - #endregion - } -} diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 5236f4b15a..ce2d07f1b9 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -67,9 +67,7 @@ public partial class Quantity { "ElectricField", ElectricField.Info }, { "ElectricInductance", ElectricInductance.Info }, { "ElectricPotential", ElectricPotential.Info }, - { "ElectricPotentialAc", ElectricPotentialAc.Info }, { "ElectricPotentialChangeRate", ElectricPotentialChangeRate.Info }, - { "ElectricPotentialDc", ElectricPotentialDc.Info }, { "ElectricResistance", ElectricResistance.Info }, { "ElectricResistivity", ElectricResistivity.Info }, { "ElectricSurfaceChargeDensity", ElectricSurfaceChargeDensity.Info }, @@ -199,9 +197,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu "ElectricField" => ElectricField.From(value, ElectricField.BaseUnit), "ElectricInductance" => ElectricInductance.From(value, ElectricInductance.BaseUnit), "ElectricPotential" => ElectricPotential.From(value, ElectricPotential.BaseUnit), - "ElectricPotentialAc" => ElectricPotentialAc.From(value, ElectricPotentialAc.BaseUnit), "ElectricPotentialChangeRate" => ElectricPotentialChangeRate.From(value, ElectricPotentialChangeRate.BaseUnit), - "ElectricPotentialDc" => ElectricPotentialDc.From(value, ElectricPotentialDc.BaseUnit), "ElectricResistance" => ElectricResistance.From(value, ElectricResistance.BaseUnit), "ElectricResistivity" => ElectricResistivity.From(value, ElectricResistivity.BaseUnit), "ElectricSurfaceChargeDensity" => ElectricSurfaceChargeDensity.From(value, ElectricSurfaceChargeDensity.BaseUnit), @@ -334,9 +330,7 @@ public static bool TryFrom(QuantityValue value, Enum? unit, [NotNullWhen(true)] ElectricFieldUnit electricFieldUnit => ElectricField.From(value, electricFieldUnit), ElectricInductanceUnit electricInductanceUnit => ElectricInductance.From(value, electricInductanceUnit), ElectricPotentialUnit electricPotentialUnit => ElectricPotential.From(value, electricPotentialUnit), - ElectricPotentialAcUnit electricPotentialAcUnit => ElectricPotentialAc.From(value, electricPotentialAcUnit), ElectricPotentialChangeRateUnit electricPotentialChangeRateUnit => ElectricPotentialChangeRate.From(value, electricPotentialChangeRateUnit), - ElectricPotentialDcUnit electricPotentialDcUnit => ElectricPotentialDc.From(value, electricPotentialDcUnit), ElectricResistanceUnit electricResistanceUnit => ElectricResistance.From(value, electricResistanceUnit), ElectricResistivityUnit electricResistivityUnit => ElectricResistivity.From(value, electricResistivityUnit), ElectricSurfaceChargeDensityUnit electricSurfaceChargeDensityUnit => ElectricSurfaceChargeDensity.From(value, electricSurfaceChargeDensityUnit), @@ -479,9 +473,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(ElectricField) => parser.TryParse(quantityString, formatProvider, ElectricField.From, out quantity), Type _ when quantityType == typeof(ElectricInductance) => parser.TryParse(quantityString, formatProvider, ElectricInductance.From, out quantity), Type _ when quantityType == typeof(ElectricPotential) => parser.TryParse(quantityString, formatProvider, ElectricPotential.From, out quantity), - Type _ when quantityType == typeof(ElectricPotentialAc) => parser.TryParse(quantityString, formatProvider, ElectricPotentialAc.From, out quantity), Type _ when quantityType == typeof(ElectricPotentialChangeRate) => parser.TryParse(quantityString, formatProvider, ElectricPotentialChangeRate.From, out quantity), - Type _ when quantityType == typeof(ElectricPotentialDc) => parser.TryParse(quantityString, formatProvider, ElectricPotentialDc.From, out quantity), Type _ when quantityType == typeof(ElectricResistance) => parser.TryParse(quantityString, formatProvider, ElectricResistance.From, out quantity), Type _ when quantityType == typeof(ElectricResistivity) => parser.TryParse(quantityString, formatProvider, ElectricResistivity.From, out quantity), Type _ when quantityType == typeof(ElectricSurfaceChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricSurfaceChargeDensity.From, out quantity), @@ -605,9 +597,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(ElectricField); yield return typeof(ElectricInductance); yield return typeof(ElectricPotential); - yield return typeof(ElectricPotentialAc); yield return typeof(ElectricPotentialChangeRate); - yield return typeof(ElectricPotentialDc); yield return typeof(ElectricResistance); yield return typeof(ElectricResistivity); yield return typeof(ElectricSurfaceChargeDensity); diff --git a/UnitsNet/GeneratedCode/Resources/ElectricPotentialAc.restext b/UnitsNet/GeneratedCode/Resources/ElectricPotentialAc.restext deleted file mode 100644 index e2c2b53e63..0000000000 --- a/UnitsNet/GeneratedCode/Resources/ElectricPotentialAc.restext +++ /dev/null @@ -1,5 +0,0 @@ -KilovoltsAc=kVac -MegavoltsAc=MVac -MicrovoltsAc=µVac -MillivoltsAc=mVac -VoltsAc=Vac diff --git a/UnitsNet/GeneratedCode/Resources/ElectricPotentialDc.restext b/UnitsNet/GeneratedCode/Resources/ElectricPotentialDc.restext deleted file mode 100644 index 621ba8ba48..0000000000 --- a/UnitsNet/GeneratedCode/Resources/ElectricPotentialDc.restext +++ /dev/null @@ -1,5 +0,0 @@ -KilovoltsDc=kVdc -MegavoltsDc=MVdc -MicrovoltsDc=µVdc -MillivoltsDc=mVdc -VoltsDc=Vdc diff --git a/UnitsNet/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs deleted file mode 100644 index 224c9c4c30..0000000000 --- a/UnitsNet/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs +++ /dev/null @@ -1,36 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by \generate-code.bat. -// -// Changes to this file will be lost when the code is regenerated. -// The build server regenerates the code before each build and a pre-build -// step will regenerate the code on each local build. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. -// -// -//------------------------------------------------------------------------------ - -// Licensed under MIT No Attribution, see LICENSE file at the root. -// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. - -// ReSharper disable once CheckNamespace -namespace UnitsNet.Units -{ - // Disable missing XML comment warnings for the generated unit enums. - #pragma warning disable 1591 - - public enum ElectricPotentialDcUnit - { - KilovoltDc = 1, - MegavoltDc = 2, - MicrovoltDc = 3, - MillivoltDc = 4, - VoltDc = 5, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet/UnitsNet.csproj b/UnitsNet/UnitsNet.csproj index 1af33a9dc1..845644b1c0 100644 --- a/UnitsNet/UnitsNet.csproj +++ b/UnitsNet/UnitsNet.csproj @@ -69,4 +69,9 @@ + + + + +