From 15f83de4a37c72002912c03e97902637bd3b8edd Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Mon, 30 Dec 2024 00:08:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5Remove=20obsolete=20electric=20quan?= =?UTF-8?q?tities=20(#1482)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made obsolete by #1467, #1444 Now removed in v6: - ApparentEnergy - ApparentPower - Capacitance - ElectricPotentialAc - ElectricPotentialDc - ReactiveEnergy - ReactivePower --- Build/build-pack-nano-nugets.psm1 | 1 - CodeGen/Generators/UnitsNetGenerator.cs | 3 + Common/UnitDefinitions/ApparentEnergy.json | 27 - Common/UnitDefinitions/ApparentPower.json | 27 - Common/UnitDefinitions/Capacitance.json | 34 - .../UnitDefinitions/ElectricPotentialAc.json | 22 - .../UnitDefinitions/ElectricPotentialDc.json | 22 - Common/UnitDefinitions/ReactiveEnergy.json | 27 - Common/UnitDefinitions/ReactivePower.json | 27 - Common/UnitEnumValues.g.json | 47 - .../ApparentEnergy/ApparentEnergy.nfproj | 42 - ...itsNet.NanoFramework.ApparentEnergy.nuspec | 26 - .../ApparentEnergy/packages.config | 4 - .../ApparentPower/ApparentPower.nfproj | 42 - ...nitsNet.NanoFramework.ApparentPower.nuspec | 26 - .../ApparentPower/packages.config | 4 - .../Capacitance/Capacitance.nfproj | 42 - .../UnitsNet.NanoFramework.Capacitance.nuspec | 26 - .../GeneratedCode/Capacitance/packages.config | 4 - .../ElectricPotentialAc.nfproj | 42 - ...t.NanoFramework.ElectricPotentialAc.nuspec | 26 - .../ElectricPotentialAc/packages.config | 4 - .../ElectricPotentialDc.nfproj | 42 - ...t.NanoFramework.ElectricPotentialDc.nuspec | 26 - .../ElectricPotentialDc/packages.config | 4 - .../Quantities/ApparentEnergy.g.cs | 185 --- .../Quantities/ApparentPower.g.cs | 221 ---- .../GeneratedCode/Quantities/Capacitance.g.cs | 233 ---- .../Quantities/ElectricPotentialAc.g.cs | 209 ---- .../Quantities/ElectricPotentialDc.g.cs | 209 ---- .../Quantities/ReactiveEnergy.g.cs | 185 --- .../Quantities/ReactivePower.g.cs | 197 ---- .../ReactiveEnergy/ReactiveEnergy.nfproj | 42 - ...itsNet.NanoFramework.ReactiveEnergy.nuspec | 26 - .../ReactiveEnergy/packages.config | 4 - .../ReactivePower/ReactivePower.nfproj | 42 - ...nitsNet.NanoFramework.ReactivePower.nuspec | 26 - .../ReactivePower/packages.config | 4 - .../Units/ApparentEnergyUnit.g.cs | 34 - .../Units/ApparentPowerUnit.g.cs | 37 - .../GeneratedCode/Units/CapacitanceUnit.g.cs | 38 - .../Units/ElectricPotentialAcUnit.g.cs | 36 - .../Units/ElectricPotentialDcUnit.g.cs | 36 - .../Units/ReactiveEnergyUnit.g.cs | 34 - .../Units/ReactivePowerUnit.g.cs | 35 - .../GeneratedCode/UnitsNet.nanoFramework.sln | 56 - .../NumberToApparentEnergyExtensionsTest.g.cs | 40 - .../NumberToApparentPowerExtensionsTest.g.cs | 52 - .../NumberToCapacitanceExtensionsTest.g.cs | 56 - ...erToElectricPotentialAcExtensionsTest.g.cs | 48 - ...erToElectricPotentialDcExtensionsTest.g.cs | 48 - .../NumberToReactiveEnergyExtensionsTest.g.cs | 40 - .../NumberToReactivePowerExtensionsTest.g.cs | 44 - .../NumberToApparentEnergyExtensions.g.cs | 64 - .../NumberToApparentPowerExtensions.g.cs | 91 -- .../NumberToCapacitanceExtensions.g.cs | 100 -- ...NumberToElectricPotentialAcExtensions.g.cs | 82 -- ...NumberToElectricPotentialDcExtensions.g.cs | 82 -- .../NumberToReactiveEnergyExtensions.g.cs | 64 - .../NumberToReactivePowerExtensions.g.cs | 73 -- .../CustomCode/ApparentEnergyTests.cs | 38 - .../CustomCode/ApparentPowerTests.cs | 44 - UnitsNet.Tests/CustomCode/CapacitanceTests.cs | 46 - .../CustomCode/ElectricPotentialAcTests.cs | 41 - .../CustomCode/ElectricPotentialDcTests.cs | 41 - .../CustomCode/ReactiveEnergyTests.cs | 37 - .../CustomCode/ReactivePowerTests.cs | 39 - .../GeneratedCode/IQuantityTests.g.cs | 21 - .../TestsBase/ApparentEnergyTestsBase.g.cs | 750 ------------ .../TestsBase/ApparentPowerTestsBase.g.cs | 840 -------------- .../TestsBase/CapacitanceTestsBase.g.cs | 874 -------------- .../ElectricPotentialAcTestsBase.g.cs | 806 ------------- .../ElectricPotentialDcTestsBase.g.cs | 806 ------------- .../TestsBase/ReactiveEnergyTestsBase.g.cs | 750 ------------ .../TestsBase/ReactivePowerTestsBase.g.cs | 784 ------------- .../Quantities/ApparentEnergy.g.cs | 954 --------------- .../Quantities/ApparentPower.g.cs | 1008 ---------------- .../GeneratedCode/Quantities/Capacitance.g.cs | 1026 ----------------- .../Quantities/ElectricPotentialAc.g.cs | 990 ---------------- .../Quantities/ElectricPotentialDc.g.cs | 990 ---------------- .../Quantities/ReactiveEnergy.g.cs | 954 --------------- .../Quantities/ReactivePower.g.cs | 972 ---------------- UnitsNet/GeneratedCode/Quantity.g.cs | 35 - .../Resources/ApparentEnergy.restext | 3 - .../Resources/ApparentPower.restext | 6 - .../Resources/Capacitance.restext | 7 - .../Resources/ElectricPotentialAc.restext | 5 - .../Resources/ElectricPotentialDc.restext | 5 - .../Units/ApparentEnergyUnit.g.cs | 34 - .../Units/ApparentPowerUnit.g.cs | 37 - .../GeneratedCode/Units/CapacitanceUnit.g.cs | 38 - .../Units/ElectricPotentialAcUnit.g.cs | 36 - .../Units/ElectricPotentialDcUnit.g.cs | 36 - 93 files changed, 3 insertions(+), 16420 deletions(-) delete mode 100644 Common/UnitDefinitions/ApparentEnergy.json delete mode 100644 Common/UnitDefinitions/ApparentPower.json delete mode 100644 Common/UnitDefinitions/Capacitance.json delete mode 100644 Common/UnitDefinitions/ElectricPotentialAc.json delete mode 100644 Common/UnitDefinitions/ElectricPotentialDc.json delete mode 100644 Common/UnitDefinitions/ReactiveEnergy.json delete mode 100644 Common/UnitDefinitions/ReactivePower.json delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/ApparentEnergy.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/UnitsNet.NanoFramework.ApparentEnergy.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/packages.config delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ApparentPower/ApparentPower.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ApparentPower/UnitsNet.NanoFramework.ApparentPower.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ApparentPower/packages.config delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Capacitance/Capacitance.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Capacitance/UnitsNet.NanoFramework.Capacitance.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Capacitance/packages.config 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.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactiveEnergy.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/ReactiveEnergy.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/UnitsNet.NanoFramework.ReactiveEnergy.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/packages.config delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReactivePower/ReactivePower.nfproj delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReactivePower/UnitsNet.NanoFramework.ReactivePower.nuspec delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/ReactivePower/packages.config delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ApparentEnergyUnit.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ApparentPowerUnit.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/CapacitanceUnit.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ReactiveEnergyUnit.g.cs delete mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/ReactivePowerUnit.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentEnergyExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentPowerExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCapacitanceExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialAcExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialDcExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactiveEnergyExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactivePowerExtensionsTest.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentEnergyExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentPowerExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToCapacitanceExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialDcExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToReactiveEnergyExtensions.g.cs delete mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToReactivePowerExtensions.g.cs delete mode 100644 UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/ApparentPowerTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/CapacitanceTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/ElectricPotentialAcTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/ElectricPotentialDcTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs delete mode 100644 UnitsNet.Tests/CustomCode/ReactivePowerTests.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs delete mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs delete mode 100644 UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs delete mode 100644 UnitsNet/GeneratedCode/Resources/ApparentEnergy.restext delete mode 100644 UnitsNet/GeneratedCode/Resources/ApparentPower.restext delete mode 100644 UnitsNet/GeneratedCode/Resources/Capacitance.restext delete mode 100644 UnitsNet/GeneratedCode/Resources/ElectricPotentialAc.restext delete mode 100644 UnitsNet/GeneratedCode/Resources/ElectricPotentialDc.restext delete mode 100644 UnitsNet/GeneratedCode/Units/ApparentEnergyUnit.g.cs delete mode 100644 UnitsNet/GeneratedCode/Units/ApparentPowerUnit.g.cs delete mode 100644 UnitsNet/GeneratedCode/Units/CapacitanceUnit.g.cs delete mode 100644 UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs delete mode 100644 UnitsNet/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs diff --git a/Build/build-pack-nano-nugets.psm1 b/Build/build-pack-nano-nugets.psm1 index 5ecf60a288..0d87ac5a64 100644 --- a/Build/build-pack-nano-nugets.psm1 +++ b/Build/build-pack-nano-nugets.psm1 @@ -8,7 +8,6 @@ function Invoke-BuildNanoNugets { & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\Duration\UnitsNet.NanoFramework.Duration.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\ElectricCurrent\UnitsNet.NanoFramework.ElectricCurrent.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\ElectricPotential\UnitsNet.NanoFramework.ElectricPotential.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" - & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\ElectricPotentialDc\UnitsNet.NanoFramework.ElectricPotentialDc.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\ElectricResistance\UnitsNet.NanoFramework.ElectricResistance.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\Frequency\UnitsNet.NanoFramework.Frequency.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" & $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\Illuminance\UnitsNet.NanoFramework.Illuminance.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" diff --git a/CodeGen/Generators/UnitsNetGenerator.cs b/CodeGen/Generators/UnitsNetGenerator.cs index ca23308212..907f70e4a6 100644 --- a/CodeGen/Generators/UnitsNetGenerator.cs +++ b/CodeGen/Generators/UnitsNetGenerator.cs @@ -153,6 +153,9 @@ private static void GenerateResourceFiles(Quantity[] quantities, string resource $"{resourcesDirectory}/{quantity.Name}.restext" : $"{resourcesDirectory}/{quantity.Name}.{culture}.restext"; + // Ensure parent folder exists + Directory.CreateDirectory(resourcesDirectory); + using var writer = File.CreateText(fileName); foreach(Unit unit in quantity.Units) diff --git a/Common/UnitDefinitions/ApparentEnergy.json b/Common/UnitDefinitions/ApparentEnergy.json deleted file mode 100644 index 7f588de3eb..0000000000 --- a/Common/UnitDefinitions/ApparentEnergy.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "Name": "ApparentEnergy", - "BaseUnit": "VoltampereHour", - "XmlDocSummary": "A unit for expressing the integral of apparent power over time, equal to the product of 1 volt-ampere and 1 hour, or to 3600 joules.", - "XmlDocRemarks": "ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.", - "ObsoleteText": "ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.", - "BaseDimensions": { - "L": 2, - "M": 1, - "T": -2 - }, - "Units": [ - { - "SingularName": "VoltampereHour", - "PluralName": "VoltampereHours", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Kilo", "Mega" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "VAh" ] - } - ] - } - ] -} diff --git a/Common/UnitDefinitions/ApparentPower.json b/Common/UnitDefinitions/ApparentPower.json deleted file mode 100644 index 4aebda1a1c..0000000000 --- a/Common/UnitDefinitions/ApparentPower.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "Name": "ApparentPower", - "BaseUnit": "Voltampere", - "XmlDocSummary": "Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. Apparent power is the product of the root-mean-square of voltage and current.", - "XmlDocRemarks": "ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.", - "ObsoleteText": "ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.", - "BaseDimensions": { - "L": 2, - "M": 1, - "T": -3 - }, - "Units": [ - { - "SingularName": "Voltampere", - "PluralName": "Voltamperes", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Micro", "Milli", "Kilo", "Mega", "Giga" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "VA" ] - } - ] - } - ] -} diff --git a/Common/UnitDefinitions/Capacitance.json b/Common/UnitDefinitions/Capacitance.json deleted file mode 100644 index d2f0a0bd5f..0000000000 --- a/Common/UnitDefinitions/Capacitance.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "Name": "Capacitance", - "BaseUnit": "Farad", - "XmlDocSummary": "Capacitance is the ability of a body to store an electric charge.", - "XmlDocRemarks": "Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.", - "ObsoleteText": "Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.", - "BaseDimensions": { - "L": -2, - "M": -1, - "T": 4, - "I": 2 - }, - "Units": [ - { - "SingularName": "Farad", - "PluralName": "Farads", - "BaseUnits": { - "L": "Meter", - "M": "Kilogram", - "T": "Second", - "I": "Ampere" - }, - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "F" ] - } - ] - } - ] -} diff --git a/Common/UnitDefinitions/ElectricPotentialAc.json b/Common/UnitDefinitions/ElectricPotentialAc.json deleted file mode 100644 index d1f24e7306..0000000000 --- a/Common/UnitDefinitions/ElectricPotentialAc.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "Name": "ElectricPotentialAc", - "BaseUnit": "VoltAc", - "XmlDocSummary": "The Electric Potential of a system known to use Alternating Current.", - "XmlDocRemarks": "ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.", - "ObsoleteText": "ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.", - "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 a79efda133..0000000000 --- a/Common/UnitDefinitions/ElectricPotentialDc.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "Name": "ElectricPotentialDc", - "BaseUnit": "VoltDc", - "XmlDocSummary": "The Electric Potential of a system known to use Direct Current.", - "XmlDocRemarks": "ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.", - "ObsoleteText": "ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.", - "Units": [ - { - "SingularName": "VoltDc", - "PluralName": "VoltsDc", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Micro", "Milli", "Kilo", "Mega" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "Vdc" ] - } - ] - } - ] -} diff --git a/Common/UnitDefinitions/ReactiveEnergy.json b/Common/UnitDefinitions/ReactiveEnergy.json deleted file mode 100644 index 89a648ccc9..0000000000 --- a/Common/UnitDefinitions/ReactiveEnergy.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "Name": "ReactiveEnergy", - "BaseUnit": "VoltampereReactiveHour", - "XmlDocSummary": "The Volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour.", - "XmlDocRemarks": "ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.", - "ObsoleteText": "ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.", - "BaseDimensions": { - "L": 2, - "M": 1, - "T": -2 - }, - "Units": [ - { - "SingularName": "VoltampereReactiveHour", - "PluralName": "VoltampereReactiveHours", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Kilo", "Mega" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "varh" ] - } - ] - } - ] -} diff --git a/Common/UnitDefinitions/ReactivePower.json b/Common/UnitDefinitions/ReactivePower.json deleted file mode 100644 index 48a84dd22d..0000000000 --- a/Common/UnitDefinitions/ReactivePower.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "Name": "ReactivePower", - "BaseUnit": "VoltampereReactive", - "XmlDocSummary": "Volt-ampere reactive (var) is a unit by which reactive power is expressed in an AC electric power system. Reactive power exists in an AC circuit when the current and voltage are not in phase.", - "XmlDocRemarks": "ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.", - "ObsoleteText": "ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.", - "BaseDimensions": { - "L": 2, - "M": 1, - "T": -3 - }, - "Units": [ - { - "SingularName": "VoltampereReactive", - "PluralName": "VoltamperesReactive", - "FromUnitToBaseFunc": "{x}", - "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Kilo", "Mega", "Giga" ], - "Localization": [ - { - "Culture": "en-US", - "Abbreviations": [ "var" ] - } - ] - } - ] -} diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index 31c1999660..aa5b0b6558 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -67,19 +67,6 @@ "Revolution": 15, "Tilt": 16 }, - "ApparentEnergy": { - "KilovoltampereHour": 1, - "MegavoltampereHour": 2, - "VoltampereHour": 3 - }, - "ApparentPower": { - "Gigavoltampere": 1, - "Kilovoltampere": 2, - "Megavoltampere": 3, - "Voltampere": 4, - "Microvoltampere": 6, - "Millivoltampere": 7 - }, "Area": { "Acre": 1, "Hectare": 2, @@ -142,15 +129,6 @@ "KilogramPerJoule": 2, "PoundPerMechanicalHorsepowerHour": 3 }, - "Capacitance": { - "Farad": 1, - "Kilofarad": 2, - "Megafarad": 3, - "Microfarad": 4, - "Millifarad": 5, - "Nanofarad": 6, - "Picofarad": 7 - }, "CoefficientOfThermalExpansion": { "InverseDegreeCelsius": 1, "InverseDegreeFahrenheit": 2, @@ -358,13 +336,6 @@ "Volt": 5, "Nanovolt": 11 }, - "ElectricPotentialAc": { - "KilovoltAc": 1, - "MegavoltAc": 2, - "MicrovoltAc": 3, - "MillivoltAc": 4, - "VoltAc": 5 - }, "ElectricPotentialChangeRate": { "KilovoltPerHour": 1, "KilovoltPerMicrosecond": 2, @@ -387,13 +358,6 @@ "VoltPerMinute": 19, "VoltPerSecond": 20 }, - "ElectricPotentialDc": { - "KilovoltDc": 1, - "MegavoltDc": 2, - "MicrovoltDc": 3, - "MillivoltDc": 4, - "VoltDc": 5 - }, "ElectricResistance": { "Gigaohm": 1, "Kiloohm": 2, @@ -1226,17 +1190,6 @@ "DecimalFractionPerSecond": 1, "PercentPerSecond": 2 }, - "ReactiveEnergy": { - "KilovoltampereReactiveHour": 1, - "MegavoltampereReactiveHour": 2, - "VoltampereReactiveHour": 3 - }, - "ReactivePower": { - "GigavoltampereReactive": 1, - "KilovoltampereReactive": 2, - "MegavoltampereReactive": 3, - "VoltampereReactive": 4 - }, "ReciprocalArea": { "InverseSquareCentimeter": 1, "InverseSquareDecimeter": 2, diff --git a/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/ApparentEnergy.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/ApparentEnergy.nfproj deleted file mode 100644 index 60d18e1638..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/ApparentEnergy.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {6f80e841-e953-bc39-6670-8711f2ad9d18} - Library - Properties - 512 - UnitsNet - UnitsNet.ApparentEnergy - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/UnitsNet.NanoFramework.ApparentEnergy.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/UnitsNet.NanoFramework.ApparentEnergy.nuspec deleted file mode 100644 index 6ed1479482..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/UnitsNet.NanoFramework.ApparentEnergy.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ApparentEnergy - 6.0.0-pre012 - Units.NET ApparentEnergy - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - https://github.com/angularsen/UnitsNet - false - Adds ApparentEnergy 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 apparentenergy unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/packages.config deleted file mode 100644 index 313a8dccdf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ApparentEnergy/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/ApparentPower.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/ApparentPower.nfproj deleted file mode 100644 index f82107c647..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/ApparentPower.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {88b9a61a-b21b-97cc-ef89-78d1e3ff7767} - Library - Properties - 512 - UnitsNet - UnitsNet.ApparentPower - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/UnitsNet.NanoFramework.ApparentPower.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/UnitsNet.NanoFramework.ApparentPower.nuspec deleted file mode 100644 index d729b6f4ac..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/UnitsNet.NanoFramework.ApparentPower.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ApparentPower - 6.0.0-pre012 - Units.NET ApparentPower - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - https://github.com/angularsen/UnitsNet - false - Adds ApparentPower 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 apparentpower unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/packages.config deleted file mode 100644 index 313a8dccdf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ApparentPower/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Capacitance/Capacitance.nfproj b/UnitsNet.NanoFramework/GeneratedCode/Capacitance/Capacitance.nfproj deleted file mode 100644 index 3b421513e0..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Capacitance/Capacitance.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94} - Library - Properties - 512 - UnitsNet - UnitsNet.Capacitance - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Capacitance/UnitsNet.NanoFramework.Capacitance.nuspec b/UnitsNet.NanoFramework/GeneratedCode/Capacitance/UnitsNet.NanoFramework.Capacitance.nuspec deleted file mode 100644 index 883f737d9a..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Capacitance/UnitsNet.NanoFramework.Capacitance.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.Capacitance - 6.0.0-pre012 - Units.NET Capacitance - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - https://github.com/angularsen/UnitsNet - false - Adds Capacitance 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 capacitance unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Capacitance/packages.config b/UnitsNet.NanoFramework/GeneratedCode/Capacitance/packages.config deleted file mode 100644 index 313a8dccdf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Capacitance/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/ElectricPotentialAc.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/ElectricPotentialAc.nfproj deleted file mode 100644 index 130a015fdd..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.15.5\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 bb0a48a3e9..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialAc/UnitsNet.NanoFramework.ElectricPotentialAc.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ElectricPotentialAc - 6.0.0-pre012 - Units.NET ElectricPotentialAc - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - 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 313a8dccdf..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 197f9efd60..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.15.5\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 f36f5c453b..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/UnitsNet.NanoFramework.ElectricPotentialDc.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ElectricPotentialDc - 6.0.0-pre012 - Units.NET ElectricPotentialDc - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - 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 313a8dccdf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ElectricPotentialDc/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs deleted file mode 100644 index 912262b2b7..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ /dev/null @@ -1,185 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// A unit for expressing the integral of apparent power over time, equal to the product of 1 volt-ampere and 1 hour, or to 3600 joules. - /// - /// - /// ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version. - /// - [Obsolete("ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.")] - public struct ApparentEnergy - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly ApparentEnergyUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public ApparentEnergyUnit Unit => _unit; - - /// - /// 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. - public ApparentEnergy(double value, ApparentEnergyUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of ApparentEnergy, which is Second. All conversions go via this value. - /// - public static ApparentEnergyUnit BaseUnit { get; } = ApparentEnergyUnit.VoltampereHour; - - /// - /// Represents the largest possible value of ApparentEnergy. - /// - public static ApparentEnergy MaxValue { get; } = new ApparentEnergy(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of ApparentEnergy. - /// - public static ApparentEnergy MinValue { get; } = new ApparentEnergy(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static ApparentEnergy Zero { get; } = new ApparentEnergy(0, BaseUnit); - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltampereHours => As(ApparentEnergyUnit.KilovoltampereHour); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltampereHours => As(ApparentEnergyUnit.MegavoltampereHour); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltampereHours => As(ApparentEnergyUnit.VoltampereHour); - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ApparentEnergy FromKilovoltampereHours(double kilovoltamperehours) => new ApparentEnergy(kilovoltamperehours, ApparentEnergyUnit.KilovoltampereHour); - - /// - /// Creates a from . - /// - public static ApparentEnergy FromMegavoltampereHours(double megavoltamperehours) => new ApparentEnergy(megavoltamperehours, ApparentEnergyUnit.MegavoltampereHour); - - /// - /// Creates a from . - /// - public static ApparentEnergy FromVoltampereHours(double voltamperehours) => new ApparentEnergy(voltamperehours, ApparentEnergyUnit.VoltampereHour); - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ApparentEnergy unit value. - public static ApparentEnergy From(double value, ApparentEnergyUnit fromUnit) - { - return new ApparentEnergy(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ApparentEnergyUnit unit) => GetValueAs(unit); - - /// - /// Converts this ApparentEnergy to another ApparentEnergy with the unit representation . - /// - /// A ApparentEnergy with the specified unit. - public ApparentEnergy ToUnit(ApparentEnergyUnit unit) - { - var convertedValue = GetValueAs(unit); - return new ApparentEnergy(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - ApparentEnergyUnit.KilovoltampereHour => (_value) * 1e3d, - ApparentEnergyUnit.MegavoltampereHour => (_value) * 1e6d, - ApparentEnergyUnit.VoltampereHour => _value, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(ApparentEnergyUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - ApparentEnergyUnit.KilovoltampereHour => (baseUnitValue) / 1e3d, - ApparentEnergyUnit.MegavoltampereHour => (baseUnitValue) / 1e6d, - ApparentEnergyUnit.VoltampereHour => baseUnitValue, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs deleted file mode 100644 index 8b15504592..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs +++ /dev/null @@ -1,221 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. Apparent power is the product of the root-mean-square of voltage and current. - /// - /// - /// ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version. - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public struct ApparentPower - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly ApparentPowerUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public ApparentPowerUnit Unit => _unit; - - /// - /// 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. - public ApparentPower(double value, ApparentPowerUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of ApparentPower, which is Second. All conversions go via this value. - /// - public static ApparentPowerUnit BaseUnit { get; } = ApparentPowerUnit.Voltampere; - - /// - /// Represents the largest possible value of ApparentPower. - /// - public static ApparentPower MaxValue { get; } = new ApparentPower(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of ApparentPower. - /// - public static ApparentPower MinValue { get; } = new ApparentPower(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static ApparentPower Zero { get; } = new ApparentPower(0, BaseUnit); - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double Gigavoltamperes => As(ApparentPowerUnit.Gigavoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Kilovoltamperes => As(ApparentPowerUnit.Kilovoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Megavoltamperes => As(ApparentPowerUnit.Megavoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Microvoltamperes => As(ApparentPowerUnit.Microvoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Millivoltamperes => As(ApparentPowerUnit.Millivoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Voltamperes => As(ApparentPowerUnit.Voltampere); - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ApparentPower FromGigavoltamperes(double gigavoltamperes) => new ApparentPower(gigavoltamperes, ApparentPowerUnit.Gigavoltampere); - - /// - /// Creates a from . - /// - public static ApparentPower FromKilovoltamperes(double kilovoltamperes) => new ApparentPower(kilovoltamperes, ApparentPowerUnit.Kilovoltampere); - - /// - /// Creates a from . - /// - public static ApparentPower FromMegavoltamperes(double megavoltamperes) => new ApparentPower(megavoltamperes, ApparentPowerUnit.Megavoltampere); - - /// - /// Creates a from . - /// - public static ApparentPower FromMicrovoltamperes(double microvoltamperes) => new ApparentPower(microvoltamperes, ApparentPowerUnit.Microvoltampere); - - /// - /// Creates a from . - /// - public static ApparentPower FromMillivoltamperes(double millivoltamperes) => new ApparentPower(millivoltamperes, ApparentPowerUnit.Millivoltampere); - - /// - /// Creates a from . - /// - public static ApparentPower FromVoltamperes(double voltamperes) => new ApparentPower(voltamperes, ApparentPowerUnit.Voltampere); - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ApparentPower unit value. - public static ApparentPower From(double value, ApparentPowerUnit fromUnit) - { - return new ApparentPower(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ApparentPowerUnit unit) => GetValueAs(unit); - - /// - /// Converts this ApparentPower to another ApparentPower with the unit representation . - /// - /// A ApparentPower with the specified unit. - public ApparentPower ToUnit(ApparentPowerUnit unit) - { - var convertedValue = GetValueAs(unit); - return new ApparentPower(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - ApparentPowerUnit.Gigavoltampere => (_value) * 1e9d, - ApparentPowerUnit.Kilovoltampere => (_value) * 1e3d, - ApparentPowerUnit.Megavoltampere => (_value) * 1e6d, - ApparentPowerUnit.Microvoltampere => (_value) * 1e-6d, - ApparentPowerUnit.Millivoltampere => (_value) * 1e-3d, - ApparentPowerUnit.Voltampere => _value, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(ApparentPowerUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - ApparentPowerUnit.Gigavoltampere => (baseUnitValue) / 1e9d, - ApparentPowerUnit.Kilovoltampere => (baseUnitValue) / 1e3d, - ApparentPowerUnit.Megavoltampere => (baseUnitValue) / 1e6d, - ApparentPowerUnit.Microvoltampere => (baseUnitValue) / 1e-6d, - ApparentPowerUnit.Millivoltampere => (baseUnitValue) / 1e-3d, - ApparentPowerUnit.Voltampere => baseUnitValue, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs deleted file mode 100644 index 68886a6e22..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs +++ /dev/null @@ -1,233 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// Capacitance is the ability of a body to store an electric charge. - /// - /// - /// Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version. - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public struct Capacitance - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly CapacitanceUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public CapacitanceUnit Unit => _unit; - - /// - /// 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. - public Capacitance(double value, CapacitanceUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of Capacitance, which is Second. All conversions go via this value. - /// - public static CapacitanceUnit BaseUnit { get; } = CapacitanceUnit.Farad; - - /// - /// Represents the largest possible value of Capacitance. - /// - public static Capacitance MaxValue { get; } = new Capacitance(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of Capacitance. - /// - public static Capacitance MinValue { get; } = new Capacitance(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static Capacitance Zero { get; } = new Capacitance(0, BaseUnit); - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double Farads => As(CapacitanceUnit.Farad); - - /// - /// Gets a value of this quantity converted into - /// - public double Kilofarads => As(CapacitanceUnit.Kilofarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Megafarads => As(CapacitanceUnit.Megafarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Microfarads => As(CapacitanceUnit.Microfarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Millifarads => As(CapacitanceUnit.Millifarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Nanofarads => As(CapacitanceUnit.Nanofarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Picofarads => As(CapacitanceUnit.Picofarad); - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static Capacitance FromFarads(double farads) => new Capacitance(farads, CapacitanceUnit.Farad); - - /// - /// Creates a from . - /// - public static Capacitance FromKilofarads(double kilofarads) => new Capacitance(kilofarads, CapacitanceUnit.Kilofarad); - - /// - /// Creates a from . - /// - public static Capacitance FromMegafarads(double megafarads) => new Capacitance(megafarads, CapacitanceUnit.Megafarad); - - /// - /// Creates a from . - /// - public static Capacitance FromMicrofarads(double microfarads) => new Capacitance(microfarads, CapacitanceUnit.Microfarad); - - /// - /// Creates a from . - /// - public static Capacitance FromMillifarads(double millifarads) => new Capacitance(millifarads, CapacitanceUnit.Millifarad); - - /// - /// Creates a from . - /// - public static Capacitance FromNanofarads(double nanofarads) => new Capacitance(nanofarads, CapacitanceUnit.Nanofarad); - - /// - /// Creates a from . - /// - public static Capacitance FromPicofarads(double picofarads) => new Capacitance(picofarads, CapacitanceUnit.Picofarad); - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// Capacitance unit value. - public static Capacitance From(double value, CapacitanceUnit fromUnit) - { - return new Capacitance(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(CapacitanceUnit unit) => GetValueAs(unit); - - /// - /// Converts this Capacitance to another Capacitance with the unit representation . - /// - /// A Capacitance with the specified unit. - public Capacitance ToUnit(CapacitanceUnit unit) - { - var convertedValue = GetValueAs(unit); - return new Capacitance(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - CapacitanceUnit.Farad => _value, - CapacitanceUnit.Kilofarad => (_value) * 1e3d, - CapacitanceUnit.Megafarad => (_value) * 1e6d, - CapacitanceUnit.Microfarad => (_value) * 1e-6d, - CapacitanceUnit.Millifarad => (_value) * 1e-3d, - CapacitanceUnit.Nanofarad => (_value) * 1e-9d, - CapacitanceUnit.Picofarad => (_value) * 1e-12d, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(CapacitanceUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - CapacitanceUnit.Farad => baseUnitValue, - CapacitanceUnit.Kilofarad => (baseUnitValue) / 1e3d, - CapacitanceUnit.Megafarad => (baseUnitValue) / 1e6d, - CapacitanceUnit.Microfarad => (baseUnitValue) / 1e-6d, - CapacitanceUnit.Millifarad => (baseUnitValue) / 1e-3d, - CapacitanceUnit.Nanofarad => (baseUnitValue) / 1e-9d, - CapacitanceUnit.Picofarad => (baseUnitValue) / 1e-12d, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs deleted file mode 100644 index 8dbac64546..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ /dev/null @@ -1,209 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// The Electric Potential of a system known to use Alternating Current. - /// - /// - /// ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public struct ElectricPotentialAc - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly ElectricPotentialAcUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public ElectricPotentialAcUnit Unit => _unit; - - /// - /// 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. - public ElectricPotentialAc(double value, ElectricPotentialAcUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of ElectricPotentialAc, which is Second. All conversions go via this value. - /// - public static ElectricPotentialAcUnit BaseUnit { get; } = ElectricPotentialAcUnit.VoltAc; - - /// - /// Represents the largest possible value of ElectricPotentialAc. - /// - public static ElectricPotentialAc MaxValue { get; } = new ElectricPotentialAc(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of ElectricPotentialAc. - /// - public static ElectricPotentialAc MinValue { get; } = new ElectricPotentialAc(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static ElectricPotentialAc Zero { get; } = new ElectricPotentialAc(0, BaseUnit); - #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 Factory Methods - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromKilovoltsAc(double kilovoltsac) => new ElectricPotentialAc(kilovoltsac, ElectricPotentialAcUnit.KilovoltAc); - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromMegavoltsAc(double megavoltsac) => new ElectricPotentialAc(megavoltsac, ElectricPotentialAcUnit.MegavoltAc); - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromMicrovoltsAc(double microvoltsac) => new ElectricPotentialAc(microvoltsac, ElectricPotentialAcUnit.MicrovoltAc); - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromMillivoltsAc(double millivoltsac) => new ElectricPotentialAc(millivoltsac, ElectricPotentialAcUnit.MillivoltAc); - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromVoltsAc(double voltsac) => new ElectricPotentialAc(voltsac, 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(double value, ElectricPotentialAcUnit fromUnit) - { - return new ElectricPotentialAc(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ElectricPotentialAcUnit unit) => GetValueAs(unit); - - /// - /// Converts this ElectricPotentialAc to another ElectricPotentialAc with the unit representation . - /// - /// A ElectricPotentialAc with the specified unit. - public ElectricPotentialAc ToUnit(ElectricPotentialAcUnit unit) - { - var convertedValue = GetValueAs(unit); - return new ElectricPotentialAc(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - ElectricPotentialAcUnit.KilovoltAc => (_value) * 1e3d, - ElectricPotentialAcUnit.MegavoltAc => (_value) * 1e6d, - ElectricPotentialAcUnit.MicrovoltAc => (_value) * 1e-6d, - ElectricPotentialAcUnit.MillivoltAc => (_value) * 1e-3d, - ElectricPotentialAcUnit.VoltAc => _value, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(ElectricPotentialAcUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - ElectricPotentialAcUnit.KilovoltAc => (baseUnitValue) / 1e3d, - ElectricPotentialAcUnit.MegavoltAc => (baseUnitValue) / 1e6d, - ElectricPotentialAcUnit.MicrovoltAc => (baseUnitValue) / 1e-6d, - ElectricPotentialAcUnit.MillivoltAc => (baseUnitValue) / 1e-3d, - ElectricPotentialAcUnit.VoltAc => baseUnitValue, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs deleted file mode 100644 index 327652c72f..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ /dev/null @@ -1,209 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// The Electric Potential of a system known to use Direct Current. - /// - /// - /// ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public struct ElectricPotentialDc - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly ElectricPotentialDcUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public ElectricPotentialDcUnit Unit => _unit; - - /// - /// 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. - public ElectricPotentialDc(double value, ElectricPotentialDcUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of ElectricPotentialDc, which is Second. All conversions go via this value. - /// - public static ElectricPotentialDcUnit BaseUnit { get; } = ElectricPotentialDcUnit.VoltDc; - - /// - /// Represents the largest possible value of ElectricPotentialDc. - /// - public static ElectricPotentialDc MaxValue { get; } = new ElectricPotentialDc(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of ElectricPotentialDc. - /// - public static ElectricPotentialDc MinValue { get; } = new ElectricPotentialDc(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static ElectricPotentialDc Zero { get; } = new ElectricPotentialDc(0, BaseUnit); - #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 Factory Methods - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromKilovoltsDc(double kilovoltsdc) => new ElectricPotentialDc(kilovoltsdc, ElectricPotentialDcUnit.KilovoltDc); - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromMegavoltsDc(double megavoltsdc) => new ElectricPotentialDc(megavoltsdc, ElectricPotentialDcUnit.MegavoltDc); - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromMicrovoltsDc(double microvoltsdc) => new ElectricPotentialDc(microvoltsdc, ElectricPotentialDcUnit.MicrovoltDc); - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromMillivoltsDc(double millivoltsdc) => new ElectricPotentialDc(millivoltsdc, ElectricPotentialDcUnit.MillivoltDc); - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromVoltsDc(double voltsdc) => new ElectricPotentialDc(voltsdc, 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(double value, ElectricPotentialDcUnit fromUnit) - { - return new ElectricPotentialDc(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ElectricPotentialDcUnit unit) => GetValueAs(unit); - - /// - /// Converts this ElectricPotentialDc to another ElectricPotentialDc with the unit representation . - /// - /// A ElectricPotentialDc with the specified unit. - public ElectricPotentialDc ToUnit(ElectricPotentialDcUnit unit) - { - var convertedValue = GetValueAs(unit); - return new ElectricPotentialDc(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - ElectricPotentialDcUnit.KilovoltDc => (_value) * 1e3d, - ElectricPotentialDcUnit.MegavoltDc => (_value) * 1e6d, - ElectricPotentialDcUnit.MicrovoltDc => (_value) * 1e-6d, - ElectricPotentialDcUnit.MillivoltDc => (_value) * 1e-3d, - ElectricPotentialDcUnit.VoltDc => _value, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(ElectricPotentialDcUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - ElectricPotentialDcUnit.KilovoltDc => (baseUnitValue) / 1e3d, - ElectricPotentialDcUnit.MegavoltDc => (baseUnitValue) / 1e6d, - ElectricPotentialDcUnit.MicrovoltDc => (baseUnitValue) / 1e-6d, - ElectricPotentialDcUnit.MillivoltDc => (baseUnitValue) / 1e-3d, - ElectricPotentialDcUnit.VoltDc => baseUnitValue, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactiveEnergy.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactiveEnergy.g.cs deleted file mode 100644 index a1a2800d3d..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ /dev/null @@ -1,185 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// The Volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour. - /// - /// - /// ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version. - /// - [Obsolete("ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.")] - public struct ReactiveEnergy - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly ReactiveEnergyUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public ReactiveEnergyUnit Unit => _unit; - - /// - /// 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. - public ReactiveEnergy(double value, ReactiveEnergyUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of ReactiveEnergy, which is Second. All conversions go via this value. - /// - public static ReactiveEnergyUnit BaseUnit { get; } = ReactiveEnergyUnit.VoltampereReactiveHour; - - /// - /// Represents the largest possible value of ReactiveEnergy. - /// - public static ReactiveEnergy MaxValue { get; } = new ReactiveEnergy(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of ReactiveEnergy. - /// - public static ReactiveEnergy MinValue { get; } = new ReactiveEnergy(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static ReactiveEnergy Zero { get; } = new ReactiveEnergy(0, BaseUnit); - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltampereReactiveHours => As(ReactiveEnergyUnit.KilovoltampereReactiveHour); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltampereReactiveHours => As(ReactiveEnergyUnit.MegavoltampereReactiveHour); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltampereReactiveHours => As(ReactiveEnergyUnit.VoltampereReactiveHour); - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ReactiveEnergy FromKilovoltampereReactiveHours(double kilovoltamperereactivehours) => new ReactiveEnergy(kilovoltamperereactivehours, ReactiveEnergyUnit.KilovoltampereReactiveHour); - - /// - /// Creates a from . - /// - public static ReactiveEnergy FromMegavoltampereReactiveHours(double megavoltamperereactivehours) => new ReactiveEnergy(megavoltamperereactivehours, ReactiveEnergyUnit.MegavoltampereReactiveHour); - - /// - /// Creates a from . - /// - public static ReactiveEnergy FromVoltampereReactiveHours(double voltamperereactivehours) => new ReactiveEnergy(voltamperereactivehours, ReactiveEnergyUnit.VoltampereReactiveHour); - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ReactiveEnergy unit value. - public static ReactiveEnergy From(double value, ReactiveEnergyUnit fromUnit) - { - return new ReactiveEnergy(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ReactiveEnergyUnit unit) => GetValueAs(unit); - - /// - /// Converts this ReactiveEnergy to another ReactiveEnergy with the unit representation . - /// - /// A ReactiveEnergy with the specified unit. - public ReactiveEnergy ToUnit(ReactiveEnergyUnit unit) - { - var convertedValue = GetValueAs(unit); - return new ReactiveEnergy(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - ReactiveEnergyUnit.KilovoltampereReactiveHour => (_value) * 1e3d, - ReactiveEnergyUnit.MegavoltampereReactiveHour => (_value) * 1e6d, - ReactiveEnergyUnit.VoltampereReactiveHour => _value, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(ReactiveEnergyUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - ReactiveEnergyUnit.KilovoltampereReactiveHour => (baseUnitValue) / 1e3d, - ReactiveEnergyUnit.MegavoltampereReactiveHour => (baseUnitValue) / 1e6d, - ReactiveEnergyUnit.VoltampereReactiveHour => baseUnitValue, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs deleted file mode 100644 index 267d79a688..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs +++ /dev/null @@ -1,197 +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 UnitsNet.Units; - -namespace UnitsNet -{ - /// - /// - /// Volt-ampere reactive (var) is a unit by which reactive power is expressed in an AC electric power system. Reactive power exists in an AC circuit when the current and voltage are not in phase. - /// - /// - /// ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version. - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - public struct ReactivePower - { - /// - /// The numeric value this quantity was constructed with. - /// - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - private readonly ReactivePowerUnit _unit; - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - public ReactivePowerUnit Unit => _unit; - - /// - /// 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. - public ReactivePower(double value, ReactivePowerUnit unit) - { - _value = value; - _unit = unit; - } - - /// - /// The base unit of ReactivePower, which is Second. All conversions go via this value. - /// - public static ReactivePowerUnit BaseUnit { get; } = ReactivePowerUnit.VoltampereReactive; - - /// - /// Represents the largest possible value of ReactivePower. - /// - public static ReactivePower MaxValue { get; } = new ReactivePower(double.MaxValue, BaseUnit); - - /// - /// Represents the smallest possible value of ReactivePower. - /// - public static ReactivePower MinValue { get; } = new ReactivePower(double.MinValue, BaseUnit); - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Second. - /// - public static ReactivePower Zero { get; } = new ReactivePower(0, BaseUnit); - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double GigavoltamperesReactive => As(ReactivePowerUnit.GigavoltampereReactive); - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltamperesReactive => As(ReactivePowerUnit.KilovoltampereReactive); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltamperesReactive => As(ReactivePowerUnit.MegavoltampereReactive); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltamperesReactive => As(ReactivePowerUnit.VoltampereReactive); - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ReactivePower FromGigavoltamperesReactive(double gigavoltamperesreactive) => new ReactivePower(gigavoltamperesreactive, ReactivePowerUnit.GigavoltampereReactive); - - /// - /// Creates a from . - /// - public static ReactivePower FromKilovoltamperesReactive(double kilovoltamperesreactive) => new ReactivePower(kilovoltamperesreactive, ReactivePowerUnit.KilovoltampereReactive); - - /// - /// Creates a from . - /// - public static ReactivePower FromMegavoltamperesReactive(double megavoltamperesreactive) => new ReactivePower(megavoltamperesreactive, ReactivePowerUnit.MegavoltampereReactive); - - /// - /// Creates a from . - /// - public static ReactivePower FromVoltamperesReactive(double voltamperesreactive) => new ReactivePower(voltamperesreactive, ReactivePowerUnit.VoltampereReactive); - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ReactivePower unit value. - public static ReactivePower From(double value, ReactivePowerUnit fromUnit) - { - return new ReactivePower(value, fromUnit); - } - - #endregion - - #region Conversion Methods - - /// - /// Convert to the unit representation . - /// - /// Value converted to the specified unit. - public double As(ReactivePowerUnit unit) => GetValueAs(unit); - - /// - /// Converts this ReactivePower to another ReactivePower with the unit representation . - /// - /// A ReactivePower with the specified unit. - public ReactivePower ToUnit(ReactivePowerUnit unit) - { - var convertedValue = GetValueAs(unit); - return new ReactivePower(convertedValue, unit); - } - - /// - /// Converts the current value + unit to the base unit. - /// This is typically the first step in converting from one unit to another. - /// - /// The value in the base unit representation. - private double GetValueInBaseUnit() - { - return Unit switch - { - ReactivePowerUnit.GigavoltampereReactive => (_value) * 1e9d, - ReactivePowerUnit.KilovoltampereReactive => (_value) * 1e3d, - ReactivePowerUnit.MegavoltampereReactive => (_value) * 1e6d, - ReactivePowerUnit.VoltampereReactive => _value, - _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") - }; - } - - private double GetValueAs(ReactivePowerUnit unit) - { - if (Unit == unit) - return _value; - - var baseUnitValue = GetValueInBaseUnit(); - - return unit switch - { - ReactivePowerUnit.GigavoltampereReactive => (baseUnitValue) / 1e9d, - ReactivePowerUnit.KilovoltampereReactive => (baseUnitValue) / 1e3d, - ReactivePowerUnit.MegavoltampereReactive => (baseUnitValue) / 1e6d, - ReactivePowerUnit.VoltampereReactive => baseUnitValue, - _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") - }; - } - - #endregion - } -} - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/ReactiveEnergy.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/ReactiveEnergy.nfproj deleted file mode 100644 index 14698a4a67..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/ReactiveEnergy.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {64c918a4-27a8-3e9c-e81f-6917f0edde90} - Library - Properties - 512 - UnitsNet - UnitsNet.ReactiveEnergy - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/UnitsNet.NanoFramework.ReactiveEnergy.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/UnitsNet.NanoFramework.ReactiveEnergy.nuspec deleted file mode 100644 index fa2331ec83..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/UnitsNet.NanoFramework.ReactiveEnergy.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ReactiveEnergy - 6.0.0-pre012 - Units.NET ReactiveEnergy - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - https://github.com/angularsen/UnitsNet - false - Adds ReactiveEnergy 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 reactiveenergy unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/packages.config deleted file mode 100644 index 313a8dccdf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ReactiveEnergy/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/ReactivePower.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/ReactivePower.nfproj deleted file mode 100644 index 10a7ed64be..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/ReactivePower.nfproj +++ /dev/null @@ -1,42 +0,0 @@ - - - - $(MSBuildExtensionsPath)\nanoFramework\v1.0\ - - - - Debug - AnyCPU - {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {6821b87e-65eb-bfdb-8fdc-8b183edf739e} - Library - Properties - 512 - UnitsNet - UnitsNet.ReactivePower - v1.0 - bin\$(Configuration)\$(AssemblyName).xml - - - - - - - - - - ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll - True - True - - - - - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/UnitsNet.NanoFramework.ReactivePower.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/UnitsNet.NanoFramework.ReactivePower.nuspec deleted file mode 100644 index a84c733438..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/UnitsNet.NanoFramework.ReactivePower.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - UnitsNet.nanoFramework.ReactivePower - 6.0.0-pre012 - Units.NET ReactivePower - nanoFramework - Andreas Gullberg Larsen,nanoframework - UnitsNet - MIT-0 - https://github.com/angularsen/UnitsNet - false - Adds ReactivePower 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 reactivepower unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable - - - - - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/packages.config deleted file mode 100644 index 313a8dccdf..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/ReactivePower/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ApparentEnergyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ApparentEnergyUnit.g.cs deleted file mode 100644 index 2a8c1aba5b..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ApparentEnergyUnit.g.cs +++ /dev/null @@ -1,34 +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 ApparentEnergyUnit - { - KilovoltampereHour = 1, - MegavoltampereHour = 2, - VoltampereHour = 3, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ApparentPowerUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ApparentPowerUnit.g.cs deleted file mode 100644 index 856789bbdd..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ApparentPowerUnit.g.cs +++ /dev/null @@ -1,37 +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 ApparentPowerUnit - { - Gigavoltampere = 1, - Kilovoltampere = 2, - Megavoltampere = 3, - Microvoltampere = 6, - Millivoltampere = 7, - Voltampere = 4, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/CapacitanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/CapacitanceUnit.g.cs deleted file mode 100644 index a76cc8f2d8..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/CapacitanceUnit.g.cs +++ /dev/null @@ -1,38 +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 CapacitanceUnit - { - Farad = 1, - Kilofarad = 2, - Megafarad = 3, - Microfarad = 4, - Millifarad = 5, - Nanofarad = 6, - Picofarad = 7, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs deleted file mode 100644 index ada8068172..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialAcUnit.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 ElectricPotentialAcUnit - { - KilovoltAc = 1, - MegavoltAc = 2, - MicrovoltAc = 3, - MillivoltAc = 4, - VoltAc = 5, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricPotentialDcUnit.g.cs deleted file mode 100644 index 224c9c4c30..0000000000 --- a/UnitsNet.NanoFramework/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.NanoFramework/GeneratedCode/Units/ReactiveEnergyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ReactiveEnergyUnit.g.cs deleted file mode 100644 index d48f6482a1..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ReactiveEnergyUnit.g.cs +++ /dev/null @@ -1,34 +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 ReactiveEnergyUnit - { - KilovoltampereReactiveHour = 1, - MegavoltampereReactiveHour = 2, - VoltampereReactiveHour = 3, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ReactivePowerUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ReactivePowerUnit.g.cs deleted file mode 100644 index 32e7a9ede9..0000000000 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ReactivePowerUnit.g.cs +++ /dev/null @@ -1,35 +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 ReactivePowerUnit - { - GigavoltampereReactive = 1, - KilovoltampereReactive = 2, - MegavoltampereReactive = 3, - VoltampereReactive = 4, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index 85f5660d09..8b3d31124e 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -12,10 +12,6 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "AmplitudeRatio", "Amplitude EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Angle", "Angle\Angle.nfproj", "{4b036819-f813-0c4d-3e44-1fcc8b5f3ec7}" EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ApparentEnergy", "ApparentEnergy\ApparentEnergy.nfproj", "{6f80e841-e953-bc39-6670-8711f2ad9d18}" -EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ApparentPower", "ApparentPower\ApparentPower.nfproj", "{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}" -EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Area", "Area\Area.nfproj", "{04c24d02-bad7-a877-ff9b-a36a886c9633}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "AreaDensity", "AreaDensity\AreaDensity.nfproj", "{92ff1332-bf34-943e-a58d-8a76746d879e}" @@ -26,8 +22,6 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "BitRate", "BitRate\BitRate. EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "BrakeSpecificFuelConsumption", "BrakeSpecificFuelConsumption\BrakeSpecificFuelConsumption.nfproj", "{085145f2-2b8f-4d09-5290-c14cdcd452bf}" EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Capacitance", "Capacitance\Capacitance.nfproj", "{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}" -EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "CoefficientOfThermalExpansion", "CoefficientOfThermalExpansion\CoefficientOfThermalExpansion.nfproj", "{a9514ce6-d4e7-88ca-051e-e9e53610c519}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Compressibility", "Compressibility\Compressibility.nfproj", "{daf647be-be87-88b9-ee92-dece21fe0dff}" @@ -70,12 +64,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}") = "ElectricReactance", "ElectricReactance\ElectricReactance.nfproj", "{e3d3c1e3-aaa3-5d40-472e-ae837457cf73}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricReactiveEnergy", "ElectricReactiveEnergy\ElectricReactiveEnergy.nfproj", "{9f892c4e-26c2-1420-a73c-08138c8f6ca2}" @@ -200,10 +190,6 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Ratio", "Ratio\Ratio.nfproj EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "RatioChangeRate", "RatioChangeRate\RatioChangeRate.nfproj", "{c028861d-f9e8-8231-2b6a-bc3b3fba349c}" EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReactiveEnergy", "ReactiveEnergy\ReactiveEnergy.nfproj", "{64c918a4-27a8-3e9c-e81f-6917f0edde90}" -EndProject -Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReactivePower", "ReactivePower\ReactivePower.nfproj", "{6821b87e-65eb-bfdb-8fdc-8b183edf739e}" -EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReciprocalArea", "ReciprocalArea\ReciprocalArea.nfproj", "{30fee563-a3f0-9c50-bfd1-1af707aaf3c4}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ReciprocalLength", "ReciprocalLength\ReciprocalLength.nfproj", "{83d6c79a-c71a-d467-284c-28edbbd059d2}" @@ -304,18 +290,6 @@ Global {4b036819-f813-0c4d-3e44-1fcc8b5f3ec7}.Release|Any CPU.ActiveCfg = Release|Any CPU {4b036819-f813-0c4d-3e44-1fcc8b5f3ec7}.Release|Any CPU.Build.0 = Release|Any CPU {4b036819-f813-0c4d-3e44-1fcc8b5f3ec7}.Release|Any CPU.Deploy.0 = Release|Any CPU -{6f80e841-e953-bc39-6670-8711f2ad9d18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{6f80e841-e953-bc39-6670-8711f2ad9d18}.Debug|Any CPU.Build.0 = Debug|Any CPU -{6f80e841-e953-bc39-6670-8711f2ad9d18}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{6f80e841-e953-bc39-6670-8711f2ad9d18}.Release|Any CPU.ActiveCfg = Release|Any CPU -{6f80e841-e953-bc39-6670-8711f2ad9d18}.Release|Any CPU.Build.0 = Release|Any CPU -{6f80e841-e953-bc39-6670-8711f2ad9d18}.Release|Any CPU.Deploy.0 = Release|Any CPU -{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}.Debug|Any CPU.Build.0 = Debug|Any CPU -{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}.Release|Any CPU.ActiveCfg = Release|Any CPU -{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}.Release|Any CPU.Build.0 = Release|Any CPU -{88b9a61a-b21b-97cc-ef89-78d1e3ff7767}.Release|Any CPU.Deploy.0 = Release|Any CPU {04c24d02-bad7-a877-ff9b-a36a886c9633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {04c24d02-bad7-a877-ff9b-a36a886c9633}.Debug|Any CPU.Build.0 = Debug|Any CPU {04c24d02-bad7-a877-ff9b-a36a886c9633}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -346,12 +320,6 @@ Global {085145f2-2b8f-4d09-5290-c14cdcd452bf}.Release|Any CPU.ActiveCfg = Release|Any CPU {085145f2-2b8f-4d09-5290-c14cdcd452bf}.Release|Any CPU.Build.0 = Release|Any CPU {085145f2-2b8f-4d09-5290-c14cdcd452bf}.Release|Any CPU.Deploy.0 = Release|Any CPU -{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}.Debug|Any CPU.Build.0 = Debug|Any CPU -{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}.Release|Any CPU.ActiveCfg = Release|Any CPU -{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}.Release|Any CPU.Build.0 = Release|Any CPU -{c1351fc7-d3d8-c3ce-0715-ad8e18ab8c94}.Release|Any CPU.Deploy.0 = Release|Any CPU {a9514ce6-d4e7-88ca-051e-e9e53610c519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {a9514ce6-d4e7-88ca-051e-e9e53610c519}.Debug|Any CPU.Build.0 = Debug|Any CPU {a9514ce6-d4e7-88ca-051e-e9e53610c519}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -478,24 +446,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 {e3d3c1e3-aaa3-5d40-472e-ae837457cf73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {e3d3c1e3-aaa3-5d40-472e-ae837457cf73}.Debug|Any CPU.Build.0 = Debug|Any CPU {e3d3c1e3-aaa3-5d40-472e-ae837457cf73}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -868,18 +824,6 @@ Global {c028861d-f9e8-8231-2b6a-bc3b3fba349c}.Release|Any CPU.ActiveCfg = Release|Any CPU {c028861d-f9e8-8231-2b6a-bc3b3fba349c}.Release|Any CPU.Build.0 = Release|Any CPU {c028861d-f9e8-8231-2b6a-bc3b3fba349c}.Release|Any CPU.Deploy.0 = Release|Any CPU -{64c918a4-27a8-3e9c-e81f-6917f0edde90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{64c918a4-27a8-3e9c-e81f-6917f0edde90}.Debug|Any CPU.Build.0 = Debug|Any CPU -{64c918a4-27a8-3e9c-e81f-6917f0edde90}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{64c918a4-27a8-3e9c-e81f-6917f0edde90}.Release|Any CPU.ActiveCfg = Release|Any CPU -{64c918a4-27a8-3e9c-e81f-6917f0edde90}.Release|Any CPU.Build.0 = Release|Any CPU -{64c918a4-27a8-3e9c-e81f-6917f0edde90}.Release|Any CPU.Deploy.0 = Release|Any CPU -{6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Debug|Any CPU.Build.0 = Debug|Any CPU -{6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Debug|Any CPU.Deploy.0 = Debug|Any CPU -{6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Release|Any CPU.ActiveCfg = Release|Any CPU -{6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Release|Any CPU.Build.0 = Release|Any CPU -{6821b87e-65eb-bfdb-8fdc-8b183edf739e}.Release|Any CPU.Deploy.0 = Release|Any CPU {30fee563-a3f0-9c50-bfd1-1af707aaf3c4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {30fee563-a3f0-9c50-bfd1-1af707aaf3c4}.Debug|Any CPU.Build.0 = Debug|Any CPU {30fee563-a3f0-9c50-bfd1-1af707aaf3c4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentEnergyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentEnergyExtensionsTest.g.cs deleted file mode 100644 index 8e43023662..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentEnergyExtensionsTest.g.cs +++ /dev/null @@ -1,40 +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 UnitsNet.NumberExtensions.NumberToApparentEnergy; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToApparentEnergyExtensionsTests - { - [Fact] - public void NumberToKilovoltampereHoursTest() => - Assert.Equal(ApparentEnergy.FromKilovoltampereHours(2), 2.KilovoltampereHours()); - - [Fact] - public void NumberToMegavoltampereHoursTest() => - Assert.Equal(ApparentEnergy.FromMegavoltampereHours(2), 2.MegavoltampereHours()); - - [Fact] - public void NumberToVoltampereHoursTest() => - Assert.Equal(ApparentEnergy.FromVoltampereHours(2), 2.VoltampereHours()); - - } -} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentPowerExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentPowerExtensionsTest.g.cs deleted file mode 100644 index a4ba14f43e..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToApparentPowerExtensionsTest.g.cs +++ /dev/null @@ -1,52 +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 UnitsNet.NumberExtensions.NumberToApparentPower; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToApparentPowerExtensionsTests - { - [Fact] - public void NumberToGigavoltamperesTest() => - Assert.Equal(ApparentPower.FromGigavoltamperes(2), 2.Gigavoltamperes()); - - [Fact] - public void NumberToKilovoltamperesTest() => - Assert.Equal(ApparentPower.FromKilovoltamperes(2), 2.Kilovoltamperes()); - - [Fact] - public void NumberToMegavoltamperesTest() => - Assert.Equal(ApparentPower.FromMegavoltamperes(2), 2.Megavoltamperes()); - - [Fact] - public void NumberToMicrovoltamperesTest() => - Assert.Equal(ApparentPower.FromMicrovoltamperes(2), 2.Microvoltamperes()); - - [Fact] - public void NumberToMillivoltamperesTest() => - Assert.Equal(ApparentPower.FromMillivoltamperes(2), 2.Millivoltamperes()); - - [Fact] - public void NumberToVoltamperesTest() => - Assert.Equal(ApparentPower.FromVoltamperes(2), 2.Voltamperes()); - - } -} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCapacitanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCapacitanceExtensionsTest.g.cs deleted file mode 100644 index 7e969d6f38..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCapacitanceExtensionsTest.g.cs +++ /dev/null @@ -1,56 +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 UnitsNet.NumberExtensions.NumberToCapacitance; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToCapacitanceExtensionsTests - { - [Fact] - public void NumberToFaradsTest() => - Assert.Equal(Capacitance.FromFarads(2), 2.Farads()); - - [Fact] - public void NumberToKilofaradsTest() => - Assert.Equal(Capacitance.FromKilofarads(2), 2.Kilofarads()); - - [Fact] - public void NumberToMegafaradsTest() => - Assert.Equal(Capacitance.FromMegafarads(2), 2.Megafarads()); - - [Fact] - public void NumberToMicrofaradsTest() => - Assert.Equal(Capacitance.FromMicrofarads(2), 2.Microfarads()); - - [Fact] - public void NumberToMillifaradsTest() => - Assert.Equal(Capacitance.FromMillifarads(2), 2.Millifarads()); - - [Fact] - public void NumberToNanofaradsTest() => - Assert.Equal(Capacitance.FromNanofarads(2), 2.Nanofarads()); - - [Fact] - public void NumberToPicofaradsTest() => - Assert.Equal(Capacitance.FromPicofarads(2), 2.Picofarads()); - - } -} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialAcExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialAcExtensionsTest.g.cs deleted file mode 100644 index 3943cee481..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialAcExtensionsTest.g.cs +++ /dev/null @@ -1,48 +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 UnitsNet.NumberExtensions.NumberToElectricPotentialAc; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToElectricPotentialAcExtensionsTests - { - [Fact] - public void NumberToKilovoltsAcTest() => - Assert.Equal(ElectricPotentialAc.FromKilovoltsAc(2), 2.KilovoltsAc()); - - [Fact] - public void NumberToMegavoltsAcTest() => - Assert.Equal(ElectricPotentialAc.FromMegavoltsAc(2), 2.MegavoltsAc()); - - [Fact] - public void NumberToMicrovoltsAcTest() => - Assert.Equal(ElectricPotentialAc.FromMicrovoltsAc(2), 2.MicrovoltsAc()); - - [Fact] - public void NumberToMillivoltsAcTest() => - Assert.Equal(ElectricPotentialAc.FromMillivoltsAc(2), 2.MillivoltsAc()); - - [Fact] - public void NumberToVoltsAcTest() => - Assert.Equal(ElectricPotentialAc.FromVoltsAc(2), 2.VoltsAc()); - - } -} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialDcExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialDcExtensionsTest.g.cs deleted file mode 100644 index 479460c6a9..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricPotentialDcExtensionsTest.g.cs +++ /dev/null @@ -1,48 +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 UnitsNet.NumberExtensions.NumberToElectricPotentialDc; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToElectricPotentialDcExtensionsTests - { - [Fact] - public void NumberToKilovoltsDcTest() => - Assert.Equal(ElectricPotentialDc.FromKilovoltsDc(2), 2.KilovoltsDc()); - - [Fact] - public void NumberToMegavoltsDcTest() => - Assert.Equal(ElectricPotentialDc.FromMegavoltsDc(2), 2.MegavoltsDc()); - - [Fact] - public void NumberToMicrovoltsDcTest() => - Assert.Equal(ElectricPotentialDc.FromMicrovoltsDc(2), 2.MicrovoltsDc()); - - [Fact] - public void NumberToMillivoltsDcTest() => - Assert.Equal(ElectricPotentialDc.FromMillivoltsDc(2), 2.MillivoltsDc()); - - [Fact] - public void NumberToVoltsDcTest() => - Assert.Equal(ElectricPotentialDc.FromVoltsDc(2), 2.VoltsDc()); - - } -} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactiveEnergyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactiveEnergyExtensionsTest.g.cs deleted file mode 100644 index e55046a8a2..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactiveEnergyExtensionsTest.g.cs +++ /dev/null @@ -1,40 +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 UnitsNet.NumberExtensions.NumberToReactiveEnergy; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToReactiveEnergyExtensionsTests - { - [Fact] - public void NumberToKilovoltampereReactiveHoursTest() => - Assert.Equal(ReactiveEnergy.FromKilovoltampereReactiveHours(2), 2.KilovoltampereReactiveHours()); - - [Fact] - public void NumberToMegavoltampereReactiveHoursTest() => - Assert.Equal(ReactiveEnergy.FromMegavoltampereReactiveHours(2), 2.MegavoltampereReactiveHours()); - - [Fact] - public void NumberToVoltampereReactiveHoursTest() => - Assert.Equal(ReactiveEnergy.FromVoltampereReactiveHours(2), 2.VoltampereReactiveHours()); - - } -} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactivePowerExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactivePowerExtensionsTest.g.cs deleted file mode 100644 index 4c4d9a8b4b..0000000000 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToReactivePowerExtensionsTest.g.cs +++ /dev/null @@ -1,44 +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 UnitsNet.NumberExtensions.NumberToReactivePower; -using Xunit; - -namespace UnitsNet.Tests -{ - public class NumberToReactivePowerExtensionsTests - { - [Fact] - public void NumberToGigavoltamperesReactiveTest() => - Assert.Equal(ReactivePower.FromGigavoltamperesReactive(2), 2.GigavoltamperesReactive()); - - [Fact] - public void NumberToKilovoltamperesReactiveTest() => - Assert.Equal(ReactivePower.FromKilovoltamperesReactive(2), 2.KilovoltamperesReactive()); - - [Fact] - public void NumberToMegavoltamperesReactiveTest() => - Assert.Equal(ReactivePower.FromMegavoltamperesReactive(2), 2.MegavoltamperesReactive()); - - [Fact] - public void NumberToVoltamperesReactiveTest() => - Assert.Equal(ReactivePower.FromVoltamperesReactive(2), 2.VoltamperesReactive()); - - } -} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentEnergyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentEnergyExtensions.g.cs deleted file mode 100644 index 93ee2fffd2..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentEnergyExtensions.g.cs +++ /dev/null @@ -1,64 +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.NumberToApparentEnergy -{ - /// - /// A number to ApparentEnergy Extensions - /// - [Obsolete("ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.")] - public static class NumberToApparentEnergyExtensions - { - /// - [Obsolete("ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.")] - public static ApparentEnergy KilovoltampereHours(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentEnergy.FromKilovoltampereHours(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.")] - public static ApparentEnergy MegavoltampereHours(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentEnergy.FromMegavoltampereHours(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.")] - public static ApparentEnergy VoltampereHours(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentEnergy.FromVoltampereHours(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentPowerExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentPowerExtensions.g.cs deleted file mode 100644 index a2ac4a9363..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToApparentPowerExtensions.g.cs +++ /dev/null @@ -1,91 +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.NumberToApparentPower -{ - /// - /// A number to ApparentPower Extensions - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static class NumberToApparentPowerExtensions - { - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static ApparentPower Gigavoltamperes(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentPower.FromGigavoltamperes(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static ApparentPower Kilovoltamperes(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentPower.FromKilovoltamperes(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static ApparentPower Megavoltamperes(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentPower.FromMegavoltamperes(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static ApparentPower Microvoltamperes(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentPower.FromMicrovoltamperes(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static ApparentPower Millivoltamperes(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentPower.FromMillivoltamperes(Convert.ToDouble(value)); - - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - public static ApparentPower Voltamperes(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ApparentPower.FromVoltamperes(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToCapacitanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToCapacitanceExtensions.g.cs deleted file mode 100644 index 1cd6355eed..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToCapacitanceExtensions.g.cs +++ /dev/null @@ -1,100 +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.NumberToCapacitance -{ - /// - /// A number to Capacitance Extensions - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static class NumberToCapacitanceExtensions - { - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Farads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromFarads(Convert.ToDouble(value)); - - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Kilofarads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromKilofarads(Convert.ToDouble(value)); - - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Megafarads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromMegafarads(Convert.ToDouble(value)); - - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Microfarads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromMicrofarads(Convert.ToDouble(value)); - - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Millifarads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromMillifarads(Convert.ToDouble(value)); - - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Nanofarads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromNanofarads(Convert.ToDouble(value)); - - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - public static Capacitance Picofarads(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => Capacitance.FromPicofarads(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs deleted file mode 100644 index c6b0db2fe5..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialAcExtensions.g.cs +++ /dev/null @@ -1,82 +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 - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static class NumberToElectricPotentialAcExtensions - { - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialAc KilovoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromKilovoltsAc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialAc MegavoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromMegavoltsAc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialAc MicrovoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromMicrovoltsAc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialAc MillivoltsAc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialAc.FromMillivoltsAc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - 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 1a40a8af6e..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricPotentialDcExtensions.g.cs +++ /dev/null @@ -1,82 +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 - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static class NumberToElectricPotentialDcExtensions - { - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialDc KilovoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromKilovoltsDc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialDc MegavoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromMegavoltsDc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialDc MicrovoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromMicrovoltsDc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - public static ElectricPotentialDc MillivoltsDc(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ElectricPotentialDc.FromMillivoltsDc(Convert.ToDouble(value)); - - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - 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.NumberExtensions/GeneratedCode/NumberToReactiveEnergyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToReactiveEnergyExtensions.g.cs deleted file mode 100644 index dfc87c2774..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToReactiveEnergyExtensions.g.cs +++ /dev/null @@ -1,64 +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.NumberToReactiveEnergy -{ - /// - /// A number to ReactiveEnergy Extensions - /// - [Obsolete("ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.")] - public static class NumberToReactiveEnergyExtensions - { - /// - [Obsolete("ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.")] - public static ReactiveEnergy KilovoltampereReactiveHours(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactiveEnergy.FromKilovoltampereReactiveHours(Convert.ToDouble(value)); - - /// - [Obsolete("ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.")] - public static ReactiveEnergy MegavoltampereReactiveHours(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactiveEnergy.FromMegavoltampereReactiveHours(Convert.ToDouble(value)); - - /// - [Obsolete("ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.")] - public static ReactiveEnergy VoltampereReactiveHours(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactiveEnergy.FromVoltampereReactiveHours(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToReactivePowerExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToReactivePowerExtensions.g.cs deleted file mode 100644 index 149e729d5e..0000000000 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToReactivePowerExtensions.g.cs +++ /dev/null @@ -1,73 +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.NumberToReactivePower -{ - /// - /// A number to ReactivePower Extensions - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - public static class NumberToReactivePowerExtensions - { - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - public static ReactivePower GigavoltamperesReactive(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactivePower.FromGigavoltamperesReactive(Convert.ToDouble(value)); - - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - public static ReactivePower KilovoltamperesReactive(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactivePower.FromKilovoltamperesReactive(Convert.ToDouble(value)); - - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - public static ReactivePower MegavoltamperesReactive(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactivePower.FromMegavoltamperesReactive(Convert.ToDouble(value)); - - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - public static ReactivePower VoltamperesReactive(this T value) - where T : notnull -#if NET7_0_OR_GREATER - , INumber -#endif - => ReactivePower.FromVoltamperesReactive(Convert.ToDouble(value)); - - } -} diff --git a/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs b/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs deleted file mode 100644 index 216ef60102..0000000000 --- a/UnitsNet.Tests/CustomCode/ApparentEnergyTests.cs +++ /dev/null @@ -1,38 +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 quantity and \generate-code.bat is run, -// the base test class will get a new abstract property and cause a compile error -// in this derived class, reminding the developer to implement the test case -// for the new unit. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.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; - -namespace UnitsNet.Tests.CustomCode -{ - public class ApparentEnergyTests : ApparentEnergyTestsBase - { - protected override bool SupportsSIUnitSystem => false; - - protected override double VoltampereHoursInOneVoltampereHour => 1; - - protected override double KilovoltampereHoursInOneVoltampereHour => 1E-3; - - protected override double MegavoltampereHoursInOneVoltampereHour => 1E-6; - } -} diff --git a/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs b/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs deleted file mode 100644 index 7b0b635297..0000000000 --- a/UnitsNet.Tests/CustomCode/ApparentPowerTests.cs +++ /dev/null @@ -1,44 +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 ApparentPowerTests : ApparentPowerTestsBase - { - protected override bool SupportsSIUnitSystem => false; - - protected override double VoltamperesInOneVoltampere => 1; - - protected override double KilovoltamperesInOneVoltampere => 1E-3; - - protected override double MegavoltamperesInOneVoltampere => 1E-6; - - protected override double GigavoltamperesInOneVoltampere => 1E-9; - - protected override double MicrovoltamperesInOneVoltampere => 1E6; - - protected override double MillivoltamperesInOneVoltampere => 1E3; - } -} diff --git a/UnitsNet.Tests/CustomCode/CapacitanceTests.cs b/UnitsNet.Tests/CustomCode/CapacitanceTests.cs deleted file mode 100644 index 1dee2ea97e..0000000000 --- a/UnitsNet.Tests/CustomCode/CapacitanceTests.cs +++ /dev/null @@ -1,46 +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 quantity and \generate-code.bat is run, -// the base test class will get a new abstract property and cause a compile error -// in this derived class, reminding the developer to implement the test case -// for the new unit. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.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; - -namespace UnitsNet.Tests.CustomCode -{ - public class CapacitanceTests : CapacitanceTestsBase - { - protected override bool SupportsSIUnitSystem => true; - - protected override double FaradsInOneFarad => 1; - - protected override double MillifaradsInOneFarad => 1e3; - - protected override double MicrofaradsInOneFarad => 1e6; - - protected override double NanofaradsInOneFarad => 1e9; - - protected override double PicofaradsInOneFarad => 1e12; - - protected override double KilofaradsInOneFarad => 1e-3; - - protected override double MegafaradsInOneFarad => 1e-6; - } -} 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/CustomCode/ReactiveEnergyTests.cs b/UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs deleted file mode 100644 index 2cd682b8ae..0000000000 --- a/UnitsNet.Tests/CustomCode/ReactiveEnergyTests.cs +++ /dev/null @@ -1,37 +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 quantity and \generate-code.bat is run, -// the base test class will get a new abstract property and cause a compile error -// in this derived class, reminding the developer to implement the test case -// for the new unit. -// -// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. -// -// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. -// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.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; - -namespace UnitsNet.Tests.CustomCode -{ - public class ReactiveEnergyTests : ReactiveEnergyTestsBase - { - protected override bool SupportsSIUnitSystem => false; - protected override double VoltampereReactiveHoursInOneVoltampereReactiveHour => 1; - - protected override double KilovoltampereReactiveHoursInOneVoltampereReactiveHour => 1E-3; - - protected override double MegavoltampereReactiveHoursInOneVoltampereReactiveHour => 1E-6; - } -} diff --git a/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs b/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs deleted file mode 100644 index 184a40d2f4..0000000000 --- a/UnitsNet.Tests/CustomCode/ReactivePowerTests.cs +++ /dev/null @@ -1,39 +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 ReactivePowerTests : ReactivePowerTestsBase - { - protected override bool SupportsSIUnitSystem => false; - protected override double VoltamperesReactiveInOneVoltampereReactive => 1; - - protected override double KilovoltamperesReactiveInOneVoltampereReactive => 1E-3; - - protected override double MegavoltamperesReactiveInOneVoltampereReactive => 1E-6; - - protected override double GigavoltamperesReactiveInOneVoltampereReactive => 1E-9; - } -} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 9e50897b3c..afb8d58278 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -39,14 +39,11 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, AmountOfSubstanceUnit.PoundMole, Quantity.From(3, AmountOfSubstanceUnit.PoundMole)); Assertion(3, AmplitudeRatioUnit.DecibelVolt, Quantity.From(3, AmplitudeRatioUnit.DecibelVolt)); Assertion(3, AngleUnit.Revolution, Quantity.From(3, AngleUnit.Revolution)); - Assertion(3, ApparentEnergyUnit.VoltampereHour, Quantity.From(3, ApparentEnergyUnit.VoltampereHour)); - Assertion(3, ApparentPowerUnit.Voltampere, Quantity.From(3, ApparentPowerUnit.Voltampere)); Assertion(3, AreaUnit.UsSurveySquareFoot, Quantity.From(3, AreaUnit.UsSurveySquareFoot)); Assertion(3, AreaDensityUnit.MilligramPerSquareMeter, Quantity.From(3, AreaDensityUnit.MilligramPerSquareMeter)); Assertion(3, AreaMomentOfInertiaUnit.MillimeterToTheFourth, Quantity.From(3, AreaMomentOfInertiaUnit.MillimeterToTheFourth)); Assertion(3, BitRateUnit.TerabytePerSecond, Quantity.From(3, BitRateUnit.TerabytePerSecond)); Assertion(3, BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, Quantity.From(3, BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)); - Assertion(3, CapacitanceUnit.Picofarad, Quantity.From(3, CapacitanceUnit.Picofarad)); Assertion(3, CoefficientOfThermalExpansionUnit.PpmPerKelvin, Quantity.From(3, CoefficientOfThermalExpansionUnit.PpmPerKelvin)); Assertion(3, CompressibilityUnit.InversePoundForcePerSquareInch, Quantity.From(3, CompressibilityUnit.InversePoundForcePerSquareInch)); Assertion(3, DensityUnit.TonnePerCubicMillimeter, Quantity.From(3, DensityUnit.TonnePerCubicMillimeter)); @@ -68,9 +65,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, ElectricImpedanceUnit.Teraohm, Quantity.From(3, ElectricImpedanceUnit.Teraohm)); 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, ElectricReactanceUnit.Teraohm, Quantity.From(3, ElectricReactanceUnit.Teraohm)); Assertion(3, ElectricReactiveEnergyUnit.VoltampereReactiveHour, Quantity.From(3, ElectricReactiveEnergyUnit.VoltampereReactiveHour)); Assertion(3, ElectricReactivePowerUnit.VoltampereReactive, Quantity.From(3, ElectricReactivePowerUnit.VoltampereReactive)); @@ -133,8 +128,6 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, RadioactivityUnit.Terarutherford, Quantity.From(3, RadioactivityUnit.Terarutherford)); Assertion(3, RatioUnit.Percent, Quantity.From(3, RatioUnit.Percent)); Assertion(3, RatioChangeRateUnit.PercentPerSecond, Quantity.From(3, RatioChangeRateUnit.PercentPerSecond)); - Assertion(3, ReactiveEnergyUnit.VoltampereReactiveHour, Quantity.From(3, ReactiveEnergyUnit.VoltampereReactiveHour)); - Assertion(3, ReactivePowerUnit.VoltampereReactive, Quantity.From(3, ReactivePowerUnit.VoltampereReactive)); Assertion(3, ReciprocalAreaUnit.InverseUsSurveySquareFoot, Quantity.From(3, ReciprocalAreaUnit.InverseUsSurveySquareFoot)); Assertion(3, ReciprocalLengthUnit.InverseYard, Quantity.From(3, ReciprocalLengthUnit.InverseYard)); Assertion(3, RelativeHumidityUnit.Percent, Quantity.From(3, RelativeHumidityUnit.Percent)); @@ -179,14 +172,11 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(AmountOfSubstance.Info, AmountOfSubstance.Zero); Assertion(AmplitudeRatio.Info, AmplitudeRatio.Zero); Assertion(Angle.Info, Angle.Zero); - Assertion(ApparentEnergy.Info, ApparentEnergy.Zero); - Assertion(ApparentPower.Info, ApparentPower.Zero); Assertion(Area.Info, Area.Zero); Assertion(AreaDensity.Info, AreaDensity.Zero); Assertion(AreaMomentOfInertia.Info, AreaMomentOfInertia.Zero); Assertion(BitRate.Info, BitRate.Zero); Assertion(BrakeSpecificFuelConsumption.Info, BrakeSpecificFuelConsumption.Zero); - Assertion(Capacitance.Info, Capacitance.Zero); Assertion(CoefficientOfThermalExpansion.Info, CoefficientOfThermalExpansion.Zero); Assertion(Compressibility.Info, Compressibility.Zero); Assertion(Density.Info, Density.Zero); @@ -208,9 +198,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(ElectricImpedance.Info, ElectricImpedance.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(ElectricReactance.Info, ElectricReactance.Zero); Assertion(ElectricReactiveEnergy.Info, ElectricReactiveEnergy.Zero); Assertion(ElectricReactivePower.Info, ElectricReactivePower.Zero); @@ -273,8 +261,6 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(Radioactivity.Info, Radioactivity.Zero); Assertion(Ratio.Info, Ratio.Zero); Assertion(RatioChangeRate.Info, RatioChangeRate.Zero); - Assertion(ReactiveEnergy.Info, ReactiveEnergy.Zero); - Assertion(ReactivePower.Info, ReactivePower.Zero); Assertion(ReciprocalArea.Info, ReciprocalArea.Zero); Assertion(ReciprocalLength.Info, ReciprocalLength.Zero); Assertion(RelativeHumidity.Info, RelativeHumidity.Zero); @@ -319,14 +305,11 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(AmountOfSubstance.BaseDimensions, AmountOfSubstance.Zero); Assertion(AmplitudeRatio.BaseDimensions, AmplitudeRatio.Zero); Assertion(Angle.BaseDimensions, Angle.Zero); - Assertion(ApparentEnergy.BaseDimensions, ApparentEnergy.Zero); - Assertion(ApparentPower.BaseDimensions, ApparentPower.Zero); Assertion(Area.BaseDimensions, Area.Zero); Assertion(AreaDensity.BaseDimensions, AreaDensity.Zero); Assertion(AreaMomentOfInertia.BaseDimensions, AreaMomentOfInertia.Zero); Assertion(BitRate.BaseDimensions, BitRate.Zero); Assertion(BrakeSpecificFuelConsumption.BaseDimensions, BrakeSpecificFuelConsumption.Zero); - Assertion(Capacitance.BaseDimensions, Capacitance.Zero); Assertion(CoefficientOfThermalExpansion.BaseDimensions, CoefficientOfThermalExpansion.Zero); Assertion(Compressibility.BaseDimensions, Compressibility.Zero); Assertion(Density.BaseDimensions, Density.Zero); @@ -348,9 +331,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(ElectricImpedance.BaseDimensions, ElectricImpedance.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(ElectricReactance.BaseDimensions, ElectricReactance.Zero); Assertion(ElectricReactiveEnergy.BaseDimensions, ElectricReactiveEnergy.Zero); Assertion(ElectricReactivePower.BaseDimensions, ElectricReactivePower.Zero); @@ -413,8 +394,6 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(Radioactivity.BaseDimensions, Radioactivity.Zero); Assertion(Ratio.BaseDimensions, Ratio.Zero); Assertion(RatioChangeRate.BaseDimensions, RatioChangeRate.Zero); - Assertion(ReactiveEnergy.BaseDimensions, ReactiveEnergy.Zero); - Assertion(ReactivePower.BaseDimensions, ReactivePower.Zero); Assertion(ReciprocalArea.BaseDimensions, ReciprocalArea.Zero); Assertion(ReciprocalLength.BaseDimensions, ReciprocalLength.Zero); Assertion(RelativeHumidity.BaseDimensions, RelativeHumidity.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs deleted file mode 100644 index 31074377bf..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs +++ /dev/null @@ -1,750 +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.Helpers; -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 ApparentEnergy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ApparentEnergyTestsBase : QuantityTestsBase - { - protected abstract double KilovoltampereHoursInOneVoltampereHour { get; } - protected abstract double MegavoltampereHoursInOneVoltampereHour { get; } - protected abstract double VoltampereHoursInOneVoltampereHour { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltampereHoursTolerance { get { return 1e-5; } } - protected virtual double MegavoltampereHoursTolerance { get { return 1e-5; } } - protected virtual double VoltampereHoursTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ApparentEnergyUnit unit) - { - return unit switch - { - ApparentEnergyUnit.KilovoltampereHour => (KilovoltampereHoursInOneVoltampereHour, KilovoltampereHoursTolerance), - ApparentEnergyUnit.MegavoltampereHour => (MegavoltampereHoursInOneVoltampereHour, MegavoltampereHoursTolerance), - ApparentEnergyUnit.VoltampereHour => (VoltampereHoursInOneVoltampereHour, VoltampereHoursTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { ApparentEnergyUnit.KilovoltampereHour }, - new object[] { ApparentEnergyUnit.MegavoltampereHour }, - new object[] { ApparentEnergyUnit.VoltampereHour }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new ApparentEnergy(); - Assert.Equal(0, quantity.Value); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new ApparentEnergy(double.PositiveInfinity, ApparentEnergyUnit.VoltampereHour)); - var exception2 = Record.Exception(() => new ApparentEnergy(double.NegativeInfinity, ApparentEnergyUnit.VoltampereHour)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new ApparentEnergy(double.NaN, ApparentEnergyUnit.VoltampereHour)); - - Assert.Null(exception); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new ApparentEnergy(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new ApparentEnergy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ApparentEnergy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void ApparentEnergy_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new ApparentEnergy(1, ApparentEnergyUnit.VoltampereHour); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(ApparentEnergy.Zero, quantityInfo.Zero); - Assert.Equal("ApparentEnergy", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void VoltampereHourToApparentEnergyUnits() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.KilovoltampereHours, KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.MegavoltampereHours, MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.VoltampereHours, VoltampereHoursTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = ApparentEnergy.From(1, ApparentEnergyUnit.KilovoltampereHour); - AssertEx.EqualTolerance(1, quantity00.KilovoltampereHours, KilovoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.KilovoltampereHour, quantity00.Unit); - - var quantity01 = ApparentEnergy.From(1, ApparentEnergyUnit.MegavoltampereHour); - AssertEx.EqualTolerance(1, quantity01.MegavoltampereHours, MegavoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.MegavoltampereHour, quantity01.Unit); - - var quantity02 = ApparentEnergy.From(1, ApparentEnergyUnit.VoltampereHour); - AssertEx.EqualTolerance(1, quantity02.VoltampereHours, VoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, quantity02.Unit); - - } - - [Fact] - public void FromVoltampereHours_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => ApparentEnergy.FromVoltampereHours(double.PositiveInfinity)); - var exception2 = Record.Exception(() => ApparentEnergy.FromVoltampereHours(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromVoltampereHours_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => ApparentEnergy.FromVoltampereHours(double.NaN)); - - Assert.Null(exception); - } - - [Fact] - public void As() - { - var voltamperehour = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.KilovoltampereHour), KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.MegavoltampereHour), MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.As(ApparentEnergyUnit.VoltampereHour), VoltampereHoursTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new ApparentEnergy(value: 1, unit: ApparentEnergy.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 = ApparentEnergy.Parse("1 kVAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltampereHours, KilovoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.KilovoltampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentEnergy.Parse("1 MVAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltampereHours, MegavoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.MegavoltampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentEnergy.Parse("1 VAh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltampereHours, VoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(ApparentEnergy.TryParse("1 kVAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltampereHours, KilovoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.KilovoltampereHour, parsed.Unit); - } - - { - Assert.True(ApparentEnergy.TryParse("1 MVAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegavoltampereHours, MegavoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.MegavoltampereHour, parsed.Unit); - } - - { - Assert.True(ApparentEnergy.TryParse("1 VAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltampereHours, VoltampereHoursTolerance); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, parsed.Unit); - } - - } - - [Theory] - [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentEnergyUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentEnergyUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) - { - using var _ = new CultureScope(culture); - ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] - public void ParseUnit_WithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) - { - ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentEnergyUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentEnergyUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] - [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] - [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) - { - Assert.True(ApparentEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ApparentEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(ApparentEnergyUnit unit) - { - var inBaseUnits = ApparentEnergy.From(1.0, ApparentEnergy.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(ApparentEnergyUnit unit) - { - var quantity = ApparentEnergy.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ApparentEnergyUnit 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 = ApparentEnergy.Units.First(u => u != ApparentEnergy.BaseUnit); - - var quantity = ApparentEnergy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ApparentEnergyUnit unit) - { - var quantity = default(ApparentEnergy); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(1, ApparentEnergy.FromKilovoltampereHours(voltamperehour.KilovoltampereHours).VoltampereHours, KilovoltampereHoursTolerance); - AssertEx.EqualTolerance(1, ApparentEnergy.FromMegavoltampereHours(voltamperehour.MegavoltampereHours).VoltampereHours, MegavoltampereHoursTolerance); - AssertEx.EqualTolerance(1, ApparentEnergy.FromVoltampereHours(voltamperehour.VoltampereHours).VoltampereHours, VoltampereHoursTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ApparentEnergy v = ApparentEnergy.FromVoltampereHours(1); - AssertEx.EqualTolerance(-1, -v.VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, (ApparentEnergy.FromVoltampereHours(3)-v).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, (ApparentEnergy.FromVoltampereHours(10)/5).VoltampereHours, VoltampereHoursTolerance); - AssertEx.EqualTolerance(2, ApparentEnergy.FromVoltampereHours(10)/ApparentEnergy.FromVoltampereHours(5), VoltampereHoursTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ApparentEnergy oneVoltampereHour = ApparentEnergy.FromVoltampereHours(1); - ApparentEnergy twoVoltampereHours = ApparentEnergy.FromVoltampereHours(2); - - Assert.True(oneVoltampereHour < twoVoltampereHours); - Assert.True(oneVoltampereHour <= twoVoltampereHours); - Assert.True(twoVoltampereHours > oneVoltampereHour); - Assert.True(twoVoltampereHours >= oneVoltampereHour); - - Assert.False(oneVoltampereHour > twoVoltampereHours); - Assert.False(oneVoltampereHour >= twoVoltampereHours); - Assert.False(twoVoltampereHours < oneVoltampereHour); - Assert.False(twoVoltampereHours <= oneVoltampereHour); - } - - [Fact] - public void CompareToIsImplemented() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.Equal(0, voltamperehour.CompareTo(voltamperehour)); - Assert.True(voltamperehour.CompareTo(ApparentEnergy.Zero) > 0); - Assert.True(ApparentEnergy.Zero.CompareTo(voltamperehour) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.Throws(() => voltamperehour.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.Throws(() => voltamperehour.CompareTo(null)); - } - - [Theory] - [InlineData(1, ApparentEnergyUnit.VoltampereHour, 1, ApparentEnergyUnit.VoltampereHour, true)] // Same value and unit. - [InlineData(1, ApparentEnergyUnit.VoltampereHour, 2, ApparentEnergyUnit.VoltampereHour, false)] // Different value. - [InlineData(2, ApparentEnergyUnit.VoltampereHour, 1, ApparentEnergyUnit.KilovoltampereHour, false)] // Different value and unit. - [InlineData(1, ApparentEnergyUnit.VoltampereHour, 1, ApparentEnergyUnit.KilovoltampereHour, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ApparentEnergyUnit unitA, double valueB, ApparentEnergyUnit unitB, bool expectEqual) - { - var a = new ApparentEnergy(valueA, unitA); - var b = new ApparentEnergy(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 = ApparentEnergy.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 = ApparentEnergy.FromVoltampereHours(1); - Assert.True(v.Equals(ApparentEnergy.FromVoltampereHours(1), VoltampereHoursTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ApparentEnergy.Zero, VoltampereHoursTolerance, ComparisonType.Relative)); - Assert.True(ApparentEnergy.FromVoltampereHours(100).Equals(ApparentEnergy.FromVoltampereHours(120), 0.3, ComparisonType.Relative)); - Assert.False(ApparentEnergy.FromVoltampereHours(100).Equals(ApparentEnergy.FromVoltampereHours(120), 0.1, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = ApparentEnergy.FromVoltampereHours(1); - Assert.Throws(() => v.Equals(ApparentEnergy.FromVoltampereHours(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.False(voltamperehour.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ApparentEnergy voltamperehour = ApparentEnergy.FromVoltampereHours(1); - Assert.False(voltamperehour.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ApparentEnergyUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ApparentEnergy.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - Assert.Equal("1 kVAh", new ApparentEnergy(1, ApparentEnergyUnit.KilovoltampereHour).ToString()); - Assert.Equal("1 MVAh", new ApparentEnergy(1, ApparentEnergyUnit.MegavoltampereHour).ToString()); - Assert.Equal("1 VAh", new ApparentEnergy(1, ApparentEnergyUnit.VoltampereHour).ToString()); - } - - [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 kVAh", new ApparentEnergy(1, ApparentEnergyUnit.KilovoltampereHour).ToString(swedishCulture)); - Assert.Equal("1 MVAh", new ApparentEnergy(1, ApparentEnergyUnit.MegavoltampereHour).ToString(swedishCulture)); - Assert.Equal("1 VAh", new ApparentEnergy(1, ApparentEnergyUnit.VoltampereHour).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var _ = new CultureScope(CultureInfo.InvariantCulture); - Assert.Equal("0.1 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s1")); - Assert.Equal("0.12 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s2")); - Assert.Equal("0.123 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s3")); - Assert.Equal("0.1235 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s4")); - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s1", culture)); - Assert.Equal("0.12 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s2", culture)); - Assert.Equal("0.123 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s3", culture)); - Assert.Equal("0.1235 VAh", new ApparentEnergy(0.123456, ApparentEnergyUnit.VoltampereHour).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = ApparentEnergy.FromVoltampereHours(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 = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ApparentEnergy))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ApparentEnergyUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(ApparentEnergy.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(ApparentEnergy.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = ApparentEnergy.FromVoltampereHours(1.0); - Assert.Equal(new {ApparentEnergy.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 = ApparentEnergy.FromVoltampereHours(value); - Assert.Equal(ApparentEnergy.FromVoltampereHours(-value), -quantity); - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs deleted file mode 100644 index e19d4130f3..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs +++ /dev/null @@ -1,840 +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.Helpers; -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 ApparentPower. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ApparentPowerTestsBase : QuantityTestsBase - { - protected abstract double GigavoltamperesInOneVoltampere { get; } - protected abstract double KilovoltamperesInOneVoltampere { get; } - protected abstract double MegavoltamperesInOneVoltampere { get; } - protected abstract double MicrovoltamperesInOneVoltampere { get; } - protected abstract double MillivoltamperesInOneVoltampere { get; } - protected abstract double VoltamperesInOneVoltampere { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GigavoltamperesTolerance { get { return 1e-5; } } - protected virtual double KilovoltamperesTolerance { get { return 1e-5; } } - protected virtual double MegavoltamperesTolerance { get { return 1e-5; } } - protected virtual double MicrovoltamperesTolerance { get { return 1e-5; } } - protected virtual double MillivoltamperesTolerance { get { return 1e-5; } } - protected virtual double VoltamperesTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ApparentPowerUnit unit) - { - return unit switch - { - ApparentPowerUnit.Gigavoltampere => (GigavoltamperesInOneVoltampere, GigavoltamperesTolerance), - ApparentPowerUnit.Kilovoltampere => (KilovoltamperesInOneVoltampere, KilovoltamperesTolerance), - ApparentPowerUnit.Megavoltampere => (MegavoltamperesInOneVoltampere, MegavoltamperesTolerance), - ApparentPowerUnit.Microvoltampere => (MicrovoltamperesInOneVoltampere, MicrovoltamperesTolerance), - ApparentPowerUnit.Millivoltampere => (MillivoltamperesInOneVoltampere, MillivoltamperesTolerance), - ApparentPowerUnit.Voltampere => (VoltamperesInOneVoltampere, VoltamperesTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { ApparentPowerUnit.Gigavoltampere }, - new object[] { ApparentPowerUnit.Kilovoltampere }, - new object[] { ApparentPowerUnit.Megavoltampere }, - new object[] { ApparentPowerUnit.Microvoltampere }, - new object[] { ApparentPowerUnit.Millivoltampere }, - new object[] { ApparentPowerUnit.Voltampere }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new ApparentPower(); - Assert.Equal(0, quantity.Value); - Assert.Equal(ApparentPowerUnit.Voltampere, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new ApparentPower(double.PositiveInfinity, ApparentPowerUnit.Voltampere)); - var exception2 = Record.Exception(() => new ApparentPower(double.NegativeInfinity, ApparentPowerUnit.Voltampere)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new ApparentPower(double.NaN, ApparentPowerUnit.Voltampere)); - - Assert.Null(exception); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new ApparentPower(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new ApparentPower(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ApparentPower) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void ApparentPower_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new ApparentPower(1, ApparentPowerUnit.Voltampere); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(ApparentPower.Zero, quantityInfo.Zero); - Assert.Equal("ApparentPower", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void VoltampereToApparentPowerUnits() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, voltampere.Gigavoltamperes, GigavoltamperesTolerance); - AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, voltampere.Kilovoltamperes, KilovoltamperesTolerance); - AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, voltampere.Megavoltamperes, MegavoltamperesTolerance); - AssertEx.EqualTolerance(MicrovoltamperesInOneVoltampere, voltampere.Microvoltamperes, MicrovoltamperesTolerance); - AssertEx.EqualTolerance(MillivoltamperesInOneVoltampere, voltampere.Millivoltamperes, MillivoltamperesTolerance); - AssertEx.EqualTolerance(VoltamperesInOneVoltampere, voltampere.Voltamperes, VoltamperesTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = ApparentPower.From(1, ApparentPowerUnit.Gigavoltampere); - AssertEx.EqualTolerance(1, quantity00.Gigavoltamperes, GigavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Gigavoltampere, quantity00.Unit); - - var quantity01 = ApparentPower.From(1, ApparentPowerUnit.Kilovoltampere); - AssertEx.EqualTolerance(1, quantity01.Kilovoltamperes, KilovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Kilovoltampere, quantity01.Unit); - - var quantity02 = ApparentPower.From(1, ApparentPowerUnit.Megavoltampere); - AssertEx.EqualTolerance(1, quantity02.Megavoltamperes, MegavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Megavoltampere, quantity02.Unit); - - var quantity03 = ApparentPower.From(1, ApparentPowerUnit.Microvoltampere); - AssertEx.EqualTolerance(1, quantity03.Microvoltamperes, MicrovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Microvoltampere, quantity03.Unit); - - var quantity04 = ApparentPower.From(1, ApparentPowerUnit.Millivoltampere); - AssertEx.EqualTolerance(1, quantity04.Millivoltamperes, MillivoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Millivoltampere, quantity04.Unit); - - var quantity05 = ApparentPower.From(1, ApparentPowerUnit.Voltampere); - AssertEx.EqualTolerance(1, quantity05.Voltamperes, VoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Voltampere, quantity05.Unit); - - } - - [Fact] - public void FromVoltamperes_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => ApparentPower.FromVoltamperes(double.PositiveInfinity)); - var exception2 = Record.Exception(() => ApparentPower.FromVoltamperes(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromVoltamperes_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => ApparentPower.FromVoltamperes(double.NaN)); - - Assert.Null(exception); - } - - [Fact] - public void As() - { - var voltampere = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Gigavoltampere), GigavoltamperesTolerance); - AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Kilovoltampere), KilovoltamperesTolerance); - AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Megavoltampere), MegavoltamperesTolerance); - AssertEx.EqualTolerance(MicrovoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Microvoltampere), MicrovoltamperesTolerance); - AssertEx.EqualTolerance(MillivoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Millivoltampere), MillivoltamperesTolerance); - AssertEx.EqualTolerance(VoltamperesInOneVoltampere, voltampere.As(ApparentPowerUnit.Voltampere), VoltamperesTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new ApparentPower(value: 1, unit: ApparentPower.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 = ApparentPower.Parse("1 GVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Gigavoltamperes, GigavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Gigavoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentPower.Parse("1 kVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilovoltamperes, KilovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Kilovoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentPower.Parse("1 MVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megavoltamperes, MegavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Megavoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentPower.Parse("1 µVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microvoltamperes, MicrovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Microvoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentPower.Parse("1 mVA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millivoltamperes, MillivoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Millivoltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ApparentPower.Parse("1 VA", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Voltamperes, VoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Voltampere, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(ApparentPower.TryParse("1 GVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Gigavoltamperes, GigavoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Gigavoltampere, parsed.Unit); - } - - { - Assert.True(ApparentPower.TryParse("1 kVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilovoltamperes, KilovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Kilovoltampere, parsed.Unit); - } - - { - Assert.True(ApparentPower.TryParse("1 µVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microvoltamperes, MicrovoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Microvoltampere, parsed.Unit); - } - - { - Assert.True(ApparentPower.TryParse("1 VA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Voltamperes, VoltamperesTolerance); - Assert.Equal(ApparentPowerUnit.Voltampere, parsed.Unit); - } - - } - - [Theory] - [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("VA", ApparentPowerUnit.Voltampere)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentPowerUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("VA", ApparentPowerUnit.Voltampere)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentPowerUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) - { - using var _ = new CultureScope(culture); - ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] - public void ParseUnit_WithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) - { - ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("VA", ApparentPowerUnit.Voltampere)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentPowerUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("VA", ApparentPowerUnit.Voltampere)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentPowerUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] - [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] - [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] - [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] - [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] - [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) - { - Assert.True(ApparentPower.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ApparentPowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(ApparentPowerUnit unit) - { - var inBaseUnits = ApparentPower.From(1.0, ApparentPower.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(ApparentPowerUnit unit) - { - var quantity = ApparentPower.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ApparentPowerUnit 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 = ApparentPower.Units.First(u => u != ApparentPower.BaseUnit); - - var quantity = ApparentPower.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ApparentPowerUnit unit) - { - var quantity = default(ApparentPower); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(1, ApparentPower.FromGigavoltamperes(voltampere.Gigavoltamperes).Voltamperes, GigavoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromKilovoltamperes(voltampere.Kilovoltamperes).Voltamperes, KilovoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromMegavoltamperes(voltampere.Megavoltamperes).Voltamperes, MegavoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromMicrovoltamperes(voltampere.Microvoltamperes).Voltamperes, MicrovoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromMillivoltamperes(voltampere.Millivoltamperes).Voltamperes, MillivoltamperesTolerance); - AssertEx.EqualTolerance(1, ApparentPower.FromVoltamperes(voltampere.Voltamperes).Voltamperes, VoltamperesTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ApparentPower v = ApparentPower.FromVoltamperes(1); - AssertEx.EqualTolerance(-1, -v.Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, (ApparentPower.FromVoltamperes(3)-v).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, (v + v).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(10, (v*10).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(10, (10*v).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, (ApparentPower.FromVoltamperes(10)/5).Voltamperes, VoltamperesTolerance); - AssertEx.EqualTolerance(2, ApparentPower.FromVoltamperes(10)/ApparentPower.FromVoltamperes(5), VoltamperesTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ApparentPower oneVoltampere = ApparentPower.FromVoltamperes(1); - ApparentPower twoVoltamperes = ApparentPower.FromVoltamperes(2); - - Assert.True(oneVoltampere < twoVoltamperes); - Assert.True(oneVoltampere <= twoVoltamperes); - Assert.True(twoVoltamperes > oneVoltampere); - Assert.True(twoVoltamperes >= oneVoltampere); - - Assert.False(oneVoltampere > twoVoltamperes); - Assert.False(oneVoltampere >= twoVoltamperes); - Assert.False(twoVoltamperes < oneVoltampere); - Assert.False(twoVoltamperes <= oneVoltampere); - } - - [Fact] - public void CompareToIsImplemented() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.Equal(0, voltampere.CompareTo(voltampere)); - Assert.True(voltampere.CompareTo(ApparentPower.Zero) > 0); - Assert.True(ApparentPower.Zero.CompareTo(voltampere) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.Throws(() => voltampere.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.Throws(() => voltampere.CompareTo(null)); - } - - [Theory] - [InlineData(1, ApparentPowerUnit.Voltampere, 1, ApparentPowerUnit.Voltampere, true)] // Same value and unit. - [InlineData(1, ApparentPowerUnit.Voltampere, 2, ApparentPowerUnit.Voltampere, false)] // Different value. - [InlineData(2, ApparentPowerUnit.Voltampere, 1, ApparentPowerUnit.Gigavoltampere, false)] // Different value and unit. - [InlineData(1, ApparentPowerUnit.Voltampere, 1, ApparentPowerUnit.Gigavoltampere, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ApparentPowerUnit unitA, double valueB, ApparentPowerUnit unitB, bool expectEqual) - { - var a = new ApparentPower(valueA, unitA); - var b = new ApparentPower(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 = ApparentPower.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 = ApparentPower.FromVoltamperes(1); - Assert.True(v.Equals(ApparentPower.FromVoltamperes(1), VoltamperesTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ApparentPower.Zero, VoltamperesTolerance, ComparisonType.Relative)); - Assert.True(ApparentPower.FromVoltamperes(100).Equals(ApparentPower.FromVoltamperes(120), 0.3, ComparisonType.Relative)); - Assert.False(ApparentPower.FromVoltamperes(100).Equals(ApparentPower.FromVoltamperes(120), 0.1, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = ApparentPower.FromVoltamperes(1); - Assert.Throws(() => v.Equals(ApparentPower.FromVoltamperes(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.False(voltampere.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ApparentPower voltampere = ApparentPower.FromVoltamperes(1); - Assert.False(voltampere.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ApparentPowerUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ApparentPower.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - Assert.Equal("1 GVA", new ApparentPower(1, ApparentPowerUnit.Gigavoltampere).ToString()); - Assert.Equal("1 kVA", new ApparentPower(1, ApparentPowerUnit.Kilovoltampere).ToString()); - Assert.Equal("1 MVA", new ApparentPower(1, ApparentPowerUnit.Megavoltampere).ToString()); - Assert.Equal("1 µVA", new ApparentPower(1, ApparentPowerUnit.Microvoltampere).ToString()); - Assert.Equal("1 mVA", new ApparentPower(1, ApparentPowerUnit.Millivoltampere).ToString()); - Assert.Equal("1 VA", new ApparentPower(1, ApparentPowerUnit.Voltampere).ToString()); - } - - [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 GVA", new ApparentPower(1, ApparentPowerUnit.Gigavoltampere).ToString(swedishCulture)); - Assert.Equal("1 kVA", new ApparentPower(1, ApparentPowerUnit.Kilovoltampere).ToString(swedishCulture)); - Assert.Equal("1 MVA", new ApparentPower(1, ApparentPowerUnit.Megavoltampere).ToString(swedishCulture)); - Assert.Equal("1 µVA", new ApparentPower(1, ApparentPowerUnit.Microvoltampere).ToString(swedishCulture)); - Assert.Equal("1 mVA", new ApparentPower(1, ApparentPowerUnit.Millivoltampere).ToString(swedishCulture)); - Assert.Equal("1 VA", new ApparentPower(1, ApparentPowerUnit.Voltampere).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var _ = new CultureScope(CultureInfo.InvariantCulture); - Assert.Equal("0.1 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s1")); - Assert.Equal("0.12 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s2")); - Assert.Equal("0.123 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s3")); - Assert.Equal("0.1235 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s4")); - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s1", culture)); - Assert.Equal("0.12 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s2", culture)); - Assert.Equal("0.123 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s3", culture)); - Assert.Equal("0.1235 VA", new ApparentPower(0.123456, ApparentPowerUnit.Voltampere).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = ApparentPower.FromVoltamperes(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 = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ApparentPower))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ApparentPowerUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(ApparentPower.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(ApparentPower.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = ApparentPower.FromVoltamperes(1.0); - Assert.Equal(new {ApparentPower.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 = ApparentPower.FromVoltamperes(value); - Assert.Equal(ApparentPower.FromVoltamperes(-value), -quantity); - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs deleted file mode 100644 index 05706e2b79..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs +++ /dev/null @@ -1,874 +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.Helpers; -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 Capacitance. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class CapacitanceTestsBase : QuantityTestsBase - { - protected abstract double FaradsInOneFarad { get; } - protected abstract double KilofaradsInOneFarad { get; } - protected abstract double MegafaradsInOneFarad { get; } - protected abstract double MicrofaradsInOneFarad { get; } - protected abstract double MillifaradsInOneFarad { get; } - protected abstract double NanofaradsInOneFarad { get; } - protected abstract double PicofaradsInOneFarad { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double FaradsTolerance { get { return 1e-5; } } - protected virtual double KilofaradsTolerance { get { return 1e-5; } } - protected virtual double MegafaradsTolerance { get { return 1e-5; } } - protected virtual double MicrofaradsTolerance { get { return 1e-5; } } - protected virtual double MillifaradsTolerance { get { return 1e-5; } } - protected virtual double NanofaradsTolerance { get { return 1e-5; } } - protected virtual double PicofaradsTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(CapacitanceUnit unit) - { - return unit switch - { - CapacitanceUnit.Farad => (FaradsInOneFarad, FaradsTolerance), - CapacitanceUnit.Kilofarad => (KilofaradsInOneFarad, KilofaradsTolerance), - CapacitanceUnit.Megafarad => (MegafaradsInOneFarad, MegafaradsTolerance), - CapacitanceUnit.Microfarad => (MicrofaradsInOneFarad, MicrofaradsTolerance), - CapacitanceUnit.Millifarad => (MillifaradsInOneFarad, MillifaradsTolerance), - CapacitanceUnit.Nanofarad => (NanofaradsInOneFarad, NanofaradsTolerance), - CapacitanceUnit.Picofarad => (PicofaradsInOneFarad, PicofaradsTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { CapacitanceUnit.Farad }, - new object[] { CapacitanceUnit.Kilofarad }, - new object[] { CapacitanceUnit.Megafarad }, - new object[] { CapacitanceUnit.Microfarad }, - new object[] { CapacitanceUnit.Millifarad }, - new object[] { CapacitanceUnit.Nanofarad }, - new object[] { CapacitanceUnit.Picofarad }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new Capacitance(); - Assert.Equal(0, quantity.Value); - Assert.Equal(CapacitanceUnit.Farad, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new Capacitance(double.PositiveInfinity, CapacitanceUnit.Farad)); - var exception2 = Record.Exception(() => new Capacitance(double.NegativeInfinity, CapacitanceUnit.Farad)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new Capacitance(double.NaN, CapacitanceUnit.Farad)); - - Assert.Null(exception); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new Capacitance(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new Capacitance(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (Capacitance) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void Capacitance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new Capacitance(1, CapacitanceUnit.Farad); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(Capacitance.Zero, quantityInfo.Zero); - Assert.Equal("Capacitance", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void FaradToCapacitanceUnits() - { - Capacitance farad = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(FaradsInOneFarad, farad.Farads, FaradsTolerance); - AssertEx.EqualTolerance(KilofaradsInOneFarad, farad.Kilofarads, KilofaradsTolerance); - AssertEx.EqualTolerance(MegafaradsInOneFarad, farad.Megafarads, MegafaradsTolerance); - AssertEx.EqualTolerance(MicrofaradsInOneFarad, farad.Microfarads, MicrofaradsTolerance); - AssertEx.EqualTolerance(MillifaradsInOneFarad, farad.Millifarads, MillifaradsTolerance); - AssertEx.EqualTolerance(NanofaradsInOneFarad, farad.Nanofarads, NanofaradsTolerance); - AssertEx.EqualTolerance(PicofaradsInOneFarad, farad.Picofarads, PicofaradsTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = Capacitance.From(1, CapacitanceUnit.Farad); - AssertEx.EqualTolerance(1, quantity00.Farads, FaradsTolerance); - Assert.Equal(CapacitanceUnit.Farad, quantity00.Unit); - - var quantity01 = Capacitance.From(1, CapacitanceUnit.Kilofarad); - AssertEx.EqualTolerance(1, quantity01.Kilofarads, KilofaradsTolerance); - Assert.Equal(CapacitanceUnit.Kilofarad, quantity01.Unit); - - var quantity02 = Capacitance.From(1, CapacitanceUnit.Megafarad); - AssertEx.EqualTolerance(1, quantity02.Megafarads, MegafaradsTolerance); - Assert.Equal(CapacitanceUnit.Megafarad, quantity02.Unit); - - var quantity03 = Capacitance.From(1, CapacitanceUnit.Microfarad); - AssertEx.EqualTolerance(1, quantity03.Microfarads, MicrofaradsTolerance); - Assert.Equal(CapacitanceUnit.Microfarad, quantity03.Unit); - - var quantity04 = Capacitance.From(1, CapacitanceUnit.Millifarad); - AssertEx.EqualTolerance(1, quantity04.Millifarads, MillifaradsTolerance); - Assert.Equal(CapacitanceUnit.Millifarad, quantity04.Unit); - - var quantity05 = Capacitance.From(1, CapacitanceUnit.Nanofarad); - AssertEx.EqualTolerance(1, quantity05.Nanofarads, NanofaradsTolerance); - Assert.Equal(CapacitanceUnit.Nanofarad, quantity05.Unit); - - var quantity06 = Capacitance.From(1, CapacitanceUnit.Picofarad); - AssertEx.EqualTolerance(1, quantity06.Picofarads, PicofaradsTolerance); - Assert.Equal(CapacitanceUnit.Picofarad, quantity06.Unit); - - } - - [Fact] - public void FromFarads_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => Capacitance.FromFarads(double.PositiveInfinity)); - var exception2 = Record.Exception(() => Capacitance.FromFarads(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromFarads_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => Capacitance.FromFarads(double.NaN)); - - Assert.Null(exception); - } - - [Fact] - public void As() - { - var farad = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(FaradsInOneFarad, farad.As(CapacitanceUnit.Farad), FaradsTolerance); - AssertEx.EqualTolerance(KilofaradsInOneFarad, farad.As(CapacitanceUnit.Kilofarad), KilofaradsTolerance); - AssertEx.EqualTolerance(MegafaradsInOneFarad, farad.As(CapacitanceUnit.Megafarad), MegafaradsTolerance); - AssertEx.EqualTolerance(MicrofaradsInOneFarad, farad.As(CapacitanceUnit.Microfarad), MicrofaradsTolerance); - AssertEx.EqualTolerance(MillifaradsInOneFarad, farad.As(CapacitanceUnit.Millifarad), MillifaradsTolerance); - AssertEx.EqualTolerance(NanofaradsInOneFarad, farad.As(CapacitanceUnit.Nanofarad), NanofaradsTolerance); - AssertEx.EqualTolerance(PicofaradsInOneFarad, farad.As(CapacitanceUnit.Picofarad), PicofaradsTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new Capacitance(value: 1, unit: Capacitance.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 = Capacitance.Parse("1 F", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Farads, FaradsTolerance); - Assert.Equal(CapacitanceUnit.Farad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Capacitance.Parse("1 kF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Kilofarads, KilofaradsTolerance); - Assert.Equal(CapacitanceUnit.Kilofarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Capacitance.Parse("1 MF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Megafarads, MegafaradsTolerance); - Assert.Equal(CapacitanceUnit.Megafarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Capacitance.Parse("1 µF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Microfarads, MicrofaradsTolerance); - Assert.Equal(CapacitanceUnit.Microfarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Capacitance.Parse("1 mF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Millifarads, MillifaradsTolerance); - Assert.Equal(CapacitanceUnit.Millifarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Capacitance.Parse("1 nF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Nanofarads, NanofaradsTolerance); - Assert.Equal(CapacitanceUnit.Nanofarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = Capacitance.Parse("1 pF", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.Picofarads, PicofaradsTolerance); - Assert.Equal(CapacitanceUnit.Picofarad, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(Capacitance.TryParse("1 F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Farads, FaradsTolerance); - Assert.Equal(CapacitanceUnit.Farad, parsed.Unit); - } - - { - Assert.True(Capacitance.TryParse("1 kF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Kilofarads, KilofaradsTolerance); - Assert.Equal(CapacitanceUnit.Kilofarad, parsed.Unit); - } - - { - Assert.True(Capacitance.TryParse("1 µF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Microfarads, MicrofaradsTolerance); - Assert.Equal(CapacitanceUnit.Microfarad, parsed.Unit); - } - - { - Assert.True(Capacitance.TryParse("1 nF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Nanofarads, NanofaradsTolerance); - Assert.Equal(CapacitanceUnit.Nanofarad, parsed.Unit); - } - - { - Assert.True(Capacitance.TryParse("1 pF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Picofarads, PicofaradsTolerance); - Assert.Equal(CapacitanceUnit.Picofarad, parsed.Unit); - } - - } - - [Theory] - [InlineData("F", CapacitanceUnit.Farad)] - [InlineData("kF", CapacitanceUnit.Kilofarad)] - [InlineData("MF", CapacitanceUnit.Megafarad)] - [InlineData("µF", CapacitanceUnit.Microfarad)] - [InlineData("mF", CapacitanceUnit.Millifarad)] - [InlineData("nF", CapacitanceUnit.Nanofarad)] - [InlineData("pF", CapacitanceUnit.Picofarad)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CapacitanceUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("F", CapacitanceUnit.Farad)] - [InlineData("kF", CapacitanceUnit.Kilofarad)] - [InlineData("MF", CapacitanceUnit.Megafarad)] - [InlineData("µF", CapacitanceUnit.Microfarad)] - [InlineData("mF", CapacitanceUnit.Millifarad)] - [InlineData("nF", CapacitanceUnit.Nanofarad)] - [InlineData("pF", CapacitanceUnit.Picofarad)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CapacitanceUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "F", CapacitanceUnit.Farad)] - [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] - [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] - [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] - [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] - [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] - [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) - { - using var _ = new CultureScope(culture); - CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "F", CapacitanceUnit.Farad)] - [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] - [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] - [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] - [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] - [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] - [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] - public void ParseUnit_WithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) - { - CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("F", CapacitanceUnit.Farad)] - [InlineData("kF", CapacitanceUnit.Kilofarad)] - [InlineData("MF", CapacitanceUnit.Megafarad)] - [InlineData("µF", CapacitanceUnit.Microfarad)] - [InlineData("mF", CapacitanceUnit.Millifarad)] - [InlineData("nF", CapacitanceUnit.Nanofarad)] - [InlineData("pF", CapacitanceUnit.Picofarad)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CapacitanceUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("F", CapacitanceUnit.Farad)] - [InlineData("kF", CapacitanceUnit.Kilofarad)] - [InlineData("MF", CapacitanceUnit.Megafarad)] - [InlineData("µF", CapacitanceUnit.Microfarad)] - [InlineData("mF", CapacitanceUnit.Millifarad)] - [InlineData("nF", CapacitanceUnit.Nanofarad)] - [InlineData("pF", CapacitanceUnit.Picofarad)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CapacitanceUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "F", CapacitanceUnit.Farad)] - [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] - [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] - [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] - [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] - [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] - [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "F", CapacitanceUnit.Farad)] - [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] - [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] - [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] - [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] - [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] - [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) - { - Assert.True(Capacitance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CapacitanceUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(CapacitanceUnit unit) - { - var inBaseUnits = Capacitance.From(1.0, Capacitance.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(CapacitanceUnit unit) - { - var quantity = Capacitance.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(CapacitanceUnit 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 = Capacitance.Units.First(u => u != Capacitance.BaseUnit); - - var quantity = Capacitance.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(CapacitanceUnit unit) - { - var quantity = default(Capacitance); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - Capacitance farad = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(1, Capacitance.FromFarads(farad.Farads).Farads, FaradsTolerance); - AssertEx.EqualTolerance(1, Capacitance.FromKilofarads(farad.Kilofarads).Farads, KilofaradsTolerance); - AssertEx.EqualTolerance(1, Capacitance.FromMegafarads(farad.Megafarads).Farads, MegafaradsTolerance); - AssertEx.EqualTolerance(1, Capacitance.FromMicrofarads(farad.Microfarads).Farads, MicrofaradsTolerance); - AssertEx.EqualTolerance(1, Capacitance.FromMillifarads(farad.Millifarads).Farads, MillifaradsTolerance); - AssertEx.EqualTolerance(1, Capacitance.FromNanofarads(farad.Nanofarads).Farads, NanofaradsTolerance); - AssertEx.EqualTolerance(1, Capacitance.FromPicofarads(farad.Picofarads).Farads, PicofaradsTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - Capacitance v = Capacitance.FromFarads(1); - AssertEx.EqualTolerance(-1, -v.Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, (Capacitance.FromFarads(3)-v).Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, (v + v).Farads, FaradsTolerance); - AssertEx.EqualTolerance(10, (v*10).Farads, FaradsTolerance); - AssertEx.EqualTolerance(10, (10*v).Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, (Capacitance.FromFarads(10)/5).Farads, FaradsTolerance); - AssertEx.EqualTolerance(2, Capacitance.FromFarads(10)/Capacitance.FromFarads(5), FaradsTolerance); - } - - [Fact] - public void ComparisonOperators() - { - Capacitance oneFarad = Capacitance.FromFarads(1); - Capacitance twoFarads = Capacitance.FromFarads(2); - - Assert.True(oneFarad < twoFarads); - Assert.True(oneFarad <= twoFarads); - Assert.True(twoFarads > oneFarad); - Assert.True(twoFarads >= oneFarad); - - Assert.False(oneFarad > twoFarads); - Assert.False(oneFarad >= twoFarads); - Assert.False(twoFarads < oneFarad); - Assert.False(twoFarads <= oneFarad); - } - - [Fact] - public void CompareToIsImplemented() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.Equal(0, farad.CompareTo(farad)); - Assert.True(farad.CompareTo(Capacitance.Zero) > 0); - Assert.True(Capacitance.Zero.CompareTo(farad) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.Throws(() => farad.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.Throws(() => farad.CompareTo(null)); - } - - [Theory] - [InlineData(1, CapacitanceUnit.Farad, 1, CapacitanceUnit.Farad, true)] // Same value and unit. - [InlineData(1, CapacitanceUnit.Farad, 2, CapacitanceUnit.Farad, false)] // Different value. - [InlineData(2, CapacitanceUnit.Farad, 1, CapacitanceUnit.Kilofarad, false)] // Different value and unit. - [InlineData(1, CapacitanceUnit.Farad, 1, CapacitanceUnit.Kilofarad, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, CapacitanceUnit unitA, double valueB, CapacitanceUnit unitB, bool expectEqual) - { - var a = new Capacitance(valueA, unitA); - var b = new Capacitance(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 = Capacitance.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 = Capacitance.FromFarads(1); - Assert.True(v.Equals(Capacitance.FromFarads(1), FaradsTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(Capacitance.Zero, FaradsTolerance, ComparisonType.Relative)); - Assert.True(Capacitance.FromFarads(100).Equals(Capacitance.FromFarads(120), 0.3, ComparisonType.Relative)); - Assert.False(Capacitance.FromFarads(100).Equals(Capacitance.FromFarads(120), 0.1, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = Capacitance.FromFarads(1); - Assert.Throws(() => v.Equals(Capacitance.FromFarads(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.False(farad.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Capacitance farad = Capacitance.FromFarads(1); - Assert.False(farad.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(CapacitanceUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(Capacitance.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - Assert.Equal("1 F", new Capacitance(1, CapacitanceUnit.Farad).ToString()); - Assert.Equal("1 kF", new Capacitance(1, CapacitanceUnit.Kilofarad).ToString()); - Assert.Equal("1 MF", new Capacitance(1, CapacitanceUnit.Megafarad).ToString()); - Assert.Equal("1 µF", new Capacitance(1, CapacitanceUnit.Microfarad).ToString()); - Assert.Equal("1 mF", new Capacitance(1, CapacitanceUnit.Millifarad).ToString()); - Assert.Equal("1 nF", new Capacitance(1, CapacitanceUnit.Nanofarad).ToString()); - Assert.Equal("1 pF", new Capacitance(1, CapacitanceUnit.Picofarad).ToString()); - } - - [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 F", new Capacitance(1, CapacitanceUnit.Farad).ToString(swedishCulture)); - Assert.Equal("1 kF", new Capacitance(1, CapacitanceUnit.Kilofarad).ToString(swedishCulture)); - Assert.Equal("1 MF", new Capacitance(1, CapacitanceUnit.Megafarad).ToString(swedishCulture)); - Assert.Equal("1 µF", new Capacitance(1, CapacitanceUnit.Microfarad).ToString(swedishCulture)); - Assert.Equal("1 mF", new Capacitance(1, CapacitanceUnit.Millifarad).ToString(swedishCulture)); - Assert.Equal("1 nF", new Capacitance(1, CapacitanceUnit.Nanofarad).ToString(swedishCulture)); - Assert.Equal("1 pF", new Capacitance(1, CapacitanceUnit.Picofarad).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var _ = new CultureScope(CultureInfo.InvariantCulture); - Assert.Equal("0.1 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s1")); - Assert.Equal("0.12 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s2")); - Assert.Equal("0.123 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s3")); - Assert.Equal("0.1235 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s4")); - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s1", culture)); - Assert.Equal("0.12 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s2", culture)); - Assert.Equal("0.123 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s3", culture)); - Assert.Equal("0.1235 F", new Capacitance(0.123456, CapacitanceUnit.Farad).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = Capacitance.FromFarads(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 = Capacitance.FromFarads(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Capacitance))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(CapacitanceUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal(Capacitance.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal(Capacitance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = Capacitance.FromFarads(1.0); - Assert.Equal(new {Capacitance.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 = Capacitance.FromFarads(value); - Assert.Equal(Capacitance.FromFarads(-value), -quantity); - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs deleted file mode 100644 index 4c2eb1e3bc..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs +++ /dev/null @@ -1,806 +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.Helpers; -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_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new ElectricPotentialAc(double.PositiveInfinity, ElectricPotentialAcUnit.VoltAc)); - var exception2 = Record.Exception(() => new ElectricPotentialAc(double.NegativeInfinity, ElectricPotentialAcUnit.VoltAc)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new ElectricPotentialAc(double.NaN, ElectricPotentialAcUnit.VoltAc)); - - Assert.Null(exception); - } - - [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_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => ElectricPotentialAc.FromVoltsAc(double.PositiveInfinity)); - var exception2 = Record.Exception(() => ElectricPotentialAc.FromVoltsAc(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromVoltsAc_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => ElectricPotentialAc.FromVoltsAc(double.NaN)); - - Assert.Null(exception); - } - - [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); - } - - } - - [Theory] - [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - using var _ = new CultureScope(culture); - ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] - public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] - [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] - [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] - [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] - [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) - { - Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialAcUnit parsedUnit)); - Assert.Equal(expectedUnit, 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)); - Assert.True(ElectricPotentialAc.FromVoltsAc(100).Equals(ElectricPotentialAc.FromVoltsAc(120), 0.3, ComparisonType.Relative)); - Assert.False(ElectricPotentialAc.FromVoltsAc(100).Equals(ElectricPotentialAc.FromVoltsAc(120), 0.1, 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 = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ElectricPotentialAc.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - 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()); - } - - [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 _ = new CultureScope(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")); - } - - [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 c8bc7c5b68..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs +++ /dev/null @@ -1,806 +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.Helpers; -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_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new ElectricPotentialDc(double.PositiveInfinity, ElectricPotentialDcUnit.VoltDc)); - var exception2 = Record.Exception(() => new ElectricPotentialDc(double.NegativeInfinity, ElectricPotentialDcUnit.VoltDc)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new ElectricPotentialDc(double.NaN, ElectricPotentialDcUnit.VoltDc)); - - Assert.Null(exception); - } - - [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_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => ElectricPotentialDc.FromVoltsDc(double.PositiveInfinity)); - var exception2 = Record.Exception(() => ElectricPotentialDc.FromVoltsDc(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromVoltsDc_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => ElectricPotentialDc.FromVoltsDc(double.NaN)); - - Assert.Null(exception); - } - - [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); - } - - } - - [Theory] - [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - using var _ = new CultureScope(culture); - ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] - public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] - [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] - [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] - [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] - [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) - { - Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialDcUnit parsedUnit)); - Assert.Equal(expectedUnit, 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)); - Assert.True(ElectricPotentialDc.FromVoltsDc(100).Equals(ElectricPotentialDc.FromVoltsDc(120), 0.3, ComparisonType.Relative)); - Assert.False(ElectricPotentialDc.FromVoltsDc(100).Equals(ElectricPotentialDc.FromVoltsDc(120), 0.1, 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 = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ElectricPotentialDc.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - 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()); - } - - [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 _ = new CultureScope(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")); - } - - [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.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs deleted file mode 100644 index c404281126..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs +++ /dev/null @@ -1,750 +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.Helpers; -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 ReactiveEnergy. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ReactiveEnergyTestsBase : QuantityTestsBase - { - protected abstract double KilovoltampereReactiveHoursInOneVoltampereReactiveHour { get; } - protected abstract double MegavoltampereReactiveHoursInOneVoltampereReactiveHour { get; } - protected abstract double VoltampereReactiveHoursInOneVoltampereReactiveHour { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double KilovoltampereReactiveHoursTolerance { get { return 1e-5; } } - protected virtual double MegavoltampereReactiveHoursTolerance { get { return 1e-5; } } - protected virtual double VoltampereReactiveHoursTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ReactiveEnergyUnit unit) - { - return unit switch - { - ReactiveEnergyUnit.KilovoltampereReactiveHour => (KilovoltampereReactiveHoursInOneVoltampereReactiveHour, KilovoltampereReactiveHoursTolerance), - ReactiveEnergyUnit.MegavoltampereReactiveHour => (MegavoltampereReactiveHoursInOneVoltampereReactiveHour, MegavoltampereReactiveHoursTolerance), - ReactiveEnergyUnit.VoltampereReactiveHour => (VoltampereReactiveHoursInOneVoltampereReactiveHour, VoltampereReactiveHoursTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { ReactiveEnergyUnit.KilovoltampereReactiveHour }, - new object[] { ReactiveEnergyUnit.MegavoltampereReactiveHour }, - new object[] { ReactiveEnergyUnit.VoltampereReactiveHour }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new ReactiveEnergy(); - Assert.Equal(0, quantity.Value); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new ReactiveEnergy(double.PositiveInfinity, ReactiveEnergyUnit.VoltampereReactiveHour)); - var exception2 = Record.Exception(() => new ReactiveEnergy(double.NegativeInfinity, ReactiveEnergyUnit.VoltampereReactiveHour)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new ReactiveEnergy(double.NaN, ReactiveEnergyUnit.VoltampereReactiveHour)); - - Assert.Null(exception); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new ReactiveEnergy(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new ReactiveEnergy(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ReactiveEnergy) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void ReactiveEnergy_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new ReactiveEnergy(1, ReactiveEnergyUnit.VoltampereReactiveHour); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(ReactiveEnergy.Zero, quantityInfo.Zero); - Assert.Equal("ReactiveEnergy", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void VoltampereReactiveHourToReactiveEnergyUnits() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(KilovoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = ReactiveEnergy.From(1, ReactiveEnergyUnit.KilovoltampereReactiveHour); - AssertEx.EqualTolerance(1, quantity00.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.KilovoltampereReactiveHour, quantity00.Unit); - - var quantity01 = ReactiveEnergy.From(1, ReactiveEnergyUnit.MegavoltampereReactiveHour); - AssertEx.EqualTolerance(1, quantity01.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.MegavoltampereReactiveHour, quantity01.Unit); - - var quantity02 = ReactiveEnergy.From(1, ReactiveEnergyUnit.VoltampereReactiveHour); - AssertEx.EqualTolerance(1, quantity02.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, quantity02.Unit); - - } - - [Fact] - public void FromVoltampereReactiveHours_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => ReactiveEnergy.FromVoltampereReactiveHours(double.PositiveInfinity)); - var exception2 = Record.Exception(() => ReactiveEnergy.FromVoltampereReactiveHours(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromVoltampereReactiveHours_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => ReactiveEnergy.FromVoltampereReactiveHours(double.NaN)); - - Assert.Null(exception); - } - - [Fact] - public void As() - { - var voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(KilovoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.KilovoltampereReactiveHour), KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(MegavoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.MegavoltampereReactiveHour), MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ReactiveEnergyUnit.VoltampereReactiveHour), VoltampereReactiveHoursTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new ReactiveEnergy(value: 1, unit: ReactiveEnergy.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 = ReactiveEnergy.Parse("1 kvarh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.KilovoltampereReactiveHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReactiveEnergy.Parse("1 Mvarh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.MegavoltampereReactiveHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReactiveEnergy.Parse("1 varh", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(ReactiveEnergy.TryParse("1 kvarh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.KilovoltampereReactiveHour, parsed.Unit); - } - - { - Assert.True(ReactiveEnergy.TryParse("1 Mvarh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.MegavoltampereReactiveHour, parsed.Unit); - } - - { - Assert.True(ReactiveEnergy.TryParse("1 varh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, parsed.Unit); - } - - } - - [Theory] - [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactiveEnergyUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactiveEnergyUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) - { - using var _ = new CultureScope(culture); - ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void ParseUnit_WithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) - { - ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactiveEnergyUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactiveEnergyUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] - [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] - [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) - { - Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReactiveEnergyUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(ReactiveEnergyUnit unit) - { - var inBaseUnits = ReactiveEnergy.From(1.0, ReactiveEnergy.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(ReactiveEnergyUnit unit) - { - var quantity = ReactiveEnergy.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ReactiveEnergyUnit 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 = ReactiveEnergy.Units.First(u => u != ReactiveEnergy.BaseUnit); - - var quantity = ReactiveEnergy.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ReactiveEnergyUnit unit) - { - var quantity = default(ReactiveEnergy); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(1, ReactiveEnergy.FromKilovoltampereReactiveHours(voltamperereactivehour.KilovoltampereReactiveHours).VoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(1, ReactiveEnergy.FromMegavoltampereReactiveHours(voltamperereactivehour.MegavoltampereReactiveHours).VoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(1, ReactiveEnergy.FromVoltampereReactiveHours(voltamperereactivehour.VoltampereReactiveHours).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ReactiveEnergy v = ReactiveEnergy.FromVoltampereReactiveHours(1); - AssertEx.EqualTolerance(-1, -v.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, (ReactiveEnergy.FromVoltampereReactiveHours(3)-v).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, (ReactiveEnergy.FromVoltampereReactiveHours(10)/5).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); - AssertEx.EqualTolerance(2, ReactiveEnergy.FromVoltampereReactiveHours(10)/ReactiveEnergy.FromVoltampereReactiveHours(5), VoltampereReactiveHoursTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ReactiveEnergy oneVoltampereReactiveHour = ReactiveEnergy.FromVoltampereReactiveHours(1); - ReactiveEnergy twoVoltampereReactiveHours = ReactiveEnergy.FromVoltampereReactiveHours(2); - - Assert.True(oneVoltampereReactiveHour < twoVoltampereReactiveHours); - Assert.True(oneVoltampereReactiveHour <= twoVoltampereReactiveHours); - Assert.True(twoVoltampereReactiveHours > oneVoltampereReactiveHour); - Assert.True(twoVoltampereReactiveHours >= oneVoltampereReactiveHour); - - Assert.False(oneVoltampereReactiveHour > twoVoltampereReactiveHours); - Assert.False(oneVoltampereReactiveHour >= twoVoltampereReactiveHours); - Assert.False(twoVoltampereReactiveHours < oneVoltampereReactiveHour); - Assert.False(twoVoltampereReactiveHours <= oneVoltampereReactiveHour); - } - - [Fact] - public void CompareToIsImplemented() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Equal(0, voltamperereactivehour.CompareTo(voltamperereactivehour)); - Assert.True(voltamperereactivehour.CompareTo(ReactiveEnergy.Zero) > 0); - Assert.True(ReactiveEnergy.Zero.CompareTo(voltamperereactivehour) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Throws(() => voltamperereactivehour.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Throws(() => voltamperereactivehour.CompareTo(null)); - } - - [Theory] - [InlineData(1, ReactiveEnergyUnit.VoltampereReactiveHour, 1, ReactiveEnergyUnit.VoltampereReactiveHour, true)] // Same value and unit. - [InlineData(1, ReactiveEnergyUnit.VoltampereReactiveHour, 2, ReactiveEnergyUnit.VoltampereReactiveHour, false)] // Different value. - [InlineData(2, ReactiveEnergyUnit.VoltampereReactiveHour, 1, ReactiveEnergyUnit.KilovoltampereReactiveHour, false)] // Different value and unit. - [InlineData(1, ReactiveEnergyUnit.VoltampereReactiveHour, 1, ReactiveEnergyUnit.KilovoltampereReactiveHour, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ReactiveEnergyUnit unitA, double valueB, ReactiveEnergyUnit unitB, bool expectEqual) - { - var a = new ReactiveEnergy(valueA, unitA); - var b = new ReactiveEnergy(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 = ReactiveEnergy.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 = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.True(v.Equals(ReactiveEnergy.FromVoltampereReactiveHours(1), VoltampereReactiveHoursTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ReactiveEnergy.Zero, VoltampereReactiveHoursTolerance, ComparisonType.Relative)); - Assert.True(ReactiveEnergy.FromVoltampereReactiveHours(100).Equals(ReactiveEnergy.FromVoltampereReactiveHours(120), 0.3, ComparisonType.Relative)); - Assert.False(ReactiveEnergy.FromVoltampereReactiveHours(100).Equals(ReactiveEnergy.FromVoltampereReactiveHours(120), 0.1, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.Throws(() => v.Equals(ReactiveEnergy.FromVoltampereReactiveHours(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.False(voltamperereactivehour.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ReactiveEnergy voltamperereactivehour = ReactiveEnergy.FromVoltampereReactiveHours(1); - Assert.False(voltamperereactivehour.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ReactiveEnergyUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ReactiveEnergy.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - Assert.Equal("1 kvarh", new ReactiveEnergy(1, ReactiveEnergyUnit.KilovoltampereReactiveHour).ToString()); - Assert.Equal("1 Mvarh", new ReactiveEnergy(1, ReactiveEnergyUnit.MegavoltampereReactiveHour).ToString()); - Assert.Equal("1 varh", new ReactiveEnergy(1, ReactiveEnergyUnit.VoltampereReactiveHour).ToString()); - } - - [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 kvarh", new ReactiveEnergy(1, ReactiveEnergyUnit.KilovoltampereReactiveHour).ToString(swedishCulture)); - Assert.Equal("1 Mvarh", new ReactiveEnergy(1, ReactiveEnergyUnit.MegavoltampereReactiveHour).ToString(swedishCulture)); - Assert.Equal("1 varh", new ReactiveEnergy(1, ReactiveEnergyUnit.VoltampereReactiveHour).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var _ = new CultureScope(CultureInfo.InvariantCulture); - Assert.Equal("0.1 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s1")); - Assert.Equal("0.12 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s2")); - Assert.Equal("0.123 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s3")); - Assert.Equal("0.1235 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s4")); - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s1", culture)); - Assert.Equal("0.12 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s2", culture)); - Assert.Equal("0.123 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s3", culture)); - Assert.Equal("0.1235 varh", new ReactiveEnergy(0.123456, ReactiveEnergyUnit.VoltampereReactiveHour).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(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 = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ReactiveEnergy))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ReactiveEnergyUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(ReactiveEnergy.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(ReactiveEnergy.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = ReactiveEnergy.FromVoltampereReactiveHours(1.0); - Assert.Equal(new {ReactiveEnergy.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 = ReactiveEnergy.FromVoltampereReactiveHours(value); - Assert.Equal(ReactiveEnergy.FromVoltampereReactiveHours(-value), -quantity); - } - } -} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs deleted file mode 100644 index b0653c9ab1..0000000000 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs +++ /dev/null @@ -1,784 +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.Helpers; -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 ReactivePower. - /// -// ReSharper disable once PartialTypeWithSinglePart - public abstract partial class ReactivePowerTestsBase : QuantityTestsBase - { - protected abstract double GigavoltamperesReactiveInOneVoltampereReactive { get; } - protected abstract double KilovoltamperesReactiveInOneVoltampereReactive { get; } - protected abstract double MegavoltamperesReactiveInOneVoltampereReactive { get; } - protected abstract double VoltamperesReactiveInOneVoltampereReactive { get; } - -// ReSharper disable VirtualMemberNeverOverriden.Global - protected virtual double GigavoltamperesReactiveTolerance { get { return 1e-5; } } - protected virtual double KilovoltamperesReactiveTolerance { get { return 1e-5; } } - protected virtual double MegavoltamperesReactiveTolerance { get { return 1e-5; } } - protected virtual double VoltamperesReactiveTolerance { get { return 1e-5; } } -// ReSharper restore VirtualMemberNeverOverriden.Global - - protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ReactivePowerUnit unit) - { - return unit switch - { - ReactivePowerUnit.GigavoltampereReactive => (GigavoltamperesReactiveInOneVoltampereReactive, GigavoltamperesReactiveTolerance), - ReactivePowerUnit.KilovoltampereReactive => (KilovoltamperesReactiveInOneVoltampereReactive, KilovoltamperesReactiveTolerance), - ReactivePowerUnit.MegavoltampereReactive => (MegavoltamperesReactiveInOneVoltampereReactive, MegavoltamperesReactiveTolerance), - ReactivePowerUnit.VoltampereReactive => (VoltamperesReactiveInOneVoltampereReactive, VoltamperesReactiveTolerance), - _ => throw new NotSupportedException() - }; - } - - public static IEnumerable UnitTypes = new List - { - new object[] { ReactivePowerUnit.GigavoltampereReactive }, - new object[] { ReactivePowerUnit.KilovoltampereReactive }, - new object[] { ReactivePowerUnit.MegavoltampereReactive }, - new object[] { ReactivePowerUnit.VoltampereReactive }, - }; - - [Fact] - public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() - { - var quantity = new ReactivePower(); - Assert.Equal(0, quantity.Value); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, quantity.Unit); - } - - [Fact] - public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => new ReactivePower(double.PositiveInfinity, ReactivePowerUnit.VoltampereReactive)); - var exception2 = Record.Exception(() => new ReactivePower(double.NegativeInfinity, ReactivePowerUnit.VoltampereReactive)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void Ctor_WithNaNValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => new ReactivePower(double.NaN, ReactivePowerUnit.VoltampereReactive)); - - Assert.Null(exception); - } - - [Fact] - public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() - { - Assert.Throws(() => new ReactivePower(value: 1, unitSystem: null)); - } - - [Fact] - public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - Func TestCode = () => new ReactivePower(value: 1, unitSystem: UnitSystem.SI); - if (SupportsSIUnitSystem) - { - var quantity = (ReactivePower) TestCode(); - Assert.Equal(1, quantity.Value); - } - else - { - Assert.Throws(TestCode); - } - } - - [Fact] - public void ReactivePower_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() - { - var quantity = new ReactivePower(1, ReactivePowerUnit.VoltampereReactive); - - QuantityInfo quantityInfo = quantity.QuantityInfo; - - Assert.Equal(ReactivePower.Zero, quantityInfo.Zero); - Assert.Equal("ReactivePower", quantityInfo.Name); - - var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); - var unitNames = units.Select(x => x.ToString()); - } - - [Fact] - public void VoltampereReactiveToReactivePowerUnits() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(GigavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(KilovoltamperesReactiveInOneVoltampereReactive, voltamperereactive.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(MegavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, voltamperereactive.VoltamperesReactive, VoltamperesReactiveTolerance); - } - - [Fact] - public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() - { - var quantity00 = ReactivePower.From(1, ReactivePowerUnit.GigavoltampereReactive); - AssertEx.EqualTolerance(1, quantity00.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.GigavoltampereReactive, quantity00.Unit); - - var quantity01 = ReactivePower.From(1, ReactivePowerUnit.KilovoltampereReactive); - AssertEx.EqualTolerance(1, quantity01.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.KilovoltampereReactive, quantity01.Unit); - - var quantity02 = ReactivePower.From(1, ReactivePowerUnit.MegavoltampereReactive); - AssertEx.EqualTolerance(1, quantity02.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.MegavoltampereReactive, quantity02.Unit); - - var quantity03 = ReactivePower.From(1, ReactivePowerUnit.VoltampereReactive); - AssertEx.EqualTolerance(1, quantity03.VoltamperesReactive, VoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, quantity03.Unit); - - } - - [Fact] - public void FromVoltamperesReactive_WithInfinityValue_DoNotThrowsArgumentException() - { - var exception1 = Record.Exception(() => ReactivePower.FromVoltamperesReactive(double.PositiveInfinity)); - var exception2 = Record.Exception(() => ReactivePower.FromVoltamperesReactive(double.NegativeInfinity)); - - Assert.Null(exception1); - Assert.Null(exception2); - } - - [Fact] - public void FromVoltamperesReactive_WithNanValue_DoNotThrowsArgumentException() - { - var exception = Record.Exception(() => ReactivePower.FromVoltamperesReactive(double.NaN)); - - Assert.Null(exception); - } - - [Fact] - public void As() - { - var voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(GigavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.GigavoltampereReactive), GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(KilovoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.KilovoltampereReactive), KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(MegavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.MegavoltampereReactive), MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ReactivePowerUnit.VoltampereReactive), VoltamperesReactiveTolerance); - } - - [Fact] - public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() - { - var quantity = new ReactivePower(value: 1, unit: ReactivePower.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 = ReactivePower.Parse("1 Gvar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.GigavoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReactivePower.Parse("1 kvar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.KilovoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReactivePower.Parse("1 Mvar", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.MegavoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsed = ReactivePower.Parse("1 var", CultureInfo.GetCultureInfo("en-US")); - AssertEx.EqualTolerance(1, parsed.VoltamperesReactive, VoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, parsed.Unit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParse() - { - { - Assert.True(ReactivePower.TryParse("1 Gvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.GigavoltampereReactive, parsed.Unit); - } - - { - Assert.True(ReactivePower.TryParse("1 kvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.KilovoltampereReactive, parsed.Unit); - } - - { - Assert.True(ReactivePower.TryParse("1 Mvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.MegavoltampereReactive, parsed.Unit); - } - - { - Assert.True(ReactivePower.TryParse("1 var", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.VoltamperesReactive, VoltamperesReactiveTolerance); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, parsed.Unit); - } - - } - - [Theory] - [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("var", ReactivePowerUnit.VoltampereReactive)] - public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactivePowerUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("var", ReactivePowerUnit.VoltampereReactive)] - public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactivePowerUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] - public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) - { - using var _ = new CultureScope(culture); - ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] - public void ParseUnit_WithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) - { - ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("var", ReactivePowerUnit.VoltampereReactive)] - public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactivePowerUnit expectedUnit) - { - // Fallback culture "en-US" is always localized - using var _ = new CultureScope("en-US"); - Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("var", ReactivePowerUnit.VoltampereReactive)] - public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactivePowerUnit expectedUnit) - { - // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. - using var _ = new CultureScope("is-IS"); - Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] - public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) - { - using var _ = new CultureScope(culture); - Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] - [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] - [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] - [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] - public void TryParseUnit_WithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) - { - Assert.True(ReactivePower.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReactivePowerUnit parsedUnit)); - Assert.Equal(expectedUnit, parsedUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit(ReactivePowerUnit unit) - { - var inBaseUnits = ReactivePower.From(1.0, ReactivePower.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(ReactivePowerUnit unit) - { - var quantity = ReactivePower.From(3.0, unit); - var toUnitWithSameUnit = quantity.ToUnit(unit); - Assert.Equal(quantity, toUnitWithSameUnit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ReactivePowerUnit 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 = ReactivePower.Units.First(u => u != ReactivePower.BaseUnit); - - var quantity = ReactivePower.From(3.0, fromUnit); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Theory] - [MemberData(nameof(UnitTypes))] - public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ReactivePowerUnit unit) - { - var quantity = default(ReactivePower); - var converted = quantity.ToUnit(unit); - Assert.Equal(converted.Unit, unit); - } - - [Fact] - public void ConversionRoundTrip() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(1, ReactivePower.FromGigavoltamperesReactive(voltamperereactive.GigavoltamperesReactive).VoltamperesReactive, GigavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.FromKilovoltamperesReactive(voltamperereactive.KilovoltamperesReactive).VoltamperesReactive, KilovoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.FromMegavoltamperesReactive(voltamperereactive.MegavoltamperesReactive).VoltamperesReactive, MegavoltamperesReactiveTolerance); - AssertEx.EqualTolerance(1, ReactivePower.FromVoltamperesReactive(voltamperereactive.VoltamperesReactive).VoltamperesReactive, VoltamperesReactiveTolerance); - } - - [Fact] - public void ArithmeticOperators() - { - ReactivePower v = ReactivePower.FromVoltamperesReactive(1); - AssertEx.EqualTolerance(-1, -v.VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, (ReactivePower.FromVoltamperesReactive(3)-v).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, (v + v).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(10, (v*10).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(10, (10*v).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, (ReactivePower.FromVoltamperesReactive(10)/5).VoltamperesReactive, VoltamperesReactiveTolerance); - AssertEx.EqualTolerance(2, ReactivePower.FromVoltamperesReactive(10)/ReactivePower.FromVoltamperesReactive(5), VoltamperesReactiveTolerance); - } - - [Fact] - public void ComparisonOperators() - { - ReactivePower oneVoltampereReactive = ReactivePower.FromVoltamperesReactive(1); - ReactivePower twoVoltamperesReactive = ReactivePower.FromVoltamperesReactive(2); - - Assert.True(oneVoltampereReactive < twoVoltamperesReactive); - Assert.True(oneVoltampereReactive <= twoVoltamperesReactive); - Assert.True(twoVoltamperesReactive > oneVoltampereReactive); - Assert.True(twoVoltamperesReactive >= oneVoltampereReactive); - - Assert.False(oneVoltampereReactive > twoVoltamperesReactive); - Assert.False(oneVoltampereReactive >= twoVoltamperesReactive); - Assert.False(twoVoltamperesReactive < oneVoltampereReactive); - Assert.False(twoVoltamperesReactive <= oneVoltampereReactive); - } - - [Fact] - public void CompareToIsImplemented() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.Equal(0, voltamperereactive.CompareTo(voltamperereactive)); - Assert.True(voltamperereactive.CompareTo(ReactivePower.Zero) > 0); - Assert.True(ReactivePower.Zero.CompareTo(voltamperereactive) < 0); - } - - [Fact] - public void CompareToThrowsOnTypeMismatch() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.Throws(() => voltamperereactive.CompareTo(new object())); - } - - [Fact] - public void CompareToThrowsOnNull() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.Throws(() => voltamperereactive.CompareTo(null)); - } - - [Theory] - [InlineData(1, ReactivePowerUnit.VoltampereReactive, 1, ReactivePowerUnit.VoltampereReactive, true)] // Same value and unit. - [InlineData(1, ReactivePowerUnit.VoltampereReactive, 2, ReactivePowerUnit.VoltampereReactive, false)] // Different value. - [InlineData(2, ReactivePowerUnit.VoltampereReactive, 1, ReactivePowerUnit.GigavoltampereReactive, false)] // Different value and unit. - [InlineData(1, ReactivePowerUnit.VoltampereReactive, 1, ReactivePowerUnit.GigavoltampereReactive, false)] // Different unit. - public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ReactivePowerUnit unitA, double valueB, ReactivePowerUnit unitB, bool expectEqual) - { - var a = new ReactivePower(valueA, unitA); - var b = new ReactivePower(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 = ReactivePower.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 = ReactivePower.FromVoltamperesReactive(1); - Assert.True(v.Equals(ReactivePower.FromVoltamperesReactive(1), VoltamperesReactiveTolerance, ComparisonType.Relative)); - Assert.False(v.Equals(ReactivePower.Zero, VoltamperesReactiveTolerance, ComparisonType.Relative)); - Assert.True(ReactivePower.FromVoltamperesReactive(100).Equals(ReactivePower.FromVoltamperesReactive(120), 0.3, ComparisonType.Relative)); - Assert.False(ReactivePower.FromVoltamperesReactive(100).Equals(ReactivePower.FromVoltamperesReactive(120), 0.1, ComparisonType.Relative)); - } - - [Fact] - public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() - { - var v = ReactivePower.FromVoltamperesReactive(1); - Assert.Throws(() => v.Equals(ReactivePower.FromVoltamperesReactive(1), -1, ComparisonType.Relative)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.False(voltamperereactive.Equals(new object())); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - ReactivePower voltamperereactive = ReactivePower.FromVoltamperesReactive(1); - Assert.False(voltamperereactive.Equals(null)); - } - - [Fact] - public void HasAtLeastOneAbbreviationSpecified() - { - var units = Enum.GetValues(typeof(ReactivePowerUnit)).Cast(); - foreach (var unit in units) - { - var defaultAbbreviation = UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit); - } - } - - [Fact] - public void BaseDimensionsShouldNeverBeNull() - { - Assert.False(ReactivePower.BaseDimensions is null); - } - - [Fact] - public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() - { - using var _ = new CultureScope("en-US"); - Assert.Equal("1 Gvar", new ReactivePower(1, ReactivePowerUnit.GigavoltampereReactive).ToString()); - Assert.Equal("1 kvar", new ReactivePower(1, ReactivePowerUnit.KilovoltampereReactive).ToString()); - Assert.Equal("1 Mvar", new ReactivePower(1, ReactivePowerUnit.MegavoltampereReactive).ToString()); - Assert.Equal("1 var", new ReactivePower(1, ReactivePowerUnit.VoltampereReactive).ToString()); - } - - [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 Gvar", new ReactivePower(1, ReactivePowerUnit.GigavoltampereReactive).ToString(swedishCulture)); - Assert.Equal("1 kvar", new ReactivePower(1, ReactivePowerUnit.KilovoltampereReactive).ToString(swedishCulture)); - Assert.Equal("1 Mvar", new ReactivePower(1, ReactivePowerUnit.MegavoltampereReactive).ToString(swedishCulture)); - Assert.Equal("1 var", new ReactivePower(1, ReactivePowerUnit.VoltampereReactive).ToString(swedishCulture)); - } - - [Fact] - public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() - { - var _ = new CultureScope(CultureInfo.InvariantCulture); - Assert.Equal("0.1 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s1")); - Assert.Equal("0.12 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s2")); - Assert.Equal("0.123 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s3")); - Assert.Equal("0.1235 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s4")); - } - - [Fact] - public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() - { - var culture = CultureInfo.InvariantCulture; - Assert.Equal("0.1 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s1", culture)); - Assert.Equal("0.12 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s2", culture)); - Assert.Equal("0.123 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s3", culture)); - Assert.Equal("0.1235 var", new ReactivePower(0.123456, ReactivePowerUnit.VoltampereReactive).ToString("s4", culture)); - } - - [Theory] - [InlineData(null)] - [InlineData("en-US")] - public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) - { - var quantity = ReactivePower.FromVoltamperesReactive(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 = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); - } - - [Fact] - public void Convert_ToBool_ThrowsInvalidCastException() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Throws(() => Convert.ToBoolean(quantity)); - } - - [Fact] - public void Convert_ToByte_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); - } - - [Fact] - public void Convert_ToChar_ThrowsInvalidCastException() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Throws(() => Convert.ToChar(quantity)); - } - - [Fact] - public void Convert_ToDateTime_ThrowsInvalidCastException() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Throws(() => Convert.ToDateTime(quantity)); - } - - [Fact] - public void Convert_ToDecimal_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); - } - - [Fact] - public void Convert_ToDouble_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); - } - - [Fact] - public void Convert_ToInt16_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); - } - - [Fact] - public void Convert_ToInt32_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); - } - - [Fact] - public void Convert_ToInt64_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); - } - - [Fact] - public void Convert_ToSByte_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); - } - - [Fact] - public void Convert_ToSingle_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); - } - - [Fact] - public void Convert_ToString_EqualsToString() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); - } - - [Fact] - public void Convert_ToUInt16_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); - } - - [Fact] - public void Convert_ToUInt32_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); - } - - [Fact] - public void Convert_ToUInt64_EqualsValueAsSameType() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); - } - - [Fact] - public void Convert_ChangeType_SelfType_EqualsSelf() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ReactivePower))); - } - - [Fact] - public void Convert_ChangeType_UnitType_EqualsUnit() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ReactivePowerUnit))); - } - - [Fact] - public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(ReactivePower.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); - } - - [Fact] - public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(ReactivePower.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); - } - - [Fact] - public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); - } - - [Fact] - public void GetHashCode_Equals() - { - var quantity = ReactivePower.FromVoltamperesReactive(1.0); - Assert.Equal(new {ReactivePower.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 = ReactivePower.FromVoltamperesReactive(value); - Assert.Equal(ReactivePower.FromVoltamperesReactive(-value), -quantity); - } - } -} diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs deleted file mode 100644 index 3c34b8d258..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ /dev/null @@ -1,954 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// A unit for expressing the integral of apparent power over time, equal to the product of 1 volt-ampere and 1 hour, or to 3600 joules. - /// - /// - /// ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version. - /// - [Obsolete("ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct ApparentEnergy : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - private readonly ApparentEnergyUnit? _unit; - - static ApparentEnergy() - { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = ApparentEnergyUnit.VoltampereHour; - Units = Enum.GetValues(typeof(ApparentEnergyUnit)).Cast().ToArray(); - Zero = new ApparentEnergy(0, BaseUnit); - Info = new QuantityInfo("ApparentEnergy", - new UnitInfo[] - { - new UnitInfo(ApparentEnergyUnit.KilovoltampereHour, "KilovoltampereHours", BaseUnits.Undefined, "ApparentEnergy"), - new UnitInfo(ApparentEnergyUnit.MegavoltampereHour, "MegavoltampereHours", BaseUnits.Undefined, "ApparentEnergy"), - new UnitInfo(ApparentEnergyUnit.VoltampereHour, "VoltampereHours", BaseUnits.Undefined, "ApparentEnergy"), - }, - 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. - public ApparentEnergy(double value, ApparentEnergyUnit unit) - { - _value = 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 ApparentEnergy(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = 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 ApparentEnergy, which is VoltampereHour. All conversions go via this value. - /// - public static ApparentEnergyUnit BaseUnit { get; } - - /// - /// All units of measurement for the ApparentEnergy quantity. - /// - public static ApparentEnergyUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereHour. - /// - public static ApparentEnergy Zero { get; } - - /// - public static ApparentEnergy AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - double IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public ApparentEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => ApparentEnergy.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltampereHours => As(ApparentEnergyUnit.KilovoltampereHour); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltampereHours => As(ApparentEnergyUnit.MegavoltampereHour); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltampereHours => As(ApparentEnergyUnit.VoltampereHour); - - #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: ApparentEnergyUnit -> BaseUnit - unitConverter.SetConversionFunction(ApparentEnergyUnit.KilovoltampereHour, ApparentEnergyUnit.VoltampereHour, quantity => quantity.ToUnit(ApparentEnergyUnit.VoltampereHour)); - unitConverter.SetConversionFunction(ApparentEnergyUnit.MegavoltampereHour, ApparentEnergyUnit.VoltampereHour, quantity => quantity.ToUnit(ApparentEnergyUnit.VoltampereHour)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(ApparentEnergyUnit.VoltampereHour, ApparentEnergyUnit.VoltampereHour, quantity => quantity); - - // Register in unit converter: BaseUnit -> ApparentEnergyUnit - unitConverter.SetConversionFunction(ApparentEnergyUnit.VoltampereHour, ApparentEnergyUnit.KilovoltampereHour, quantity => quantity.ToUnit(ApparentEnergyUnit.KilovoltampereHour)); - unitConverter.SetConversionFunction(ApparentEnergyUnit.VoltampereHour, ApparentEnergyUnit.MegavoltampereHour, quantity => quantity.ToUnit(ApparentEnergyUnit.MegavoltampereHour)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(ApparentEnergyUnit 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(ApparentEnergyUnit unit, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ApparentEnergy FromKilovoltampereHours(double value) - { - return new ApparentEnergy(value, ApparentEnergyUnit.KilovoltampereHour); - } - - /// - /// Creates a from . - /// - public static ApparentEnergy FromMegavoltampereHours(double value) - { - return new ApparentEnergy(value, ApparentEnergyUnit.MegavoltampereHour); - } - - /// - /// Creates a from . - /// - public static ApparentEnergy FromVoltampereHours(double value) - { - return new ApparentEnergy(value, ApparentEnergyUnit.VoltampereHour); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ApparentEnergy unit value. - public static ApparentEnergy From(double value, ApparentEnergyUnit fromUnit) - { - return new ApparentEnergy(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 ApparentEnergy 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 ApparentEnergy Parse(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]string? str, out ApparentEnergy 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ApparentEnergy result) - { - return UnitsNetSetup.Default.QuantityParser.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 ApparentEnergyUnit 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 ApparentEnergyUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]string? str, out ApparentEnergyUnit 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ApparentEnergyUnit unit) - { - return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static ApparentEnergy operator -(ApparentEnergy right) - { - return new ApparentEnergy(-right.Value, right.Unit); - } - - /// Get from adding two . - public static ApparentEnergy operator +(ApparentEnergy left, ApparentEnergy right) - { - return new ApparentEnergy(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static ApparentEnergy operator -(ApparentEnergy left, ApparentEnergy right) - { - return new ApparentEnergy(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static ApparentEnergy operator *(double left, ApparentEnergy right) - { - return new ApparentEnergy(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static ApparentEnergy operator *(ApparentEnergy left, double right) - { - return new ApparentEnergy(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static ApparentEnergy operator /(ApparentEnergy left, double right) - { - return new ApparentEnergy(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(ApparentEnergy left, ApparentEnergy right) - { - return left.VoltampereHours / right.VoltampereHours; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(ApparentEnergy left, ApparentEnergy right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(ApparentEnergy left, ApparentEnergy right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(ApparentEnergy left, ApparentEnergy right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(ApparentEnergy left, ApparentEnergy 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(ApparentEnergy other, ApparentEnergy 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 ==(ApparentEnergy left, ApparentEnergy 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(ApparentEnergy other, ApparentEnergy 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 !=(ApparentEnergy left, ApparentEnergy right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ApparentEnergy other, ApparentEnergy 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 ApparentEnergy otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ApparentEnergy other, ApparentEnergy 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(ApparentEnergy 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 ApparentEnergy otherQuantity)) throw new ArgumentException("Expected type ApparentEnergy.", 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(ApparentEnergy other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another ApparentEnergy 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(ApparentEnergy other, ApparentEnergy 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(ApparentEnergy 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); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is ApparentEnergy otherTyped - && (tolerance is ApparentEnergy toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ApparentEnergy'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(ApparentEnergy other, ApparentEnergy 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 ApparentEnergy. - 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(ApparentEnergyUnit 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 ApparentEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentEnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this ApparentEnergy to another ApparentEnergy with the unit representation . - /// - /// The unit to convert to. - /// A ApparentEnergy with the specified unit. - public ApparentEnergy ToUnit(ApparentEnergyUnit 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 ApparentEnergy with the specified unit. - public ApparentEnergy ToUnit(ApparentEnergyUnit 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(ApparentEnergy), Unit, typeof(ApparentEnergy), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (ApparentEnergy)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(ApparentEnergyUnit unit, [NotNullWhen(true)] out ApparentEnergy? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - ApparentEnergy? convertedOrNull = (Unit, unit) switch - { - // ApparentEnergyUnit -> BaseUnit - (ApparentEnergyUnit.KilovoltampereHour, ApparentEnergyUnit.VoltampereHour) => new ApparentEnergy((_value) * 1e3d, ApparentEnergyUnit.VoltampereHour), - (ApparentEnergyUnit.MegavoltampereHour, ApparentEnergyUnit.VoltampereHour) => new ApparentEnergy((_value) * 1e6d, ApparentEnergyUnit.VoltampereHour), - - // BaseUnit -> ApparentEnergyUnit - (ApparentEnergyUnit.VoltampereHour, ApparentEnergyUnit.KilovoltampereHour) => new ApparentEnergy((_value) / 1e3d, ApparentEnergyUnit.KilovoltampereHour), - (ApparentEnergyUnit.VoltampereHour, ApparentEnergyUnit.MegavoltampereHour) => new ApparentEnergy((_value) / 1e6d, ApparentEnergyUnit.MegavoltampereHour), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is ApparentEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentEnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public ApparentEnergy 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(ApparentEnergyUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.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(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(ApparentEnergy)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ApparentEnergy)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ApparentEnergy)} 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(null, provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(ApparentEnergy)) - return this; - else if (conversionType == typeof(ApparentEnergyUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return ApparentEnergy.Info; - else if (conversionType == typeof(BaseDimensions)) - return ApparentEnergy.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(ApparentEnergy)} 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/ApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs deleted file mode 100644 index a05ce84d64..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs +++ /dev/null @@ -1,1008 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. Apparent power is the product of the root-mean-square of voltage and current. - /// - /// - /// ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version. - /// - [Obsolete("ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct ApparentPower : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - private readonly ApparentPowerUnit? _unit; - - static ApparentPower() - { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = ApparentPowerUnit.Voltampere; - Units = Enum.GetValues(typeof(ApparentPowerUnit)).Cast().ToArray(); - Zero = new ApparentPower(0, BaseUnit); - Info = new QuantityInfo("ApparentPower", - new UnitInfo[] - { - new UnitInfo(ApparentPowerUnit.Gigavoltampere, "Gigavoltamperes", BaseUnits.Undefined, "ApparentPower"), - new UnitInfo(ApparentPowerUnit.Kilovoltampere, "Kilovoltamperes", BaseUnits.Undefined, "ApparentPower"), - new UnitInfo(ApparentPowerUnit.Megavoltampere, "Megavoltamperes", BaseUnits.Undefined, "ApparentPower"), - new UnitInfo(ApparentPowerUnit.Microvoltampere, "Microvoltamperes", BaseUnits.Undefined, "ApparentPower"), - new UnitInfo(ApparentPowerUnit.Millivoltampere, "Millivoltamperes", BaseUnits.Undefined, "ApparentPower"), - new UnitInfo(ApparentPowerUnit.Voltampere, "Voltamperes", BaseUnits.Undefined, "ApparentPower"), - }, - 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. - public ApparentPower(double value, ApparentPowerUnit unit) - { - _value = 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 ApparentPower(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = 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 ApparentPower, which is Voltampere. All conversions go via this value. - /// - public static ApparentPowerUnit BaseUnit { get; } - - /// - /// All units of measurement for the ApparentPower quantity. - /// - public static ApparentPowerUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Voltampere. - /// - public static ApparentPower Zero { get; } - - /// - public static ApparentPower AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - double IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public ApparentPowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => ApparentPower.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double Gigavoltamperes => As(ApparentPowerUnit.Gigavoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Kilovoltamperes => As(ApparentPowerUnit.Kilovoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Megavoltamperes => As(ApparentPowerUnit.Megavoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Microvoltamperes => As(ApparentPowerUnit.Microvoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Millivoltamperes => As(ApparentPowerUnit.Millivoltampere); - - /// - /// Gets a value of this quantity converted into - /// - public double Voltamperes => As(ApparentPowerUnit.Voltampere); - - #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: ApparentPowerUnit -> BaseUnit - unitConverter.SetConversionFunction(ApparentPowerUnit.Gigavoltampere, ApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Voltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Kilovoltampere, ApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Voltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Megavoltampere, ApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Voltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Microvoltampere, ApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Voltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Millivoltampere, ApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Voltampere)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(ApparentPowerUnit.Voltampere, ApparentPowerUnit.Voltampere, quantity => quantity); - - // Register in unit converter: BaseUnit -> ApparentPowerUnit - unitConverter.SetConversionFunction(ApparentPowerUnit.Voltampere, ApparentPowerUnit.Gigavoltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Gigavoltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Voltampere, ApparentPowerUnit.Kilovoltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Kilovoltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Voltampere, ApparentPowerUnit.Megavoltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Megavoltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Voltampere, ApparentPowerUnit.Microvoltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Microvoltampere)); - unitConverter.SetConversionFunction(ApparentPowerUnit.Voltampere, ApparentPowerUnit.Millivoltampere, quantity => quantity.ToUnit(ApparentPowerUnit.Millivoltampere)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(ApparentPowerUnit 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(ApparentPowerUnit unit, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ApparentPower FromGigavoltamperes(double value) - { - return new ApparentPower(value, ApparentPowerUnit.Gigavoltampere); - } - - /// - /// Creates a from . - /// - public static ApparentPower FromKilovoltamperes(double value) - { - return new ApparentPower(value, ApparentPowerUnit.Kilovoltampere); - } - - /// - /// Creates a from . - /// - public static ApparentPower FromMegavoltamperes(double value) - { - return new ApparentPower(value, ApparentPowerUnit.Megavoltampere); - } - - /// - /// Creates a from . - /// - public static ApparentPower FromMicrovoltamperes(double value) - { - return new ApparentPower(value, ApparentPowerUnit.Microvoltampere); - } - - /// - /// Creates a from . - /// - public static ApparentPower FromMillivoltamperes(double value) - { - return new ApparentPower(value, ApparentPowerUnit.Millivoltampere); - } - - /// - /// Creates a from . - /// - public static ApparentPower FromVoltamperes(double value) - { - return new ApparentPower(value, ApparentPowerUnit.Voltampere); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ApparentPower unit value. - public static ApparentPower From(double value, ApparentPowerUnit fromUnit) - { - return new ApparentPower(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 ApparentPower 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 ApparentPower Parse(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]string? str, out ApparentPower 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ApparentPower result) - { - return UnitsNetSetup.Default.QuantityParser.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 ApparentPowerUnit 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 ApparentPowerUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]string? str, out ApparentPowerUnit 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ApparentPowerUnit unit) - { - return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static ApparentPower operator -(ApparentPower right) - { - return new ApparentPower(-right.Value, right.Unit); - } - - /// Get from adding two . - public static ApparentPower operator +(ApparentPower left, ApparentPower right) - { - return new ApparentPower(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static ApparentPower operator -(ApparentPower left, ApparentPower right) - { - return new ApparentPower(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static ApparentPower operator *(double left, ApparentPower right) - { - return new ApparentPower(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static ApparentPower operator *(ApparentPower left, double right) - { - return new ApparentPower(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static ApparentPower operator /(ApparentPower left, double right) - { - return new ApparentPower(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(ApparentPower left, ApparentPower right) - { - return left.Voltamperes / right.Voltamperes; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(ApparentPower left, ApparentPower right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(ApparentPower left, ApparentPower right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(ApparentPower left, ApparentPower right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(ApparentPower left, ApparentPower 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(ApparentPower other, ApparentPower 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 ==(ApparentPower left, ApparentPower 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(ApparentPower other, ApparentPower 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 !=(ApparentPower left, ApparentPower right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ApparentPower other, ApparentPower 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 ApparentPower otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ApparentPower other, ApparentPower 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(ApparentPower 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 ApparentPower otherQuantity)) throw new ArgumentException("Expected type ApparentPower.", 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(ApparentPower other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another ApparentPower 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(ApparentPower other, ApparentPower 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(ApparentPower 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); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is ApparentPower otherTyped - && (tolerance is ApparentPower toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ApparentPower'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(ApparentPower other, ApparentPower 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 ApparentPower. - 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(ApparentPowerUnit 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 ApparentPowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentPowerUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this ApparentPower to another ApparentPower with the unit representation . - /// - /// The unit to convert to. - /// A ApparentPower with the specified unit. - public ApparentPower ToUnit(ApparentPowerUnit 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 ApparentPower with the specified unit. - public ApparentPower ToUnit(ApparentPowerUnit 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(ApparentPower), Unit, typeof(ApparentPower), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (ApparentPower)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(ApparentPowerUnit unit, [NotNullWhen(true)] out ApparentPower? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - ApparentPower? convertedOrNull = (Unit, unit) switch - { - // ApparentPowerUnit -> BaseUnit - (ApparentPowerUnit.Gigavoltampere, ApparentPowerUnit.Voltampere) => new ApparentPower((_value) * 1e9d, ApparentPowerUnit.Voltampere), - (ApparentPowerUnit.Kilovoltampere, ApparentPowerUnit.Voltampere) => new ApparentPower((_value) * 1e3d, ApparentPowerUnit.Voltampere), - (ApparentPowerUnit.Megavoltampere, ApparentPowerUnit.Voltampere) => new ApparentPower((_value) * 1e6d, ApparentPowerUnit.Voltampere), - (ApparentPowerUnit.Microvoltampere, ApparentPowerUnit.Voltampere) => new ApparentPower((_value) * 1e-6d, ApparentPowerUnit.Voltampere), - (ApparentPowerUnit.Millivoltampere, ApparentPowerUnit.Voltampere) => new ApparentPower((_value) * 1e-3d, ApparentPowerUnit.Voltampere), - - // BaseUnit -> ApparentPowerUnit - (ApparentPowerUnit.Voltampere, ApparentPowerUnit.Gigavoltampere) => new ApparentPower((_value) / 1e9d, ApparentPowerUnit.Gigavoltampere), - (ApparentPowerUnit.Voltampere, ApparentPowerUnit.Kilovoltampere) => new ApparentPower((_value) / 1e3d, ApparentPowerUnit.Kilovoltampere), - (ApparentPowerUnit.Voltampere, ApparentPowerUnit.Megavoltampere) => new ApparentPower((_value) / 1e6d, ApparentPowerUnit.Megavoltampere), - (ApparentPowerUnit.Voltampere, ApparentPowerUnit.Microvoltampere) => new ApparentPower((_value) / 1e-6d, ApparentPowerUnit.Microvoltampere), - (ApparentPowerUnit.Voltampere, ApparentPowerUnit.Millivoltampere) => new ApparentPower((_value) / 1e-3d, ApparentPowerUnit.Millivoltampere), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is ApparentPowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentPowerUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public ApparentPower 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(ApparentPowerUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.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(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(ApparentPower)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ApparentPower)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ApparentPower)} 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(null, provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(ApparentPower)) - return this; - else if (conversionType == typeof(ApparentPowerUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return ApparentPower.Info; - else if (conversionType == typeof(BaseDimensions)) - return ApparentPower.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(ApparentPower)} 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/Capacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs deleted file mode 100644 index a480f399b5..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs +++ /dev/null @@ -1,1026 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// Capacitance is the ability of a body to store an electric charge. - /// - /// - /// Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version. - /// - [Obsolete("Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct Capacitance : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - private readonly CapacitanceUnit? _unit; - - static Capacitance() - { - BaseDimensions = new BaseDimensions(-2, -1, 4, 2, 0, 0, 0); - BaseUnit = CapacitanceUnit.Farad; - Units = Enum.GetValues(typeof(CapacitanceUnit)).Cast().ToArray(); - Zero = new Capacitance(0, BaseUnit); - Info = new QuantityInfo("Capacitance", - new UnitInfo[] - { - new UnitInfo(CapacitanceUnit.Farad, "Farads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "Capacitance"), - new UnitInfo(CapacitanceUnit.Kilofarad, "Kilofarads", BaseUnits.Undefined, "Capacitance"), - new UnitInfo(CapacitanceUnit.Megafarad, "Megafarads", BaseUnits.Undefined, "Capacitance"), - new UnitInfo(CapacitanceUnit.Microfarad, "Microfarads", BaseUnits.Undefined, "Capacitance"), - new UnitInfo(CapacitanceUnit.Millifarad, "Millifarads", BaseUnits.Undefined, "Capacitance"), - new UnitInfo(CapacitanceUnit.Nanofarad, "Nanofarads", BaseUnits.Undefined, "Capacitance"), - new UnitInfo(CapacitanceUnit.Picofarad, "Picofarads", BaseUnits.Undefined, "Capacitance"), - }, - 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. - public Capacitance(double value, CapacitanceUnit unit) - { - _value = 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 Capacitance(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = 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 Capacitance, which is Farad. All conversions go via this value. - /// - public static CapacitanceUnit BaseUnit { get; } - - /// - /// All units of measurement for the Capacitance quantity. - /// - public static CapacitanceUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit Farad. - /// - public static Capacitance Zero { get; } - - /// - public static Capacitance AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - double IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public CapacitanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => Capacitance.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double Farads => As(CapacitanceUnit.Farad); - - /// - /// Gets a value of this quantity converted into - /// - public double Kilofarads => As(CapacitanceUnit.Kilofarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Megafarads => As(CapacitanceUnit.Megafarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Microfarads => As(CapacitanceUnit.Microfarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Millifarads => As(CapacitanceUnit.Millifarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Nanofarads => As(CapacitanceUnit.Nanofarad); - - /// - /// Gets a value of this quantity converted into - /// - public double Picofarads => As(CapacitanceUnit.Picofarad); - - #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: CapacitanceUnit -> BaseUnit - unitConverter.SetConversionFunction(CapacitanceUnit.Kilofarad, CapacitanceUnit.Farad, quantity => quantity.ToUnit(CapacitanceUnit.Farad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Megafarad, CapacitanceUnit.Farad, quantity => quantity.ToUnit(CapacitanceUnit.Farad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Microfarad, CapacitanceUnit.Farad, quantity => quantity.ToUnit(CapacitanceUnit.Farad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Millifarad, CapacitanceUnit.Farad, quantity => quantity.ToUnit(CapacitanceUnit.Farad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Nanofarad, CapacitanceUnit.Farad, quantity => quantity.ToUnit(CapacitanceUnit.Farad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Picofarad, CapacitanceUnit.Farad, quantity => quantity.ToUnit(CapacitanceUnit.Farad)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Farad, quantity => quantity); - - // Register in unit converter: BaseUnit -> CapacitanceUnit - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Kilofarad, quantity => quantity.ToUnit(CapacitanceUnit.Kilofarad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Megafarad, quantity => quantity.ToUnit(CapacitanceUnit.Megafarad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Microfarad, quantity => quantity.ToUnit(CapacitanceUnit.Microfarad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Millifarad, quantity => quantity.ToUnit(CapacitanceUnit.Millifarad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Nanofarad, quantity => quantity.ToUnit(CapacitanceUnit.Nanofarad)); - unitConverter.SetConversionFunction(CapacitanceUnit.Farad, CapacitanceUnit.Picofarad, quantity => quantity.ToUnit(CapacitanceUnit.Picofarad)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(CapacitanceUnit 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(CapacitanceUnit unit, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static Capacitance FromFarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Farad); - } - - /// - /// Creates a from . - /// - public static Capacitance FromKilofarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Kilofarad); - } - - /// - /// Creates a from . - /// - public static Capacitance FromMegafarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Megafarad); - } - - /// - /// Creates a from . - /// - public static Capacitance FromMicrofarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Microfarad); - } - - /// - /// Creates a from . - /// - public static Capacitance FromMillifarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Millifarad); - } - - /// - /// Creates a from . - /// - public static Capacitance FromNanofarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Nanofarad); - } - - /// - /// Creates a from . - /// - public static Capacitance FromPicofarads(double value) - { - return new Capacitance(value, CapacitanceUnit.Picofarad); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// Capacitance unit value. - public static Capacitance From(double value, CapacitanceUnit fromUnit) - { - return new Capacitance(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 Capacitance 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 Capacitance Parse(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]string? str, out Capacitance 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out Capacitance result) - { - return UnitsNetSetup.Default.QuantityParser.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 CapacitanceUnit 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 CapacitanceUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]string? str, out CapacitanceUnit 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out CapacitanceUnit unit) - { - return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static Capacitance operator -(Capacitance right) - { - return new Capacitance(-right.Value, right.Unit); - } - - /// Get from adding two . - public static Capacitance operator +(Capacitance left, Capacitance right) - { - return new Capacitance(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static Capacitance operator -(Capacitance left, Capacitance right) - { - return new Capacitance(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static Capacitance operator *(double left, Capacitance right) - { - return new Capacitance(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static Capacitance operator *(Capacitance left, double right) - { - return new Capacitance(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static Capacitance operator /(Capacitance left, double right) - { - return new Capacitance(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(Capacitance left, Capacitance right) - { - return left.Farads / right.Farads; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(Capacitance left, Capacitance right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(Capacitance left, Capacitance right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(Capacitance left, Capacitance right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(Capacitance left, Capacitance 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(Capacitance other, Capacitance 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 ==(Capacitance left, Capacitance 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(Capacitance other, Capacitance 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 !=(Capacitance left, Capacitance right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(Capacitance other, Capacitance 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 Capacitance otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(Capacitance other, Capacitance 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(Capacitance 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 Capacitance otherQuantity)) throw new ArgumentException("Expected type Capacitance.", 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(Capacitance other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another Capacitance 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(Capacitance other, Capacitance 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(Capacitance 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); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is Capacitance otherTyped - && (tolerance is Capacitance toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'Capacitance'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(Capacitance other, Capacitance 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 Capacitance. - 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(CapacitanceUnit 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 CapacitanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CapacitanceUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this Capacitance to another Capacitance with the unit representation . - /// - /// The unit to convert to. - /// A Capacitance with the specified unit. - public Capacitance ToUnit(CapacitanceUnit 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 Capacitance with the specified unit. - public Capacitance ToUnit(CapacitanceUnit 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(Capacitance), Unit, typeof(Capacitance), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (Capacitance)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(CapacitanceUnit unit, [NotNullWhen(true)] out Capacitance? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - Capacitance? convertedOrNull = (Unit, unit) switch - { - // CapacitanceUnit -> BaseUnit - (CapacitanceUnit.Kilofarad, CapacitanceUnit.Farad) => new Capacitance((_value) * 1e3d, CapacitanceUnit.Farad), - (CapacitanceUnit.Megafarad, CapacitanceUnit.Farad) => new Capacitance((_value) * 1e6d, CapacitanceUnit.Farad), - (CapacitanceUnit.Microfarad, CapacitanceUnit.Farad) => new Capacitance((_value) * 1e-6d, CapacitanceUnit.Farad), - (CapacitanceUnit.Millifarad, CapacitanceUnit.Farad) => new Capacitance((_value) * 1e-3d, CapacitanceUnit.Farad), - (CapacitanceUnit.Nanofarad, CapacitanceUnit.Farad) => new Capacitance((_value) * 1e-9d, CapacitanceUnit.Farad), - (CapacitanceUnit.Picofarad, CapacitanceUnit.Farad) => new Capacitance((_value) * 1e-12d, CapacitanceUnit.Farad), - - // BaseUnit -> CapacitanceUnit - (CapacitanceUnit.Farad, CapacitanceUnit.Kilofarad) => new Capacitance((_value) / 1e3d, CapacitanceUnit.Kilofarad), - (CapacitanceUnit.Farad, CapacitanceUnit.Megafarad) => new Capacitance((_value) / 1e6d, CapacitanceUnit.Megafarad), - (CapacitanceUnit.Farad, CapacitanceUnit.Microfarad) => new Capacitance((_value) / 1e-6d, CapacitanceUnit.Microfarad), - (CapacitanceUnit.Farad, CapacitanceUnit.Millifarad) => new Capacitance((_value) / 1e-3d, CapacitanceUnit.Millifarad), - (CapacitanceUnit.Farad, CapacitanceUnit.Nanofarad) => new Capacitance((_value) / 1e-9d, CapacitanceUnit.Nanofarad), - (CapacitanceUnit.Farad, CapacitanceUnit.Picofarad) => new Capacitance((_value) / 1e-12d, CapacitanceUnit.Picofarad), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is CapacitanceUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CapacitanceUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public Capacitance 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(CapacitanceUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.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(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(Capacitance)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(Capacitance)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(Capacitance)} 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(null, provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(Capacitance)) - return this; - else if (conversionType == typeof(CapacitanceUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return Capacitance.Info; - else if (conversionType == typeof(BaseDimensions)) - return Capacitance.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(Capacitance)} 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/ElectricPotentialAc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs deleted file mode 100644 index 7c3384c5c8..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ /dev/null @@ -1,990 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// The Electric Potential of a system known to use Alternating Current. - /// - /// - /// ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. - /// - [Obsolete("ElectricPotentialAc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct ElectricPotentialAc : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - 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. - public ElectricPotentialAc(double value, ElectricPotentialAcUnit unit) - { - _value = 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 = 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; - - /// - double 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 UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromKilovoltsAc(double value) - { - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.KilovoltAc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromMegavoltsAc(double value) - { - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MegavoltAc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromMicrovoltsAc(double value) - { - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MicrovoltAc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromMillivoltsAc(double value) - { - return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MillivoltAc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialAc FromVoltsAc(double value) - { - 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(double value, ElectricPotentialAcUnit fromUnit) - { - return new ElectricPotentialAc(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 UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricPotentialAc result) - { - return UnitsNetSetup.Default.QuantityParser.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 UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricPotentialAcUnit unit) - { - return UnitsNetSetup.Default.UnitParser.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); - } - - /// - 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 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); - - #endregion - - #region ToString Methods - - /// - /// Gets the default string representation of value and unit. - /// - /// String representation. - public override string ToString() - { - return ToString(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(null, 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 981a1bee71..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ /dev/null @@ -1,990 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// The Electric Potential of a system known to use Direct Current. - /// - /// - /// ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. - /// - [Obsolete("ElectricPotentialDc has been merged into ElectricPotential, and will be removed in a later major version. If you want to map more parameters into the ElectricPotential class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct ElectricPotentialDc : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - 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. - public ElectricPotentialDc(double value, ElectricPotentialDcUnit unit) - { - _value = 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 = 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; - - /// - double 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 UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromKilovoltsDc(double value) - { - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.KilovoltDc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromMegavoltsDc(double value) - { - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MegavoltDc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromMicrovoltsDc(double value) - { - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MicrovoltDc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromMillivoltsDc(double value) - { - return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MillivoltDc); - } - - /// - /// Creates a from . - /// - public static ElectricPotentialDc FromVoltsDc(double value) - { - 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(double value, ElectricPotentialDcUnit fromUnit) - { - return new ElectricPotentialDc(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 UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricPotentialDc result) - { - return UnitsNetSetup.Default.QuantityParser.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 UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ElectricPotentialDcUnit unit) - { - return UnitsNetSetup.Default.UnitParser.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); - } - - /// - 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 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); - - #endregion - - #region ToString Methods - - /// - /// Gets the default string representation of value and unit. - /// - /// String representation. - public override string ToString() - { - return ToString(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(null, 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/Quantities/ReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs deleted file mode 100644 index 3891933b66..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ /dev/null @@ -1,954 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// The Volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour. - /// - /// - /// ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version. - /// - [Obsolete("ReactiveEnergy has been renamed to ElectricReactiveEnergy, and will be removed in a later major version.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct ReactiveEnergy : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - private readonly ReactiveEnergyUnit? _unit; - - static ReactiveEnergy() - { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = ReactiveEnergyUnit.VoltampereReactiveHour; - Units = Enum.GetValues(typeof(ReactiveEnergyUnit)).Cast().ToArray(); - Zero = new ReactiveEnergy(0, BaseUnit); - Info = new QuantityInfo("ReactiveEnergy", - new UnitInfo[] - { - new UnitInfo(ReactiveEnergyUnit.KilovoltampereReactiveHour, "KilovoltampereReactiveHours", BaseUnits.Undefined, "ReactiveEnergy"), - new UnitInfo(ReactiveEnergyUnit.MegavoltampereReactiveHour, "MegavoltampereReactiveHours", BaseUnits.Undefined, "ReactiveEnergy"), - new UnitInfo(ReactiveEnergyUnit.VoltampereReactiveHour, "VoltampereReactiveHours", BaseUnits.Undefined, "ReactiveEnergy"), - }, - 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. - public ReactiveEnergy(double value, ReactiveEnergyUnit unit) - { - _value = 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 ReactiveEnergy(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = 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 ReactiveEnergy, which is VoltampereReactiveHour. All conversions go via this value. - /// - public static ReactiveEnergyUnit BaseUnit { get; } - - /// - /// All units of measurement for the ReactiveEnergy quantity. - /// - public static ReactiveEnergyUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereReactiveHour. - /// - public static ReactiveEnergy Zero { get; } - - /// - public static ReactiveEnergy AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - double IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public ReactiveEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => ReactiveEnergy.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltampereReactiveHours => As(ReactiveEnergyUnit.KilovoltampereReactiveHour); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltampereReactiveHours => As(ReactiveEnergyUnit.MegavoltampereReactiveHour); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltampereReactiveHours => As(ReactiveEnergyUnit.VoltampereReactiveHour); - - #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: ReactiveEnergyUnit -> BaseUnit - unitConverter.SetConversionFunction(ReactiveEnergyUnit.KilovoltampereReactiveHour, ReactiveEnergyUnit.VoltampereReactiveHour, quantity => quantity.ToUnit(ReactiveEnergyUnit.VoltampereReactiveHour)); - unitConverter.SetConversionFunction(ReactiveEnergyUnit.MegavoltampereReactiveHour, ReactiveEnergyUnit.VoltampereReactiveHour, quantity => quantity.ToUnit(ReactiveEnergyUnit.VoltampereReactiveHour)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(ReactiveEnergyUnit.VoltampereReactiveHour, ReactiveEnergyUnit.VoltampereReactiveHour, quantity => quantity); - - // Register in unit converter: BaseUnit -> ReactiveEnergyUnit - unitConverter.SetConversionFunction(ReactiveEnergyUnit.VoltampereReactiveHour, ReactiveEnergyUnit.KilovoltampereReactiveHour, quantity => quantity.ToUnit(ReactiveEnergyUnit.KilovoltampereReactiveHour)); - unitConverter.SetConversionFunction(ReactiveEnergyUnit.VoltampereReactiveHour, ReactiveEnergyUnit.MegavoltampereReactiveHour, quantity => quantity.ToUnit(ReactiveEnergyUnit.MegavoltampereReactiveHour)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(ReactiveEnergyUnit 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(ReactiveEnergyUnit unit, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ReactiveEnergy FromKilovoltampereReactiveHours(double value) - { - return new ReactiveEnergy(value, ReactiveEnergyUnit.KilovoltampereReactiveHour); - } - - /// - /// Creates a from . - /// - public static ReactiveEnergy FromMegavoltampereReactiveHours(double value) - { - return new ReactiveEnergy(value, ReactiveEnergyUnit.MegavoltampereReactiveHour); - } - - /// - /// Creates a from . - /// - public static ReactiveEnergy FromVoltampereReactiveHours(double value) - { - return new ReactiveEnergy(value, ReactiveEnergyUnit.VoltampereReactiveHour); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ReactiveEnergy unit value. - public static ReactiveEnergy From(double value, ReactiveEnergyUnit fromUnit) - { - return new ReactiveEnergy(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 ReactiveEnergy 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 ReactiveEnergy Parse(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]string? str, out ReactiveEnergy 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ReactiveEnergy result) - { - return UnitsNetSetup.Default.QuantityParser.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 ReactiveEnergyUnit 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 ReactiveEnergyUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]string? str, out ReactiveEnergyUnit 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ReactiveEnergyUnit unit) - { - return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static ReactiveEnergy operator -(ReactiveEnergy right) - { - return new ReactiveEnergy(-right.Value, right.Unit); - } - - /// Get from adding two . - public static ReactiveEnergy operator +(ReactiveEnergy left, ReactiveEnergy right) - { - return new ReactiveEnergy(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static ReactiveEnergy operator -(ReactiveEnergy left, ReactiveEnergy right) - { - return new ReactiveEnergy(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static ReactiveEnergy operator *(double left, ReactiveEnergy right) - { - return new ReactiveEnergy(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static ReactiveEnergy operator *(ReactiveEnergy left, double right) - { - return new ReactiveEnergy(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static ReactiveEnergy operator /(ReactiveEnergy left, double right) - { - return new ReactiveEnergy(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(ReactiveEnergy left, ReactiveEnergy right) - { - return left.VoltampereReactiveHours / right.VoltampereReactiveHours; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(ReactiveEnergy left, ReactiveEnergy right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(ReactiveEnergy left, ReactiveEnergy right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(ReactiveEnergy left, ReactiveEnergy right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(ReactiveEnergy left, ReactiveEnergy 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(ReactiveEnergy other, ReactiveEnergy 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 ==(ReactiveEnergy left, ReactiveEnergy 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(ReactiveEnergy other, ReactiveEnergy 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 !=(ReactiveEnergy left, ReactiveEnergy right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ReactiveEnergy other, ReactiveEnergy 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 ReactiveEnergy otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ReactiveEnergy other, ReactiveEnergy 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(ReactiveEnergy 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 ReactiveEnergy otherQuantity)) throw new ArgumentException("Expected type ReactiveEnergy.", 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(ReactiveEnergy other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another ReactiveEnergy 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(ReactiveEnergy other, ReactiveEnergy 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(ReactiveEnergy 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); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is ReactiveEnergy otherTyped - && (tolerance is ReactiveEnergy toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ReactiveEnergy'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(ReactiveEnergy other, ReactiveEnergy 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 ReactiveEnergy. - 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(ReactiveEnergyUnit 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 ReactiveEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactiveEnergyUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this ReactiveEnergy to another ReactiveEnergy with the unit representation . - /// - /// The unit to convert to. - /// A ReactiveEnergy with the specified unit. - public ReactiveEnergy ToUnit(ReactiveEnergyUnit 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 ReactiveEnergy with the specified unit. - public ReactiveEnergy ToUnit(ReactiveEnergyUnit 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(ReactiveEnergy), Unit, typeof(ReactiveEnergy), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (ReactiveEnergy)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(ReactiveEnergyUnit unit, [NotNullWhen(true)] out ReactiveEnergy? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - ReactiveEnergy? convertedOrNull = (Unit, unit) switch - { - // ReactiveEnergyUnit -> BaseUnit - (ReactiveEnergyUnit.KilovoltampereReactiveHour, ReactiveEnergyUnit.VoltampereReactiveHour) => new ReactiveEnergy((_value) * 1e3d, ReactiveEnergyUnit.VoltampereReactiveHour), - (ReactiveEnergyUnit.MegavoltampereReactiveHour, ReactiveEnergyUnit.VoltampereReactiveHour) => new ReactiveEnergy((_value) * 1e6d, ReactiveEnergyUnit.VoltampereReactiveHour), - - // BaseUnit -> ReactiveEnergyUnit - (ReactiveEnergyUnit.VoltampereReactiveHour, ReactiveEnergyUnit.KilovoltampereReactiveHour) => new ReactiveEnergy((_value) / 1e3d, ReactiveEnergyUnit.KilovoltampereReactiveHour), - (ReactiveEnergyUnit.VoltampereReactiveHour, ReactiveEnergyUnit.MegavoltampereReactiveHour) => new ReactiveEnergy((_value) / 1e6d, ReactiveEnergyUnit.MegavoltampereReactiveHour), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is ReactiveEnergyUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactiveEnergyUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public ReactiveEnergy 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(ReactiveEnergyUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.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(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(ReactiveEnergy)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ReactiveEnergy)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ReactiveEnergy)} 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(null, provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(ReactiveEnergy)) - return this; - else if (conversionType == typeof(ReactiveEnergyUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return ReactiveEnergy.Info; - else if (conversionType == typeof(BaseDimensions)) - return ReactiveEnergy.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(ReactiveEnergy)} 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/ReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs deleted file mode 100644 index 9e00bca9da..0000000000 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs +++ /dev/null @@ -1,972 +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; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using UnitsNet.Units; -#if NET -using System.Numerics; -#endif - -#nullable enable - -// ReSharper disable once CheckNamespace - -namespace UnitsNet -{ - /// - /// - /// Volt-ampere reactive (var) is a unit by which reactive power is expressed in an AC electric power system. Reactive power exists in an AC circuit when the current and voltage are not in phase. - /// - /// - /// ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version. - /// - [Obsolete("ReactivePower has been renamed to ElectricReactivePower, and will be removed in a later major version.")] - [DataContract] - [DebuggerTypeProxy(typeof(QuantityDisplay))] - public readonly partial struct ReactivePower : - IArithmeticQuantity, -#if NET7_0_OR_GREATER - IComparisonOperators, - IParsable, -#endif - IComparable, - IComparable, - IConvertible, - IEquatable, - IFormattable - { - /// - /// The numeric value this quantity was constructed with. - /// - [DataMember(Name = "Value", Order = 1)] - private readonly double _value; - - /// - /// The unit this quantity was constructed with. - /// - [DataMember(Name = "Unit", Order = 2)] - private readonly ReactivePowerUnit? _unit; - - static ReactivePower() - { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = ReactivePowerUnit.VoltampereReactive; - Units = Enum.GetValues(typeof(ReactivePowerUnit)).Cast().ToArray(); - Zero = new ReactivePower(0, BaseUnit); - Info = new QuantityInfo("ReactivePower", - new UnitInfo[] - { - new UnitInfo(ReactivePowerUnit.GigavoltampereReactive, "GigavoltamperesReactive", BaseUnits.Undefined, "ReactivePower"), - new UnitInfo(ReactivePowerUnit.KilovoltampereReactive, "KilovoltamperesReactive", BaseUnits.Undefined, "ReactivePower"), - new UnitInfo(ReactivePowerUnit.MegavoltampereReactive, "MegavoltamperesReactive", BaseUnits.Undefined, "ReactivePower"), - new UnitInfo(ReactivePowerUnit.VoltampereReactive, "VoltamperesReactive", BaseUnits.Undefined, "ReactivePower"), - }, - 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. - public ReactivePower(double value, ReactivePowerUnit unit) - { - _value = 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 ReactivePower(double value, UnitSystem unitSystem) - { - if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); - - var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); - var firstUnitInfo = unitInfos.FirstOrDefault(); - - _value = 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 ReactivePower, which is VoltampereReactive. All conversions go via this value. - /// - public static ReactivePowerUnit BaseUnit { get; } - - /// - /// All units of measurement for the ReactivePower quantity. - /// - public static ReactivePowerUnit[] Units { get; } - - /// - /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereReactive. - /// - public static ReactivePower Zero { get; } - - /// - public static ReactivePower AdditiveIdentity => Zero; - - #endregion - - #region Properties - - /// - /// The numeric value this quantity was constructed with. - /// - public double Value => _value; - - /// - double IQuantity.Value => _value; - - Enum IQuantity.Unit => Unit; - - /// - public ReactivePowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); - - /// - public QuantityInfo QuantityInfo => Info; - - /// - QuantityInfo IQuantity.QuantityInfo => Info; - - /// - /// The of this quantity. - /// - public BaseDimensions Dimensions => ReactivePower.BaseDimensions; - - #endregion - - #region Conversion Properties - - /// - /// Gets a value of this quantity converted into - /// - public double GigavoltamperesReactive => As(ReactivePowerUnit.GigavoltampereReactive); - - /// - /// Gets a value of this quantity converted into - /// - public double KilovoltamperesReactive => As(ReactivePowerUnit.KilovoltampereReactive); - - /// - /// Gets a value of this quantity converted into - /// - public double MegavoltamperesReactive => As(ReactivePowerUnit.MegavoltampereReactive); - - /// - /// Gets a value of this quantity converted into - /// - public double VoltamperesReactive => As(ReactivePowerUnit.VoltampereReactive); - - #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: ReactivePowerUnit -> BaseUnit - unitConverter.SetConversionFunction(ReactivePowerUnit.GigavoltampereReactive, ReactivePowerUnit.VoltampereReactive, quantity => quantity.ToUnit(ReactivePowerUnit.VoltampereReactive)); - unitConverter.SetConversionFunction(ReactivePowerUnit.KilovoltampereReactive, ReactivePowerUnit.VoltampereReactive, quantity => quantity.ToUnit(ReactivePowerUnit.VoltampereReactive)); - unitConverter.SetConversionFunction(ReactivePowerUnit.MegavoltampereReactive, ReactivePowerUnit.VoltampereReactive, quantity => quantity.ToUnit(ReactivePowerUnit.VoltampereReactive)); - - // Register in unit converter: BaseUnit <-> BaseUnit - unitConverter.SetConversionFunction(ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.VoltampereReactive, quantity => quantity); - - // Register in unit converter: BaseUnit -> ReactivePowerUnit - unitConverter.SetConversionFunction(ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.GigavoltampereReactive, quantity => quantity.ToUnit(ReactivePowerUnit.GigavoltampereReactive)); - unitConverter.SetConversionFunction(ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.KilovoltampereReactive, quantity => quantity.ToUnit(ReactivePowerUnit.KilovoltampereReactive)); - unitConverter.SetConversionFunction(ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.MegavoltampereReactive, quantity => quantity.ToUnit(ReactivePowerUnit.MegavoltampereReactive)); - } - - /// - /// Get unit abbreviation string. - /// - /// Unit to get abbreviation for. - /// Unit abbreviation string. - public static string GetAbbreviation(ReactivePowerUnit 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(ReactivePowerUnit unit, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitAbbreviations.GetDefaultAbbreviation(unit, provider); - } - - #endregion - - #region Static Factory Methods - - /// - /// Creates a from . - /// - public static ReactivePower FromGigavoltamperesReactive(double value) - { - return new ReactivePower(value, ReactivePowerUnit.GigavoltampereReactive); - } - - /// - /// Creates a from . - /// - public static ReactivePower FromKilovoltamperesReactive(double value) - { - return new ReactivePower(value, ReactivePowerUnit.KilovoltampereReactive); - } - - /// - /// Creates a from . - /// - public static ReactivePower FromMegavoltamperesReactive(double value) - { - return new ReactivePower(value, ReactivePowerUnit.MegavoltampereReactive); - } - - /// - /// Creates a from . - /// - public static ReactivePower FromVoltamperesReactive(double value) - { - return new ReactivePower(value, ReactivePowerUnit.VoltampereReactive); - } - - /// - /// Dynamically convert from value and unit enum to . - /// - /// Value to convert from. - /// Unit to convert from. - /// ReactivePower unit value. - public static ReactivePower From(double value, ReactivePowerUnit fromUnit) - { - return new ReactivePower(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 ReactivePower 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 ReactivePower Parse(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.QuantityParser.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([NotNullWhen(true)]string? str, out ReactivePower 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ReactivePower result) - { - return UnitsNetSetup.Default.QuantityParser.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 ReactivePowerUnit 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 ReactivePowerUnit ParseUnit(string str, IFormatProvider? provider) - { - return UnitsNetSetup.Default.UnitParser.Parse(str, provider); - } - - /// - public static bool TryParseUnit([NotNullWhen(true)]string? str, out ReactivePowerUnit 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([NotNullWhen(true)]string? str, IFormatProvider? provider, out ReactivePowerUnit unit) - { - return UnitsNetSetup.Default.UnitParser.TryParse(str, provider, out unit); - } - - #endregion - - #region Arithmetic Operators - - /// Negate the value. - public static ReactivePower operator -(ReactivePower right) - { - return new ReactivePower(-right.Value, right.Unit); - } - - /// Get from adding two . - public static ReactivePower operator +(ReactivePower left, ReactivePower right) - { - return new ReactivePower(left.Value + right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from subtracting two . - public static ReactivePower operator -(ReactivePower left, ReactivePower right) - { - return new ReactivePower(left.Value - right.ToUnit(left.Unit).Value, left.Unit); - } - - /// Get from multiplying value and . - public static ReactivePower operator *(double left, ReactivePower right) - { - return new ReactivePower(left * right.Value, right.Unit); - } - - /// Get from multiplying value and . - public static ReactivePower operator *(ReactivePower left, double right) - { - return new ReactivePower(left.Value * right, left.Unit); - } - - /// Get from dividing by value. - public static ReactivePower operator /(ReactivePower left, double right) - { - return new ReactivePower(left.Value / right, left.Unit); - } - - /// Get ratio value from dividing by . - public static double operator /(ReactivePower left, ReactivePower right) - { - return left.VoltamperesReactive / right.VoltamperesReactive; - } - - #endregion - - #region Equality / IComparable - - /// Returns true if less or equal to. - public static bool operator <=(ReactivePower left, ReactivePower right) - { - return left.Value <= right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than or equal to. - public static bool operator >=(ReactivePower left, ReactivePower right) - { - return left.Value >= right.ToUnit(left.Unit).Value; - } - - /// Returns true if less than. - public static bool operator <(ReactivePower left, ReactivePower right) - { - return left.Value < right.ToUnit(left.Unit).Value; - } - - /// Returns true if greater than. - public static bool operator >(ReactivePower left, ReactivePower 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(ReactivePower other, ReactivePower 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 ==(ReactivePower left, ReactivePower 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(ReactivePower other, ReactivePower 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 !=(ReactivePower left, ReactivePower right) - { - return !(left == right); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ReactivePower other, ReactivePower 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 ReactivePower otherQuantity)) - return false; - - return Equals(otherQuantity); - } - - /// - /// Indicates strict equality of two quantities, where both and are exactly equal. - [Obsolete("Use Equals(ReactivePower other, ReactivePower 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(ReactivePower 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 ReactivePower otherQuantity)) throw new ArgumentException("Expected type ReactivePower.", 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(ReactivePower other) - { - return _value.CompareTo(other.ToUnit(this.Unit).Value); - } - - /// - /// - /// Compare equality to another ReactivePower 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(ReactivePower other, ReactivePower 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(ReactivePower 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); - } - - /// - public bool Equals(IQuantity? other, IQuantity tolerance) - { - return other is ReactivePower otherTyped - && (tolerance is ReactivePower toleranceTyped - ? true - : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ReactivePower'.", nameof(tolerance))) - && Equals(otherTyped, toleranceTyped); - } - - /// - public bool Equals(ReactivePower other, ReactivePower 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 ReactivePower. - 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(ReactivePowerUnit 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 ReactivePowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactivePowerUnit)} is supported.", nameof(unit)); - - return As(typedUnit); - } - - /// - /// Converts this ReactivePower to another ReactivePower with the unit representation . - /// - /// The unit to convert to. - /// A ReactivePower with the specified unit. - public ReactivePower ToUnit(ReactivePowerUnit 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 ReactivePower with the specified unit. - public ReactivePower ToUnit(ReactivePowerUnit 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(ReactivePower), Unit, typeof(ReactivePower), unit), out var conversionFunction)) - { - // See if the unit converter has an extensibility conversion registered. - return (ReactivePower)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(ReactivePowerUnit unit, [NotNullWhen(true)] out ReactivePower? converted) - { - if (Unit == unit) - { - converted = this; - return true; - } - - ReactivePower? convertedOrNull = (Unit, unit) switch - { - // ReactivePowerUnit -> BaseUnit - (ReactivePowerUnit.GigavoltampereReactive, ReactivePowerUnit.VoltampereReactive) => new ReactivePower((_value) * 1e9d, ReactivePowerUnit.VoltampereReactive), - (ReactivePowerUnit.KilovoltampereReactive, ReactivePowerUnit.VoltampereReactive) => new ReactivePower((_value) * 1e3d, ReactivePowerUnit.VoltampereReactive), - (ReactivePowerUnit.MegavoltampereReactive, ReactivePowerUnit.VoltampereReactive) => new ReactivePower((_value) * 1e6d, ReactivePowerUnit.VoltampereReactive), - - // BaseUnit -> ReactivePowerUnit - (ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.GigavoltampereReactive) => new ReactivePower((_value) / 1e9d, ReactivePowerUnit.GigavoltampereReactive), - (ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.KilovoltampereReactive) => new ReactivePower((_value) / 1e3d, ReactivePowerUnit.KilovoltampereReactive), - (ReactivePowerUnit.VoltampereReactive, ReactivePowerUnit.MegavoltampereReactive) => new ReactivePower((_value) / 1e6d, ReactivePowerUnit.MegavoltampereReactive), - - _ => null - }; - - if (convertedOrNull is null) - { - converted = default; - return false; - } - - converted = convertedOrNull.Value; - return true; - } - - /// - IQuantity IQuantity.ToUnit(Enum unit) - { - if (!(unit is ReactivePowerUnit typedUnit)) - throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactivePowerUnit)} is supported.", nameof(unit)); - - return ToUnit(typedUnit, DefaultConversionFunctions); - } - - /// - public ReactivePower 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(ReactivePowerUnit unit) => ToUnit(unit); - - /// - IQuantity IQuantity.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(null, null); - } - - /// - /// 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(null, 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, null); - } - - /// - /// - /// 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(ReactivePower)} to bool is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider? provider) - { - return Convert.ToByte(_value); - } - - char IConvertible.ToChar(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ReactivePower)} to char is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider? provider) - { - throw new InvalidCastException($"Converting {typeof(ReactivePower)} 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(null, provider); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider? provider) - { - if (conversionType == typeof(ReactivePower)) - return this; - else if (conversionType == typeof(ReactivePowerUnit)) - return Unit; - else if (conversionType == typeof(QuantityInfo)) - return ReactivePower.Info; - else if (conversionType == typeof(BaseDimensions)) - return ReactivePower.BaseDimensions; - else - throw new InvalidCastException($"Converting {typeof(ReactivePower)} 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 75f9fcdf3e..d5899d11ad 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -43,14 +43,11 @@ public partial class Quantity { "AmountOfSubstance", AmountOfSubstance.Info }, { "AmplitudeRatio", AmplitudeRatio.Info }, { "Angle", Angle.Info }, - { "ApparentEnergy", ApparentEnergy.Info }, - { "ApparentPower", ApparentPower.Info }, { "Area", Area.Info }, { "AreaDensity", AreaDensity.Info }, { "AreaMomentOfInertia", AreaMomentOfInertia.Info }, { "BitRate", BitRate.Info }, { "BrakeSpecificFuelConsumption", BrakeSpecificFuelConsumption.Info }, - { "Capacitance", Capacitance.Info }, { "CoefficientOfThermalExpansion", CoefficientOfThermalExpansion.Info }, { "Compressibility", Compressibility.Info }, { "Density", Density.Info }, @@ -72,9 +69,7 @@ public partial class Quantity { "ElectricImpedance", ElectricImpedance.Info }, { "ElectricInductance", ElectricInductance.Info }, { "ElectricPotential", ElectricPotential.Info }, - { "ElectricPotentialAc", ElectricPotentialAc.Info }, { "ElectricPotentialChangeRate", ElectricPotentialChangeRate.Info }, - { "ElectricPotentialDc", ElectricPotentialDc.Info }, { "ElectricReactance", ElectricReactance.Info }, { "ElectricReactiveEnergy", ElectricReactiveEnergy.Info }, { "ElectricReactivePower", ElectricReactivePower.Info }, @@ -137,8 +132,6 @@ public partial class Quantity { "Radioactivity", Radioactivity.Info }, { "Ratio", Ratio.Info }, { "RatioChangeRate", RatioChangeRate.Info }, - { "ReactiveEnergy", ReactiveEnergy.Info }, - { "ReactivePower", ReactivePower.Info }, { "ReciprocalArea", ReciprocalArea.Info }, { "ReciprocalLength", ReciprocalLength.Info }, { "RelativeHumidity", RelativeHumidity.Info }, @@ -188,14 +181,11 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value "AmountOfSubstance" => AmountOfSubstance.From(value, AmountOfSubstance.BaseUnit), "AmplitudeRatio" => AmplitudeRatio.From(value, AmplitudeRatio.BaseUnit), "Angle" => Angle.From(value, Angle.BaseUnit), - "ApparentEnergy" => ApparentEnergy.From(value, ApparentEnergy.BaseUnit), - "ApparentPower" => ApparentPower.From(value, ApparentPower.BaseUnit), "Area" => Area.From(value, Area.BaseUnit), "AreaDensity" => AreaDensity.From(value, AreaDensity.BaseUnit), "AreaMomentOfInertia" => AreaMomentOfInertia.From(value, AreaMomentOfInertia.BaseUnit), "BitRate" => BitRate.From(value, BitRate.BaseUnit), "BrakeSpecificFuelConsumption" => BrakeSpecificFuelConsumption.From(value, BrakeSpecificFuelConsumption.BaseUnit), - "Capacitance" => Capacitance.From(value, Capacitance.BaseUnit), "CoefficientOfThermalExpansion" => CoefficientOfThermalExpansion.From(value, CoefficientOfThermalExpansion.BaseUnit), "Compressibility" => Compressibility.From(value, Compressibility.BaseUnit), "Density" => Density.From(value, Density.BaseUnit), @@ -217,9 +207,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value "ElectricImpedance" => ElectricImpedance.From(value, ElectricImpedance.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), "ElectricReactance" => ElectricReactance.From(value, ElectricReactance.BaseUnit), "ElectricReactiveEnergy" => ElectricReactiveEnergy.From(value, ElectricReactiveEnergy.BaseUnit), "ElectricReactivePower" => ElectricReactivePower.From(value, ElectricReactivePower.BaseUnit), @@ -282,8 +270,6 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value "Radioactivity" => Radioactivity.From(value, Radioactivity.BaseUnit), "Ratio" => Ratio.From(value, Ratio.BaseUnit), "RatioChangeRate" => RatioChangeRate.From(value, RatioChangeRate.BaseUnit), - "ReactiveEnergy" => ReactiveEnergy.From(value, ReactiveEnergy.BaseUnit), - "ReactivePower" => ReactivePower.From(value, ReactivePower.BaseUnit), "ReciprocalArea" => ReciprocalArea.From(value, ReciprocalArea.BaseUnit), "ReciprocalLength" => ReciprocalLength.From(value, ReciprocalLength.BaseUnit), "RelativeHumidity" => RelativeHumidity.From(value, RelativeHumidity.BaseUnit), @@ -336,14 +322,11 @@ public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQu AmountOfSubstanceUnit amountOfSubstanceUnit => AmountOfSubstance.From(value, amountOfSubstanceUnit), AmplitudeRatioUnit amplitudeRatioUnit => AmplitudeRatio.From(value, amplitudeRatioUnit), AngleUnit angleUnit => Angle.From(value, angleUnit), - ApparentEnergyUnit apparentEnergyUnit => ApparentEnergy.From(value, apparentEnergyUnit), - ApparentPowerUnit apparentPowerUnit => ApparentPower.From(value, apparentPowerUnit), AreaUnit areaUnit => Area.From(value, areaUnit), AreaDensityUnit areaDensityUnit => AreaDensity.From(value, areaDensityUnit), AreaMomentOfInertiaUnit areaMomentOfInertiaUnit => AreaMomentOfInertia.From(value, areaMomentOfInertiaUnit), BitRateUnit bitRateUnit => BitRate.From(value, bitRateUnit), BrakeSpecificFuelConsumptionUnit brakeSpecificFuelConsumptionUnit => BrakeSpecificFuelConsumption.From(value, brakeSpecificFuelConsumptionUnit), - CapacitanceUnit capacitanceUnit => Capacitance.From(value, capacitanceUnit), CoefficientOfThermalExpansionUnit coefficientOfThermalExpansionUnit => CoefficientOfThermalExpansion.From(value, coefficientOfThermalExpansionUnit), CompressibilityUnit compressibilityUnit => Compressibility.From(value, compressibilityUnit), DensityUnit densityUnit => Density.From(value, densityUnit), @@ -365,9 +348,7 @@ public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQu ElectricImpedanceUnit electricImpedanceUnit => ElectricImpedance.From(value, electricImpedanceUnit), 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), ElectricReactanceUnit electricReactanceUnit => ElectricReactance.From(value, electricReactanceUnit), ElectricReactiveEnergyUnit electricReactiveEnergyUnit => ElectricReactiveEnergy.From(value, electricReactiveEnergyUnit), ElectricReactivePowerUnit electricReactivePowerUnit => ElectricReactivePower.From(value, electricReactivePowerUnit), @@ -430,8 +411,6 @@ public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQu RadioactivityUnit radioactivityUnit => Radioactivity.From(value, radioactivityUnit), RatioUnit ratioUnit => Ratio.From(value, ratioUnit), RatioChangeRateUnit ratioChangeRateUnit => RatioChangeRate.From(value, ratioChangeRateUnit), - ReactiveEnergyUnit reactiveEnergyUnit => ReactiveEnergy.From(value, reactiveEnergyUnit), - ReactivePowerUnit reactivePowerUnit => ReactivePower.From(value, reactivePowerUnit), ReciprocalAreaUnit reciprocalAreaUnit => ReciprocalArea.From(value, reciprocalAreaUnit), ReciprocalLengthUnit reciprocalLengthUnit => ReciprocalLength.From(value, reciprocalLengthUnit), RelativeHumidityUnit relativeHumidityUnit => RelativeHumidity.From(value, relativeHumidityUnit), @@ -494,14 +473,11 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(AmountOfSubstance) => parser.TryParse(quantityString, formatProvider, AmountOfSubstance.From, out quantity), Type _ when quantityType == typeof(AmplitudeRatio) => parser.TryParse(quantityString, formatProvider, AmplitudeRatio.From, out quantity), Type _ when quantityType == typeof(Angle) => parser.TryParse(quantityString, formatProvider, Angle.From, out quantity), - Type _ when quantityType == typeof(ApparentEnergy) => parser.TryParse(quantityString, formatProvider, ApparentEnergy.From, out quantity), - Type _ when quantityType == typeof(ApparentPower) => parser.TryParse(quantityString, formatProvider, ApparentPower.From, out quantity), Type _ when quantityType == typeof(Area) => parser.TryParse(quantityString, formatProvider, Area.From, out quantity), Type _ when quantityType == typeof(AreaDensity) => parser.TryParse(quantityString, formatProvider, AreaDensity.From, out quantity), Type _ when quantityType == typeof(AreaMomentOfInertia) => parser.TryParse(quantityString, formatProvider, AreaMomentOfInertia.From, out quantity), Type _ when quantityType == typeof(BitRate) => parser.TryParse(quantityString, formatProvider, BitRate.From, out quantity), Type _ when quantityType == typeof(BrakeSpecificFuelConsumption) => parser.TryParse(quantityString, formatProvider, BrakeSpecificFuelConsumption.From, out quantity), - Type _ when quantityType == typeof(Capacitance) => parser.TryParse(quantityString, formatProvider, Capacitance.From, out quantity), Type _ when quantityType == typeof(CoefficientOfThermalExpansion) => parser.TryParse(quantityString, formatProvider, CoefficientOfThermalExpansion.From, out quantity), Type _ when quantityType == typeof(Compressibility) => parser.TryParse(quantityString, formatProvider, Compressibility.From, out quantity), Type _ when quantityType == typeof(Density) => parser.TryParse(quantityString, formatProvider, Density.From, out quantity), @@ -523,9 +499,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(ElectricImpedance) => parser.TryParse(quantityString, formatProvider, ElectricImpedance.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(ElectricReactance) => parser.TryParse(quantityString, formatProvider, ElectricReactance.From, out quantity), Type _ when quantityType == typeof(ElectricReactiveEnergy) => parser.TryParse(quantityString, formatProvider, ElectricReactiveEnergy.From, out quantity), Type _ when quantityType == typeof(ElectricReactivePower) => parser.TryParse(quantityString, formatProvider, ElectricReactivePower.From, out quantity), @@ -588,8 +562,6 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(Radioactivity) => parser.TryParse(quantityString, formatProvider, Radioactivity.From, out quantity), Type _ when quantityType == typeof(Ratio) => parser.TryParse(quantityString, formatProvider, Ratio.From, out quantity), Type _ when quantityType == typeof(RatioChangeRate) => parser.TryParse(quantityString, formatProvider, RatioChangeRate.From, out quantity), - Type _ when quantityType == typeof(ReactiveEnergy) => parser.TryParse(quantityString, formatProvider, ReactiveEnergy.From, out quantity), - Type _ when quantityType == typeof(ReactivePower) => parser.TryParse(quantityString, formatProvider, ReactivePower.From, out quantity), Type _ when quantityType == typeof(ReciprocalArea) => parser.TryParse(quantityString, formatProvider, ReciprocalArea.From, out quantity), Type _ when quantityType == typeof(ReciprocalLength) => parser.TryParse(quantityString, formatProvider, ReciprocalLength.From, out quantity), Type _ when quantityType == typeof(RelativeHumidity) => parser.TryParse(quantityString, formatProvider, RelativeHumidity.From, out quantity), @@ -633,14 +605,11 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(AmountOfSubstance); yield return typeof(AmplitudeRatio); yield return typeof(Angle); - yield return typeof(ApparentEnergy); - yield return typeof(ApparentPower); yield return typeof(Area); yield return typeof(AreaDensity); yield return typeof(AreaMomentOfInertia); yield return typeof(BitRate); yield return typeof(BrakeSpecificFuelConsumption); - yield return typeof(Capacitance); yield return typeof(CoefficientOfThermalExpansion); yield return typeof(Compressibility); yield return typeof(Density); @@ -662,9 +631,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(ElectricImpedance); yield return typeof(ElectricInductance); yield return typeof(ElectricPotential); - yield return typeof(ElectricPotentialAc); yield return typeof(ElectricPotentialChangeRate); - yield return typeof(ElectricPotentialDc); yield return typeof(ElectricReactance); yield return typeof(ElectricReactiveEnergy); yield return typeof(ElectricReactivePower); @@ -727,8 +694,6 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(Radioactivity); yield return typeof(Ratio); yield return typeof(RatioChangeRate); - yield return typeof(ReactiveEnergy); - yield return typeof(ReactivePower); yield return typeof(ReciprocalArea); yield return typeof(ReciprocalLength); yield return typeof(RelativeHumidity); diff --git a/UnitsNet/GeneratedCode/Resources/ApparentEnergy.restext b/UnitsNet/GeneratedCode/Resources/ApparentEnergy.restext deleted file mode 100644 index 8042321934..0000000000 --- a/UnitsNet/GeneratedCode/Resources/ApparentEnergy.restext +++ /dev/null @@ -1,3 +0,0 @@ -KilovoltampereHours=kVAh -MegavoltampereHours=MVAh -VoltampereHours=VAh diff --git a/UnitsNet/GeneratedCode/Resources/ApparentPower.restext b/UnitsNet/GeneratedCode/Resources/ApparentPower.restext deleted file mode 100644 index fa9f53f44c..0000000000 --- a/UnitsNet/GeneratedCode/Resources/ApparentPower.restext +++ /dev/null @@ -1,6 +0,0 @@ -Gigavoltamperes=GVA -Kilovoltamperes=kVA -Megavoltamperes=MVA -Microvoltamperes=µVA -Millivoltamperes=mVA -Voltamperes=VA diff --git a/UnitsNet/GeneratedCode/Resources/Capacitance.restext b/UnitsNet/GeneratedCode/Resources/Capacitance.restext deleted file mode 100644 index dff2eb0e40..0000000000 --- a/UnitsNet/GeneratedCode/Resources/Capacitance.restext +++ /dev/null @@ -1,7 +0,0 @@ -Farads=F -Kilofarads=kF -Megafarads=MF -Microfarads=µF -Millifarads=mF -Nanofarads=nF -Picofarads=pF 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/ApparentEnergyUnit.g.cs b/UnitsNet/GeneratedCode/Units/ApparentEnergyUnit.g.cs deleted file mode 100644 index 2a8c1aba5b..0000000000 --- a/UnitsNet/GeneratedCode/Units/ApparentEnergyUnit.g.cs +++ /dev/null @@ -1,34 +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 ApparentEnergyUnit - { - KilovoltampereHour = 1, - MegavoltampereHour = 2, - VoltampereHour = 3, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet/GeneratedCode/Units/ApparentPowerUnit.g.cs b/UnitsNet/GeneratedCode/Units/ApparentPowerUnit.g.cs deleted file mode 100644 index 856789bbdd..0000000000 --- a/UnitsNet/GeneratedCode/Units/ApparentPowerUnit.g.cs +++ /dev/null @@ -1,37 +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 ApparentPowerUnit - { - Gigavoltampere = 1, - Kilovoltampere = 2, - Megavoltampere = 3, - Microvoltampere = 6, - Millivoltampere = 7, - Voltampere = 4, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet/GeneratedCode/Units/CapacitanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/CapacitanceUnit.g.cs deleted file mode 100644 index a76cc8f2d8..0000000000 --- a/UnitsNet/GeneratedCode/Units/CapacitanceUnit.g.cs +++ /dev/null @@ -1,38 +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 CapacitanceUnit - { - Farad = 1, - Kilofarad = 2, - Megafarad = 3, - Microfarad = 4, - Millifarad = 5, - Nanofarad = 6, - Picofarad = 7, - } - - #pragma warning restore 1591 -} diff --git a/UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.g.cs deleted file mode 100644 index ada8068172..0000000000 --- a/UnitsNet/GeneratedCode/Units/ElectricPotentialAcUnit.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 ElectricPotentialAcUnit - { - KilovoltAc = 1, - MegavoltAc = 2, - MicrovoltAc = 3, - MillivoltAc = 4, - VoltAc = 5, - } - - #pragma warning restore 1591 -} 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 -}