diff --git a/Common/UnitDefinitions/ApparentEnergy.json b/Common/UnitDefinitions/ApparentEnergy.json index f656a25c02..b9c3c4a874 100644 --- a/Common/UnitDefinitions/ApparentEnergy.json +++ b/Common/UnitDefinitions/ApparentEnergy.json @@ -2,6 +2,8 @@ "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": " has been renamed to , 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, diff --git a/Common/UnitDefinitions/ApparentPower.json b/Common/UnitDefinitions/ApparentPower.json index 5dfbd47b57..631d1285b8 100644 --- a/Common/UnitDefinitions/ApparentPower.json +++ b/Common/UnitDefinitions/ApparentPower.json @@ -2,6 +2,8 @@ "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": " has been renamed to , 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, diff --git a/Common/UnitDefinitions/Capacitance.json b/Common/UnitDefinitions/Capacitance.json index a7e88a5985..edf2c68aa7 100644 --- a/Common/UnitDefinitions/Capacitance.json +++ b/Common/UnitDefinitions/Capacitance.json @@ -2,7 +2,8 @@ "Name": "Capacitance", "BaseUnit": "Farad", "XmlDocSummary": "Capacitance is the ability of a body to store an electric charge.", - "XmlDocRemarks": "https://en.wikipedia.org/wiki/Capacitance", + "XmlDocRemarks": " has been renamed to , 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, diff --git a/Common/UnitDefinitions/ElectricAdmittance.json b/Common/UnitDefinitions/ElectricAdmittance.json index 4c75bbf0f1..dbae9f5322 100644 --- a/Common/UnitDefinitions/ElectricAdmittance.json +++ b/Common/UnitDefinitions/ElectricAdmittance.json @@ -1,7 +1,9 @@ { "Name": "ElectricAdmittance", "BaseUnit": "Siemens", - "XmlDocSummary": "Electric admittance is a measure of how easily a circuit or device will allow a current to flow. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S).", + "XmlDocSummary": "Electric admittance is a measure of how easily a circuit or device will allow a current to flow by the combined effect of conductance and susceptance in a circuit. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S).", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_admittance", + "ObsoleteText": "Admittance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricConductance or ElectricSusceptance instead.", "BaseDimensions": { "L": -2, "M": -1, @@ -14,13 +16,26 @@ "PluralName": "Siemens", "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Nano", "Micro", "Milli" ], + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], "Localization": [ { "Culture": "en-US", "Abbreviations": [ "S" ] } ] + }, + { + "SingularName": "Mho", + "PluralName": "Mhos", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "?" ] + } + ] } ] } diff --git a/Common/UnitDefinitions/ElectricApparentEnergy.json b/Common/UnitDefinitions/ElectricApparentEnergy.json new file mode 100644 index 0000000000..0a04777f90 --- /dev/null +++ b/Common/UnitDefinitions/ElectricApparentEnergy.json @@ -0,0 +1,25 @@ +{ + "Name": "ElectricApparentEnergy", + "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.", + "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/ElectricApparentPower.json b/Common/UnitDefinitions/ElectricApparentPower.json new file mode 100644 index 0000000000..4173ef577b --- /dev/null +++ b/Common/UnitDefinitions/ElectricApparentPower.json @@ -0,0 +1,26 @@ +{ + "Name": "ElectricApparentPower", + "BaseUnit": "Voltampere", + "XmlDocSummary": "Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. It is the product of the root mean square voltage (in volts) and the root mean square current (in amperes).", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state", + "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/ElectricCapacitance.json b/Common/UnitDefinitions/ElectricCapacitance.json new file mode 100644 index 0000000000..d8bfed5bd5 --- /dev/null +++ b/Common/UnitDefinitions/ElectricCapacitance.json @@ -0,0 +1,33 @@ +{ + "Name": "ElectricCapacitance", + "BaseUnit": "Farad", + "XmlDocSummary": "Capacitance is the capacity of a material object or device to store electric charge.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Capacitance", + "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/ElectricConductance.json b/Common/UnitDefinitions/ElectricConductance.json index e1ef77d71b..bf75404c0e 100644 --- a/Common/UnitDefinitions/ElectricConductance.json +++ b/Common/UnitDefinitions/ElectricConductance.json @@ -1,7 +1,7 @@ { "Name": "ElectricConductance", "BaseUnit": "Siemens", - "XmlDocSummary": "The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor.", + "XmlDocSummary": "The electrical conductance of an object is a measure of the ease with which an electric current passes. Along with susceptance, it is one of two elements of admittance. Its reciprocal quantity is electrical resistance.", "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance", "BaseDimensions": { "L": -2, @@ -15,13 +15,26 @@ "PluralName": "Siemens", "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Nano", "Micro", "Milli", "Kilo" ], + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], "Localization": [ { "Culture": "en-US", "Abbreviations": [ "S" ] } ] + }, + { + "SingularName": "Mho", + "PluralName": "Mhos", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "?" ] + } + ] } ] } diff --git a/Common/UnitDefinitions/ElectricCurrent.json b/Common/UnitDefinitions/ElectricCurrent.json index 91ee353446..8d3478b785 100644 --- a/Common/UnitDefinitions/ElectricCurrent.json +++ b/Common/UnitDefinitions/ElectricCurrent.json @@ -2,6 +2,7 @@ "Name": "ElectricCurrent", "BaseUnit": "Ampere", "XmlDocSummary": "An electric current is a flow of electric charge. In electric circuits this charge is often carried by moving electrons in a wire. It can also be carried by ions in an electrolyte, or by both ions and electrons such as in a plasma.", + "XmlDocRemarks": "If you want to map more parameters into the class (amps RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.", "BaseDimensions": { "I": 1 }, diff --git a/Common/UnitDefinitions/ElectricImpedance.json b/Common/UnitDefinitions/ElectricImpedance.json new file mode 100644 index 0000000000..26c63c8540 --- /dev/null +++ b/Common/UnitDefinitions/ElectricImpedance.json @@ -0,0 +1,28 @@ +{ + "Name": "ElectricImpedance", + "BaseUnit": "Ohm", + "XmlDocSummary": "Electric impedance is the opposition to alternating current presented by the combined effect of resistance and reactance in a circuit. It is defined as the inverse of admittance. The SI unit of impedance is the ohm (symbol Ω).", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_impedance", + "ObsoleteText": "Impedance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricResistance or ElectricReactance instead.", + "BaseDimensions": { + "L": 2, + "M": 1, + "T": -3, + "I": -2 + }, + "Units": [ + { + "SingularName": "Ohm", + "PluralName": "Ohms", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Ω" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/ElectricPotential.json b/Common/UnitDefinitions/ElectricPotential.json index 83eeda0155..ebeb84cbe9 100644 --- a/Common/UnitDefinitions/ElectricPotential.json +++ b/Common/UnitDefinitions/ElectricPotential.json @@ -2,6 +2,7 @@ "Name": "ElectricPotential", "BaseUnit": "Volt", "XmlDocSummary": "In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point.", + "XmlDocRemarks": "If you want to map more parameters into the class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.", "BaseDimensions": { "L": 2, "M": 1, diff --git a/Common/UnitDefinitions/ElectricPotentialAc.json b/Common/UnitDefinitions/ElectricPotentialAc.json index 4fd5eb435d..caf720eb5e 100644 --- a/Common/UnitDefinitions/ElectricPotentialAc.json +++ b/Common/UnitDefinitions/ElectricPotentialAc.json @@ -2,6 +2,8 @@ "Name": "ElectricPotentialAc", "BaseUnit": "VoltAc", "XmlDocSummary": "The Electric Potential of a system known to use Alternating Current.", + "XmlDocRemarks": " has been merged into , and will be removed in a later major version. If you want to map more parameters into the 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", diff --git a/Common/UnitDefinitions/ElectricPotentialDc.json b/Common/UnitDefinitions/ElectricPotentialDc.json index 734ac8bf70..20c268e91f 100644 --- a/Common/UnitDefinitions/ElectricPotentialDc.json +++ b/Common/UnitDefinitions/ElectricPotentialDc.json @@ -2,6 +2,8 @@ "Name": "ElectricPotentialDc", "BaseUnit": "VoltDc", "XmlDocSummary": "The Electric Potential of a system known to use Direct Current.", + "XmlDocRemarks": " has been merged into , and will be removed in a later major version. If you want to map more parameters into the 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", diff --git a/Common/UnitDefinitions/ElectricReactance.json b/Common/UnitDefinitions/ElectricReactance.json new file mode 100644 index 0000000000..fb18130d88 --- /dev/null +++ b/Common/UnitDefinitions/ElectricReactance.json @@ -0,0 +1,27 @@ +{ + "Name": "ElectricReactance", + "BaseUnit": "Ohm", + "XmlDocSummary": "In electrical circuits, reactance is the opposition presented to alternating current by inductance and capacitance. Along with resistance, it is one of two elements of impedance.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_reactance", + "BaseDimensions": { + "L": 2, + "M": 1, + "T": -3, + "I": -2 + }, + "Units": [ + { + "SingularName": "Ohm", + "PluralName": "Ohms", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Ω" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/ElectricReactiveEnergy.json b/Common/UnitDefinitions/ElectricReactiveEnergy.json new file mode 100644 index 0000000000..93e751c9f1 --- /dev/null +++ b/Common/UnitDefinitions/ElectricReactiveEnergy.json @@ -0,0 +1,25 @@ +{ + "Name": "ElectricReactiveEnergy", + "BaseUnit": "VoltampereReactiveHour", + "XmlDocSummary": "The volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour.", + "BaseDimensions": { + "L": 2, + "M": 1, + "T": -1 + }, + "Units": [ + { + "SingularName": "VoltampereReactiveHour", + "PluralName": "VoltampereReactiveHours", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "varh" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/ElectricReactivePower.json b/Common/UnitDefinitions/ElectricReactivePower.json new file mode 100644 index 0000000000..8a689161ab --- /dev/null +++ b/Common/UnitDefinitions/ElectricReactivePower.json @@ -0,0 +1,26 @@ +{ + "Name": "ElectricReactivePower", + "BaseUnit": "VoltampereReactive", + "XmlDocSummary": "In electric power transmission and distribution, volt-ampere reactive (var) is a unit of measurement of reactive power. Reactive power exists in an AC circuit when the current and voltage are not in phase.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state", + "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/UnitDefinitions/ElectricResistance.json b/Common/UnitDefinitions/ElectricResistance.json index 832806049f..edc5c60ece 100644 --- a/Common/UnitDefinitions/ElectricResistance.json +++ b/Common/UnitDefinitions/ElectricResistance.json @@ -1,7 +1,8 @@ { "Name": "ElectricResistance", "BaseUnit": "Ohm", - "XmlDocSummary": "The electrical resistance of an electrical conductor is the opposition to the passage of an electric current through that conductor.", + "XmlDocSummary": "The electrical resistance of an object is a measure of its opposition to the flow of electric current. Along with reactance, it is one of two elements of impedance. Its reciprocal quantity is electrical conductance.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance", "BaseDimensions": { "L": 2, "M": 1, @@ -14,7 +15,7 @@ "PluralName": "Ohms", "FromUnitToBaseFunc": "{x}", "FromBaseToUnitFunc": "{x}", - "Prefixes": [ "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], "Localization": [ { "Culture": "en-US", diff --git a/Common/UnitDefinitions/ElectricSusceptance.json b/Common/UnitDefinitions/ElectricSusceptance.json new file mode 100644 index 0000000000..05e8ad37cf --- /dev/null +++ b/Common/UnitDefinitions/ElectricSusceptance.json @@ -0,0 +1,40 @@ +{ + "Name": "ElectricSusceptance", + "BaseUnit": "Siemens", + "XmlDocSummary": "Electrical susceptance is the imaginary part of admittance, where the real part is conductance.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_susceptance", + "BaseDimensions": { + "L": -2, + "M": -1, + "T": 3, + "I": 2 + }, + "Units": [ + { + "SingularName": "Siemens", + "PluralName": "Siemens", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "S" ] + } + ] + }, + { + "SingularName": "Mho", + "PluralName": "Mhos", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "℧" ] + } + ] + } + ] +} diff --git a/Common/UnitDefinitions/ReactiveEnergy.json b/Common/UnitDefinitions/ReactiveEnergy.json index 3180621fcf..2de036c3eb 100644 --- a/Common/UnitDefinitions/ReactiveEnergy.json +++ b/Common/UnitDefinitions/ReactiveEnergy.json @@ -2,6 +2,8 @@ "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": " has been renamed to , 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, diff --git a/Common/UnitDefinitions/ReactivePower.json b/Common/UnitDefinitions/ReactivePower.json index 51c981cc83..39f43500e2 100644 --- a/Common/UnitDefinitions/ReactivePower.json +++ b/Common/UnitDefinitions/ReactivePower.json @@ -2,6 +2,8 @@ "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": " has been renamed to , 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, diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index 1e027e9e4c..71b06492d6 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -259,7 +259,19 @@ "Microsiemens": 1, "Millisiemens": 2, "Nanosiemens": 3, - "Siemens": 4 + "Siemens": 4, + "Gigamho": 7, + "Gigasiemens": 14, + "Kilomho": 11, + "Kilosiemens": 9, + "Megamho": 8, + "Megasiemens": 6, + "Mho": 13, + "Micromho": 5, + "Millimho": 10, + "Nanomho": 12, + "Teramho": 19, + "Terasiemens": 16 }, "ElectricCharge": { "AmpereHour": 1, @@ -282,7 +294,18 @@ "Millisiemens": 2, "Siemens": 3, "Kilosiemens": 6, - "Nanosiemens": 10 + "Nanosiemens": 10, + "Gigamho": 15, + "Gigasiemens": 5, + "Kilomho": 7, + "Megamho": 13, + "Megasiemens": 12, + "Mho": 9, + "Micromho": 11, + "Millimho": 8, + "Nanomho": 4, + "Teramho": 14, + "Terasiemens": 17 }, "ElectricConductivity": { "SiemensPerFoot": 1, @@ -378,7 +401,8 @@ "Microohm": 4, "Milliohm": 5, "Ohm": 6, - "Teraohm": 12 + "Teraohm": 12, + "Nanoohm": 14 }, "ElectricResistivity": { "KiloohmCentimeter": 1, @@ -1870,5 +1894,76 @@ "SquareMeterDegreeCelsiusPerWatt": 3, "SquareMeterKelvinPerKilowatt": 5, "SquareMeterKelvinPerWatt": 4 + }, + "ElectricApparentEnergy": { + "KilovoltampereHour": 1, + "MegavoltampereHour": 2, + "VoltampereHour": 3 + }, + "ElectricApparentPower": { + "Gigavoltampere": 9, + "Kilovoltampere": 3, + "Megavoltampere": 8, + "Microvoltampere": 5, + "Millivoltampere": 7, + "Voltampere": 1 + }, + "ElectricCapacitance": { + "Farad": 5, + "Kilofarad": 7, + "Megafarad": 4, + "Microfarad": 6, + "Millifarad": 10, + "Nanofarad": 9, + "Picofarad": 8 + }, + "ElectricImpedance": { + "Gigaohm": 10, + "Kiloohm": 6, + "Megaohm": 7, + "Microohm": 2, + "Milliohm": 1, + "Nanoohm": 4, + "Ohm": 9, + "Teraohm": 8 + }, + "ElectricReactance": { + "Gigaohm": 3, + "Kiloohm": 8, + "Megaohm": 10, + "Microohm": 7, + "Milliohm": 4, + "Nanoohm": 2, + "Ohm": 1, + "Teraohm": 5 + }, + "ElectricReactiveEnergy": { + "KilovoltampereReactiveHour": 9, + "MegavoltampereReactiveHour": 7, + "VoltampereReactiveHour": 6 + }, + "ElectricReactivePower": { + "GigavoltampereReactive": 3, + "KilovoltampereReactive": 8, + "MegavoltampereReactive": 5, + "VoltampereReactive": 2 + }, + "ElectricSusceptance": { + "Gigamho": 4, + "Gigasiemens": 5, + "Kilomho": 8, + "Kilosiemens": 9, + "Megamho": 10, + "Megasiemens": 6, + "Mho": 2, + "Micromho": 3, + "Microsiemens": 1, + "Millimho": 7, + "Millisiemens": 16, + "Nanomho": 13, + "Nanosiemens": 20, + "Siemens": 15, + "Teramho": 18, + "Terasiemens": 17 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/ElectricApparentEnergy.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/ElectricApparentEnergy.nfproj new file mode 100644 index 0000000000..ea49fc048a --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/ElectricApparentEnergy.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricApparentEnergy + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/UnitsNet.NanoFramework.ElectricApparentEnergy.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/UnitsNet.NanoFramework.ElectricApparentEnergy.nuspec new file mode 100644 index 0000000000..4d4ac89400 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/UnitsNet.NanoFramework.ElectricApparentEnergy.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricApparentEnergy + 6.0.0-pre012 + Units.NET ElectricApparentEnergy - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricApparentEnergy 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 electricapparentenergy unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentEnergy/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/ElectricApparentPower.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/ElectricApparentPower.nfproj new file mode 100644 index 0000000000..fef4baa953 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/ElectricApparentPower.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {b7a9eb2a-4b0e-548c-2370-a33ee63b21cc} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricApparentPower + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/UnitsNet.NanoFramework.ElectricApparentPower.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/UnitsNet.NanoFramework.ElectricApparentPower.nuspec new file mode 100644 index 0000000000..bfcdc280a1 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/UnitsNet.NanoFramework.ElectricApparentPower.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricApparentPower + 6.0.0-pre012 + Units.NET ElectricApparentPower - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricApparentPower 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 electricapparentpower unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricApparentPower/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/ElectricCapacitance.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/ElectricCapacitance.nfproj new file mode 100644 index 0000000000..61417e0504 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/ElectricCapacitance.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {10e8cf6b-7fec-911f-770d-e3641296ac89} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricCapacitance + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/UnitsNet.NanoFramework.ElectricCapacitance.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/UnitsNet.NanoFramework.ElectricCapacitance.nuspec new file mode 100644 index 0000000000..5cd2b19356 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/UnitsNet.NanoFramework.ElectricCapacitance.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricCapacitance + 6.0.0-pre012 + Units.NET ElectricCapacitance - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricCapacitance 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 electriccapacitance unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricCapacitance/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/ElectricImpedance.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/ElectricImpedance.nfproj new file mode 100644 index 0000000000..e2416e308f --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/ElectricImpedance.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {23a79010-5c1a-9120-0992-a69c8dd80015} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricImpedance + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/UnitsNet.NanoFramework.ElectricImpedance.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/UnitsNet.NanoFramework.ElectricImpedance.nuspec new file mode 100644 index 0000000000..e6ab62d5d3 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/UnitsNet.NanoFramework.ElectricImpedance.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricImpedance + 6.0.0-pre012 + Units.NET ElectricImpedance - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricImpedance 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 electricimpedance unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricImpedance/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/ElectricReactance.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/ElectricReactance.nfproj new file mode 100644 index 0000000000..137639125f --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/ElectricReactance.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {e3d3c1e3-aaa3-5d40-472e-ae837457cf73} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricReactance + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/UnitsNet.NanoFramework.ElectricReactance.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/UnitsNet.NanoFramework.ElectricReactance.nuspec new file mode 100644 index 0000000000..5b46e0824e --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/UnitsNet.NanoFramework.ElectricReactance.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricReactance + 6.0.0-pre012 + Units.NET ElectricReactance - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricReactance 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 electricreactance unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactance/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/ElectricReactiveEnergy.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/ElectricReactiveEnergy.nfproj new file mode 100644 index 0000000000..c159133d3b --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/ElectricReactiveEnergy.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {9f892c4e-26c2-1420-a73c-08138c8f6ca2} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricReactiveEnergy + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/UnitsNet.NanoFramework.ElectricReactiveEnergy.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/UnitsNet.NanoFramework.ElectricReactiveEnergy.nuspec new file mode 100644 index 0000000000..051a514c30 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/UnitsNet.NanoFramework.ElectricReactiveEnergy.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricReactiveEnergy + 6.0.0-pre012 + Units.NET ElectricReactiveEnergy - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricReactiveEnergy 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 electricreactiveenergy unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactiveEnergy/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/ElectricReactivePower.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/ElectricReactivePower.nfproj new file mode 100644 index 0000000000..f8385b3418 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/ElectricReactivePower.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricReactivePower + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/UnitsNet.NanoFramework.ElectricReactivePower.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/UnitsNet.NanoFramework.ElectricReactivePower.nuspec new file mode 100644 index 0000000000..8ce61af7e2 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/UnitsNet.NanoFramework.ElectricReactivePower.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricReactivePower + 6.0.0-pre012 + Units.NET ElectricReactivePower - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricReactivePower 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 electricreactivepower unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricReactivePower/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/ElectricSusceptance.nfproj b/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/ElectricSusceptance.nfproj new file mode 100644 index 0000000000..09618e3e01 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/ElectricSusceptance.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {544c006b-f7de-21a9-a1b4-8df710e184c8} + Library + Properties + 512 + UnitsNet + UnitsNet.ElectricSusceptance + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/UnitsNet.NanoFramework.ElectricSusceptance.nuspec b/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/UnitsNet.NanoFramework.ElectricSusceptance.nuspec new file mode 100644 index 0000000000..1a240f04fc --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/UnitsNet.NanoFramework.ElectricSusceptance.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.ElectricSusceptance + 6.0.0-pre012 + Units.NET ElectricSusceptance - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds ElectricSusceptance 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 electricsusceptance unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/packages.config b/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/ElectricSusceptance/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs index f44f365c30..95494e5cca 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentEnergy.g.cs @@ -26,6 +26,10 @@ 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. /// + /// + /// has been renamed to , 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs index f473beda05..ff465dbb2e 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ApparentPower.g.cs @@ -26,6 +26,10 @@ 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. /// + /// + /// has been renamed to , 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs index f0453dcd61..989b6b3868 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Capacitance.g.cs @@ -27,8 +27,9 @@ namespace UnitsNet /// Capacitance is the ability of a body to store an electric charge. /// /// - /// https://en.wikipedia.org/wiki/Capacitance + /// has been renamed to , 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricAdmittance.g.cs index 7fababbad1..93b1ed8c6d 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -24,8 +24,12 @@ namespace UnitsNet { /// /// - /// Electric admittance is a measure of how easily a circuit or device will allow a current to flow. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S). + /// Electric admittance is a measure of how easily a circuit or device will allow a current to flow by the combined effect of conductance and susceptance in a circuit. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S). /// + /// + /// https://en.wikipedia.org/wiki/Electrical_admittance + /// + [Obsolete("Admittance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricConductance or ElectricSusceptance instead.")] public struct ElectricAdmittance { /// @@ -78,16 +82,66 @@ public ElectricAdmittance(double value, ElectricAdmittanceUnit unit) public static ElectricAdmittance Zero { get; } = new ElectricAdmittance(0, BaseUnit); #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Gigamhos => As(ElectricAdmittanceUnit.Gigamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Gigasiemens => As(ElectricAdmittanceUnit.Gigasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilomhos => As(ElectricAdmittanceUnit.Kilomho); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilosiemens => As(ElectricAdmittanceUnit.Kilosiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Megamhos => As(ElectricAdmittanceUnit.Megamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Megasiemens => As(ElectricAdmittanceUnit.Megasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Mhos => As(ElectricAdmittanceUnit.Mho); + + /// + /// Gets a value of this quantity converted into + /// + public double Micromhos => As(ElectricAdmittanceUnit.Micromho); + /// /// Gets a value of this quantity converted into /// public double Microsiemens => As(ElectricAdmittanceUnit.Microsiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Millimhos => As(ElectricAdmittanceUnit.Millimho); + /// /// Gets a value of this quantity converted into /// public double Millisiemens => As(ElectricAdmittanceUnit.Millisiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Nanomhos => As(ElectricAdmittanceUnit.Nanomho); + /// /// Gets a value of this quantity converted into /// @@ -98,20 +152,80 @@ public ElectricAdmittance(double value, ElectricAdmittanceUnit unit) /// public double Siemens => As(ElectricAdmittanceUnit.Siemens); + /// + /// Gets a value of this quantity converted into + /// + public double Teramhos => As(ElectricAdmittanceUnit.Teramho); + + /// + /// Gets a value of this quantity converted into + /// + public double Terasiemens => As(ElectricAdmittanceUnit.Terasiemens); + #endregion #region Static Factory Methods + /// + /// Creates a from . + /// + public static ElectricAdmittance FromGigamhos(double gigamhos) => new ElectricAdmittance(gigamhos, ElectricAdmittanceUnit.Gigamho); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromGigasiemens(double gigasiemens) => new ElectricAdmittance(gigasiemens, ElectricAdmittanceUnit.Gigasiemens); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromKilomhos(double kilomhos) => new ElectricAdmittance(kilomhos, ElectricAdmittanceUnit.Kilomho); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromKilosiemens(double kilosiemens) => new ElectricAdmittance(kilosiemens, ElectricAdmittanceUnit.Kilosiemens); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMegamhos(double megamhos) => new ElectricAdmittance(megamhos, ElectricAdmittanceUnit.Megamho); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMegasiemens(double megasiemens) => new ElectricAdmittance(megasiemens, ElectricAdmittanceUnit.Megasiemens); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMhos(double mhos) => new ElectricAdmittance(mhos, ElectricAdmittanceUnit.Mho); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMicromhos(double micromhos) => new ElectricAdmittance(micromhos, ElectricAdmittanceUnit.Micromho); + /// /// Creates a from . /// public static ElectricAdmittance FromMicrosiemens(double microsiemens) => new ElectricAdmittance(microsiemens, ElectricAdmittanceUnit.Microsiemens); + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMillimhos(double millimhos) => new ElectricAdmittance(millimhos, ElectricAdmittanceUnit.Millimho); + /// /// Creates a from . /// public static ElectricAdmittance FromMillisiemens(double millisiemens) => new ElectricAdmittance(millisiemens, ElectricAdmittanceUnit.Millisiemens); + /// + /// Creates a from . + /// + public static ElectricAdmittance FromNanomhos(double nanomhos) => new ElectricAdmittance(nanomhos, ElectricAdmittanceUnit.Nanomho); + /// /// Creates a from . /// @@ -122,6 +236,16 @@ public ElectricAdmittance(double value, ElectricAdmittanceUnit unit) /// public static ElectricAdmittance FromSiemens(double siemens) => new ElectricAdmittance(siemens, ElectricAdmittanceUnit.Siemens); + /// + /// Creates a from . + /// + public static ElectricAdmittance FromTeramhos(double teramhos) => new ElectricAdmittance(teramhos, ElectricAdmittanceUnit.Teramho); + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromTerasiemens(double terasiemens) => new ElectricAdmittance(terasiemens, ElectricAdmittanceUnit.Terasiemens); + /// /// Dynamically convert from value and unit enum to . /// @@ -162,10 +286,22 @@ private double GetValueInBaseUnit() { return Unit switch { + ElectricAdmittanceUnit.Gigamho => (_value) * 1e9d, + ElectricAdmittanceUnit.Gigasiemens => (_value) * 1e9d, + ElectricAdmittanceUnit.Kilomho => (_value) * 1e3d, + ElectricAdmittanceUnit.Kilosiemens => (_value) * 1e3d, + ElectricAdmittanceUnit.Megamho => (_value) * 1e6d, + ElectricAdmittanceUnit.Megasiemens => (_value) * 1e6d, + ElectricAdmittanceUnit.Mho => _value, + ElectricAdmittanceUnit.Micromho => (_value) * 1e-6d, ElectricAdmittanceUnit.Microsiemens => (_value) * 1e-6d, + ElectricAdmittanceUnit.Millimho => (_value) * 1e-3d, ElectricAdmittanceUnit.Millisiemens => (_value) * 1e-3d, + ElectricAdmittanceUnit.Nanomho => (_value) * 1e-9d, ElectricAdmittanceUnit.Nanosiemens => (_value) * 1e-9d, ElectricAdmittanceUnit.Siemens => _value, + ElectricAdmittanceUnit.Teramho => (_value) * 1e12d, + ElectricAdmittanceUnit.Terasiemens => (_value) * 1e12d, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -179,10 +315,22 @@ private double GetValueAs(ElectricAdmittanceUnit unit) return unit switch { + ElectricAdmittanceUnit.Gigamho => (baseUnitValue) / 1e9d, + ElectricAdmittanceUnit.Gigasiemens => (baseUnitValue) / 1e9d, + ElectricAdmittanceUnit.Kilomho => (baseUnitValue) / 1e3d, + ElectricAdmittanceUnit.Kilosiemens => (baseUnitValue) / 1e3d, + ElectricAdmittanceUnit.Megamho => (baseUnitValue) / 1e6d, + ElectricAdmittanceUnit.Megasiemens => (baseUnitValue) / 1e6d, + ElectricAdmittanceUnit.Mho => baseUnitValue, + ElectricAdmittanceUnit.Micromho => (baseUnitValue) / 1e-6d, ElectricAdmittanceUnit.Microsiemens => (baseUnitValue) / 1e-6d, + ElectricAdmittanceUnit.Millimho => (baseUnitValue) / 1e-3d, ElectricAdmittanceUnit.Millisiemens => (baseUnitValue) / 1e-3d, + ElectricAdmittanceUnit.Nanomho => (baseUnitValue) / 1e-9d, ElectricAdmittanceUnit.Nanosiemens => (baseUnitValue) / 1e-9d, ElectricAdmittanceUnit.Siemens => baseUnitValue, + ElectricAdmittanceUnit.Teramho => (baseUnitValue) / 1e12d, + ElectricAdmittanceUnit.Terasiemens => (baseUnitValue) / 1e12d, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs new file mode 100644 index 0000000000..dda656ec98 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs @@ -0,0 +1,181 @@ +//------------------------------------------------------------------------------ +// +// 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. + /// + public struct ElectricApparentEnergy + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricApparentEnergyUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricApparentEnergyUnit 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 ElectricApparentEnergy(double value, ElectricApparentEnergyUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricApparentEnergy, which is Second. All conversions go via this value. + /// + public static ElectricApparentEnergyUnit BaseUnit { get; } = ElectricApparentEnergyUnit.VoltampereHour; + + /// + /// Represents the largest possible value of ElectricApparentEnergy. + /// + public static ElectricApparentEnergy MaxValue { get; } = new ElectricApparentEnergy(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricApparentEnergy. + /// + public static ElectricApparentEnergy MinValue { get; } = new ElectricApparentEnergy(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricApparentEnergy Zero { get; } = new ElectricApparentEnergy(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilovoltampereHours => As(ElectricApparentEnergyUnit.KilovoltampereHour); + + /// + /// Gets a value of this quantity converted into + /// + public double MegavoltampereHours => As(ElectricApparentEnergyUnit.MegavoltampereHour); + + /// + /// Gets a value of this quantity converted into + /// + public double VoltampereHours => As(ElectricApparentEnergyUnit.VoltampereHour); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricApparentEnergy FromKilovoltampereHours(double kilovoltamperehours) => new ElectricApparentEnergy(kilovoltamperehours, ElectricApparentEnergyUnit.KilovoltampereHour); + + /// + /// Creates a from . + /// + public static ElectricApparentEnergy FromMegavoltampereHours(double megavoltamperehours) => new ElectricApparentEnergy(megavoltamperehours, ElectricApparentEnergyUnit.MegavoltampereHour); + + /// + /// Creates a from . + /// + public static ElectricApparentEnergy FromVoltampereHours(double voltamperehours) => new ElectricApparentEnergy(voltamperehours, ElectricApparentEnergyUnit.VoltampereHour); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricApparentEnergy unit value. + public static ElectricApparentEnergy From(double value, ElectricApparentEnergyUnit fromUnit) + { + return new ElectricApparentEnergy(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricApparentEnergyUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricApparentEnergy to another ElectricApparentEnergy with the unit representation . + /// + /// A ElectricApparentEnergy with the specified unit. + public ElectricApparentEnergy ToUnit(ElectricApparentEnergyUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricApparentEnergy(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 + { + ElectricApparentEnergyUnit.KilovoltampereHour => (_value) * 1e3d, + ElectricApparentEnergyUnit.MegavoltampereHour => (_value) * 1e6d, + ElectricApparentEnergyUnit.VoltampereHour => _value, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricApparentEnergyUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricApparentEnergyUnit.KilovoltampereHour => (baseUnitValue) / 1e3d, + ElectricApparentEnergyUnit.MegavoltampereHour => (baseUnitValue) / 1e6d, + ElectricApparentEnergyUnit.VoltampereHour => baseUnitValue, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricApparentPower.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricApparentPower.g.cs new file mode 100644 index 0000000000..43111343ea --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricApparentPower.g.cs @@ -0,0 +1,220 @@ +//------------------------------------------------------------------------------ +// +// 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. It is the product of the root mean square voltage (in volts) and the root mean square current (in amperes). + /// + /// + /// https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state + /// + public struct ElectricApparentPower + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricApparentPowerUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricApparentPowerUnit 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 ElectricApparentPower(double value, ElectricApparentPowerUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricApparentPower, which is Second. All conversions go via this value. + /// + public static ElectricApparentPowerUnit BaseUnit { get; } = ElectricApparentPowerUnit.Voltampere; + + /// + /// Represents the largest possible value of ElectricApparentPower. + /// + public static ElectricApparentPower MaxValue { get; } = new ElectricApparentPower(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricApparentPower. + /// + public static ElectricApparentPower MinValue { get; } = new ElectricApparentPower(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricApparentPower Zero { get; } = new ElectricApparentPower(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigavoltamperes => As(ElectricApparentPowerUnit.Gigavoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilovoltamperes => As(ElectricApparentPowerUnit.Kilovoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Megavoltamperes => As(ElectricApparentPowerUnit.Megavoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Microvoltamperes => As(ElectricApparentPowerUnit.Microvoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Millivoltamperes => As(ElectricApparentPowerUnit.Millivoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Voltamperes => As(ElectricApparentPowerUnit.Voltampere); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromGigavoltamperes(double gigavoltamperes) => new ElectricApparentPower(gigavoltamperes, ElectricApparentPowerUnit.Gigavoltampere); + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromKilovoltamperes(double kilovoltamperes) => new ElectricApparentPower(kilovoltamperes, ElectricApparentPowerUnit.Kilovoltampere); + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromMegavoltamperes(double megavoltamperes) => new ElectricApparentPower(megavoltamperes, ElectricApparentPowerUnit.Megavoltampere); + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromMicrovoltamperes(double microvoltamperes) => new ElectricApparentPower(microvoltamperes, ElectricApparentPowerUnit.Microvoltampere); + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromMillivoltamperes(double millivoltamperes) => new ElectricApparentPower(millivoltamperes, ElectricApparentPowerUnit.Millivoltampere); + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromVoltamperes(double voltamperes) => new ElectricApparentPower(voltamperes, ElectricApparentPowerUnit.Voltampere); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricApparentPower unit value. + public static ElectricApparentPower From(double value, ElectricApparentPowerUnit fromUnit) + { + return new ElectricApparentPower(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricApparentPowerUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricApparentPower to another ElectricApparentPower with the unit representation . + /// + /// A ElectricApparentPower with the specified unit. + public ElectricApparentPower ToUnit(ElectricApparentPowerUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricApparentPower(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 + { + ElectricApparentPowerUnit.Gigavoltampere => (_value) * 1e9d, + ElectricApparentPowerUnit.Kilovoltampere => (_value) * 1e3d, + ElectricApparentPowerUnit.Megavoltampere => (_value) * 1e6d, + ElectricApparentPowerUnit.Microvoltampere => (_value) * 1e-6d, + ElectricApparentPowerUnit.Millivoltampere => (_value) * 1e-3d, + ElectricApparentPowerUnit.Voltampere => _value, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricApparentPowerUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricApparentPowerUnit.Gigavoltampere => (baseUnitValue) / 1e9d, + ElectricApparentPowerUnit.Kilovoltampere => (baseUnitValue) / 1e3d, + ElectricApparentPowerUnit.Megavoltampere => (baseUnitValue) / 1e6d, + ElectricApparentPowerUnit.Microvoltampere => (baseUnitValue) / 1e-6d, + ElectricApparentPowerUnit.Millivoltampere => (baseUnitValue) / 1e-3d, + ElectricApparentPowerUnit.Voltampere => baseUnitValue, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCapacitance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCapacitance.g.cs new file mode 100644 index 0000000000..636e11ea34 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCapacitance.g.cs @@ -0,0 +1,232 @@ +//------------------------------------------------------------------------------ +// +// 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 capacity of a material object or device to store electric charge. + /// + /// + /// https://en.wikipedia.org/wiki/Capacitance + /// + public struct ElectricCapacitance + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricCapacitanceUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricCapacitanceUnit 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 ElectricCapacitance(double value, ElectricCapacitanceUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricCapacitance, which is Second. All conversions go via this value. + /// + public static ElectricCapacitanceUnit BaseUnit { get; } = ElectricCapacitanceUnit.Farad; + + /// + /// Represents the largest possible value of ElectricCapacitance. + /// + public static ElectricCapacitance MaxValue { get; } = new ElectricCapacitance(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricCapacitance. + /// + public static ElectricCapacitance MinValue { get; } = new ElectricCapacitance(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricCapacitance Zero { get; } = new ElectricCapacitance(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Farads => As(ElectricCapacitanceUnit.Farad); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilofarads => As(ElectricCapacitanceUnit.Kilofarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Megafarads => As(ElectricCapacitanceUnit.Megafarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Microfarads => As(ElectricCapacitanceUnit.Microfarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Millifarads => As(ElectricCapacitanceUnit.Millifarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanofarads => As(ElectricCapacitanceUnit.Nanofarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Picofarads => As(ElectricCapacitanceUnit.Picofarad); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromFarads(double farads) => new ElectricCapacitance(farads, ElectricCapacitanceUnit.Farad); + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromKilofarads(double kilofarads) => new ElectricCapacitance(kilofarads, ElectricCapacitanceUnit.Kilofarad); + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromMegafarads(double megafarads) => new ElectricCapacitance(megafarads, ElectricCapacitanceUnit.Megafarad); + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromMicrofarads(double microfarads) => new ElectricCapacitance(microfarads, ElectricCapacitanceUnit.Microfarad); + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromMillifarads(double millifarads) => new ElectricCapacitance(millifarads, ElectricCapacitanceUnit.Millifarad); + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromNanofarads(double nanofarads) => new ElectricCapacitance(nanofarads, ElectricCapacitanceUnit.Nanofarad); + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromPicofarads(double picofarads) => new ElectricCapacitance(picofarads, ElectricCapacitanceUnit.Picofarad); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricCapacitance unit value. + public static ElectricCapacitance From(double value, ElectricCapacitanceUnit fromUnit) + { + return new ElectricCapacitance(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricCapacitanceUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricCapacitance to another ElectricCapacitance with the unit representation . + /// + /// A ElectricCapacitance with the specified unit. + public ElectricCapacitance ToUnit(ElectricCapacitanceUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricCapacitance(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 + { + ElectricCapacitanceUnit.Farad => _value, + ElectricCapacitanceUnit.Kilofarad => (_value) * 1e3d, + ElectricCapacitanceUnit.Megafarad => (_value) * 1e6d, + ElectricCapacitanceUnit.Microfarad => (_value) * 1e-6d, + ElectricCapacitanceUnit.Millifarad => (_value) * 1e-3d, + ElectricCapacitanceUnit.Nanofarad => (_value) * 1e-9d, + ElectricCapacitanceUnit.Picofarad => (_value) * 1e-12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricCapacitanceUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricCapacitanceUnit.Farad => baseUnitValue, + ElectricCapacitanceUnit.Kilofarad => (baseUnitValue) / 1e3d, + ElectricCapacitanceUnit.Megafarad => (baseUnitValue) / 1e6d, + ElectricCapacitanceUnit.Microfarad => (baseUnitValue) / 1e-6d, + ElectricCapacitanceUnit.Millifarad => (baseUnitValue) / 1e-3d, + ElectricCapacitanceUnit.Nanofarad => (baseUnitValue) / 1e-9d, + ElectricCapacitanceUnit.Picofarad => (baseUnitValue) / 1e-12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricConductance.g.cs index c2fab8b889..930aa75ffa 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -24,7 +24,7 @@ namespace UnitsNet { /// /// - /// The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor. + /// The electrical conductance of an object is a measure of the ease with which an electric current passes. Along with susceptance, it is one of two elements of admittance. Its reciprocal quantity is electrical resistance. /// /// /// https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance @@ -81,21 +81,66 @@ public ElectricConductance(double value, ElectricConductanceUnit unit) public static ElectricConductance Zero { get; } = new ElectricConductance(0, BaseUnit); #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Gigamhos => As(ElectricConductanceUnit.Gigamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Gigasiemens => As(ElectricConductanceUnit.Gigasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilomhos => As(ElectricConductanceUnit.Kilomho); + /// /// Gets a value of this quantity converted into /// public double Kilosiemens => As(ElectricConductanceUnit.Kilosiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Megamhos => As(ElectricConductanceUnit.Megamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Megasiemens => As(ElectricConductanceUnit.Megasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Mhos => As(ElectricConductanceUnit.Mho); + + /// + /// Gets a value of this quantity converted into + /// + public double Micromhos => As(ElectricConductanceUnit.Micromho); + /// /// Gets a value of this quantity converted into /// public double Microsiemens => As(ElectricConductanceUnit.Microsiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Millimhos => As(ElectricConductanceUnit.Millimho); + /// /// Gets a value of this quantity converted into /// public double Millisiemens => As(ElectricConductanceUnit.Millisiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Nanomhos => As(ElectricConductanceUnit.Nanomho); + /// /// Gets a value of this quantity converted into /// @@ -106,25 +151,80 @@ public ElectricConductance(double value, ElectricConductanceUnit unit) /// public double Siemens => As(ElectricConductanceUnit.Siemens); + /// + /// Gets a value of this quantity converted into + /// + public double Teramhos => As(ElectricConductanceUnit.Teramho); + + /// + /// Gets a value of this quantity converted into + /// + public double Terasiemens => As(ElectricConductanceUnit.Terasiemens); + #endregion #region Static Factory Methods + /// + /// Creates a from . + /// + public static ElectricConductance FromGigamhos(double gigamhos) => new ElectricConductance(gigamhos, ElectricConductanceUnit.Gigamho); + + /// + /// Creates a from . + /// + public static ElectricConductance FromGigasiemens(double gigasiemens) => new ElectricConductance(gigasiemens, ElectricConductanceUnit.Gigasiemens); + + /// + /// Creates a from . + /// + public static ElectricConductance FromKilomhos(double kilomhos) => new ElectricConductance(kilomhos, ElectricConductanceUnit.Kilomho); + /// /// Creates a from . /// public static ElectricConductance FromKilosiemens(double kilosiemens) => new ElectricConductance(kilosiemens, ElectricConductanceUnit.Kilosiemens); + /// + /// Creates a from . + /// + public static ElectricConductance FromMegamhos(double megamhos) => new ElectricConductance(megamhos, ElectricConductanceUnit.Megamho); + + /// + /// Creates a from . + /// + public static ElectricConductance FromMegasiemens(double megasiemens) => new ElectricConductance(megasiemens, ElectricConductanceUnit.Megasiemens); + + /// + /// Creates a from . + /// + public static ElectricConductance FromMhos(double mhos) => new ElectricConductance(mhos, ElectricConductanceUnit.Mho); + + /// + /// Creates a from . + /// + public static ElectricConductance FromMicromhos(double micromhos) => new ElectricConductance(micromhos, ElectricConductanceUnit.Micromho); + /// /// Creates a from . /// public static ElectricConductance FromMicrosiemens(double microsiemens) => new ElectricConductance(microsiemens, ElectricConductanceUnit.Microsiemens); + /// + /// Creates a from . + /// + public static ElectricConductance FromMillimhos(double millimhos) => new ElectricConductance(millimhos, ElectricConductanceUnit.Millimho); + /// /// Creates a from . /// public static ElectricConductance FromMillisiemens(double millisiemens) => new ElectricConductance(millisiemens, ElectricConductanceUnit.Millisiemens); + /// + /// Creates a from . + /// + public static ElectricConductance FromNanomhos(double nanomhos) => new ElectricConductance(nanomhos, ElectricConductanceUnit.Nanomho); + /// /// Creates a from . /// @@ -135,6 +235,16 @@ public ElectricConductance(double value, ElectricConductanceUnit unit) /// public static ElectricConductance FromSiemens(double siemens) => new ElectricConductance(siemens, ElectricConductanceUnit.Siemens); + /// + /// Creates a from . + /// + public static ElectricConductance FromTeramhos(double teramhos) => new ElectricConductance(teramhos, ElectricConductanceUnit.Teramho); + + /// + /// Creates a from . + /// + public static ElectricConductance FromTerasiemens(double terasiemens) => new ElectricConductance(terasiemens, ElectricConductanceUnit.Terasiemens); + /// /// Dynamically convert from value and unit enum to . /// @@ -175,11 +285,22 @@ private double GetValueInBaseUnit() { return Unit switch { + ElectricConductanceUnit.Gigamho => (_value) * 1e9d, + ElectricConductanceUnit.Gigasiemens => (_value) * 1e9d, + ElectricConductanceUnit.Kilomho => (_value) * 1e3d, ElectricConductanceUnit.Kilosiemens => (_value) * 1e3d, + ElectricConductanceUnit.Megamho => (_value) * 1e6d, + ElectricConductanceUnit.Megasiemens => (_value) * 1e6d, + ElectricConductanceUnit.Mho => _value, + ElectricConductanceUnit.Micromho => (_value) * 1e-6d, ElectricConductanceUnit.Microsiemens => (_value) * 1e-6d, + ElectricConductanceUnit.Millimho => (_value) * 1e-3d, ElectricConductanceUnit.Millisiemens => (_value) * 1e-3d, + ElectricConductanceUnit.Nanomho => (_value) * 1e-9d, ElectricConductanceUnit.Nanosiemens => (_value) * 1e-9d, ElectricConductanceUnit.Siemens => _value, + ElectricConductanceUnit.Teramho => (_value) * 1e12d, + ElectricConductanceUnit.Terasiemens => (_value) * 1e12d, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") }; } @@ -193,11 +314,22 @@ private double GetValueAs(ElectricConductanceUnit unit) return unit switch { + ElectricConductanceUnit.Gigamho => (baseUnitValue) / 1e9d, + ElectricConductanceUnit.Gigasiemens => (baseUnitValue) / 1e9d, + ElectricConductanceUnit.Kilomho => (baseUnitValue) / 1e3d, ElectricConductanceUnit.Kilosiemens => (baseUnitValue) / 1e3d, + ElectricConductanceUnit.Megamho => (baseUnitValue) / 1e6d, + ElectricConductanceUnit.Megasiemens => (baseUnitValue) / 1e6d, + ElectricConductanceUnit.Mho => baseUnitValue, + ElectricConductanceUnit.Micromho => (baseUnitValue) / 1e-6d, ElectricConductanceUnit.Microsiemens => (baseUnitValue) / 1e-6d, + ElectricConductanceUnit.Millimho => (baseUnitValue) / 1e-3d, ElectricConductanceUnit.Millisiemens => (baseUnitValue) / 1e-3d, + ElectricConductanceUnit.Nanomho => (baseUnitValue) / 1e-9d, ElectricConductanceUnit.Nanosiemens => (baseUnitValue) / 1e-9d, ElectricConductanceUnit.Siemens => baseUnitValue, + ElectricConductanceUnit.Teramho => (baseUnitValue) / 1e12d, + ElectricConductanceUnit.Terasiemens => (baseUnitValue) / 1e12d, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") }; } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCurrent.g.cs index e43a59993d..85be63dfd2 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -26,6 +26,9 @@ namespace UnitsNet /// /// An electric current is a flow of electric charge. In electric circuits this charge is often carried by moving electrons in a wire. It can also be carried by ions in an electrolyte, or by both ions and electrons such as in a plasma. /// + /// + /// If you want to map more parameters into the class (amps RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. + /// public struct ElectricCurrent { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricImpedance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricImpedance.g.cs new file mode 100644 index 0000000000..9aa504f3fa --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricImpedance.g.cs @@ -0,0 +1,245 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// Electric impedance is the opposition to alternating current presented by the combined effect of resistance and reactance in a circuit. It is defined as the inverse of admittance. The SI unit of impedance is the ohm (symbol Ω). + /// + /// + /// https://en.wikipedia.org/wiki/Electrical_impedance + /// + [Obsolete("Impedance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricResistance or ElectricReactance instead.")] + public struct ElectricImpedance + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricImpedanceUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricImpedanceUnit 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 ElectricImpedance(double value, ElectricImpedanceUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricImpedance, which is Second. All conversions go via this value. + /// + public static ElectricImpedanceUnit BaseUnit { get; } = ElectricImpedanceUnit.Ohm; + + /// + /// Represents the largest possible value of ElectricImpedance. + /// + public static ElectricImpedance MaxValue { get; } = new ElectricImpedance(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricImpedance. + /// + public static ElectricImpedance MinValue { get; } = new ElectricImpedance(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricImpedance Zero { get; } = new ElectricImpedance(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigaohms => As(ElectricImpedanceUnit.Gigaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Kiloohms => As(ElectricImpedanceUnit.Kiloohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Megaohms => As(ElectricImpedanceUnit.Megaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Microohms => As(ElectricImpedanceUnit.Microohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Milliohms => As(ElectricImpedanceUnit.Milliohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanoohms => As(ElectricImpedanceUnit.Nanoohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Ohms => As(ElectricImpedanceUnit.Ohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Teraohms => As(ElectricImpedanceUnit.Teraohm); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricImpedance FromGigaohms(double gigaohms) => new ElectricImpedance(gigaohms, ElectricImpedanceUnit.Gigaohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromKiloohms(double kiloohms) => new ElectricImpedance(kiloohms, ElectricImpedanceUnit.Kiloohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromMegaohms(double megaohms) => new ElectricImpedance(megaohms, ElectricImpedanceUnit.Megaohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromMicroohms(double microohms) => new ElectricImpedance(microohms, ElectricImpedanceUnit.Microohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromMilliohms(double milliohms) => new ElectricImpedance(milliohms, ElectricImpedanceUnit.Milliohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromNanoohms(double nanoohms) => new ElectricImpedance(nanoohms, ElectricImpedanceUnit.Nanoohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromOhms(double ohms) => new ElectricImpedance(ohms, ElectricImpedanceUnit.Ohm); + + /// + /// Creates a from . + /// + public static ElectricImpedance FromTeraohms(double teraohms) => new ElectricImpedance(teraohms, ElectricImpedanceUnit.Teraohm); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricImpedance unit value. + public static ElectricImpedance From(double value, ElectricImpedanceUnit fromUnit) + { + return new ElectricImpedance(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricImpedanceUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricImpedance to another ElectricImpedance with the unit representation . + /// + /// A ElectricImpedance with the specified unit. + public ElectricImpedance ToUnit(ElectricImpedanceUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricImpedance(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 + { + ElectricImpedanceUnit.Gigaohm => (_value) * 1e9d, + ElectricImpedanceUnit.Kiloohm => (_value) * 1e3d, + ElectricImpedanceUnit.Megaohm => (_value) * 1e6d, + ElectricImpedanceUnit.Microohm => (_value) * 1e-6d, + ElectricImpedanceUnit.Milliohm => (_value) * 1e-3d, + ElectricImpedanceUnit.Nanoohm => (_value) * 1e-9d, + ElectricImpedanceUnit.Ohm => _value, + ElectricImpedanceUnit.Teraohm => (_value) * 1e12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricImpedanceUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricImpedanceUnit.Gigaohm => (baseUnitValue) / 1e9d, + ElectricImpedanceUnit.Kiloohm => (baseUnitValue) / 1e3d, + ElectricImpedanceUnit.Megaohm => (baseUnitValue) / 1e6d, + ElectricImpedanceUnit.Microohm => (baseUnitValue) / 1e-6d, + ElectricImpedanceUnit.Milliohm => (baseUnitValue) / 1e-3d, + ElectricImpedanceUnit.Nanoohm => (baseUnitValue) / 1e-9d, + ElectricImpedanceUnit.Ohm => baseUnitValue, + ElectricImpedanceUnit.Teraohm => (baseUnitValue) / 1e12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotential.g.cs index e07625718d..eb87fd5730 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -26,6 +26,9 @@ namespace UnitsNet /// /// In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point. /// + /// + /// If you want to map more parameters into the class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. + /// public struct ElectricPotential { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs index 7977b80791..f4a6166263 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialAc.g.cs @@ -26,6 +26,10 @@ namespace UnitsNet /// /// The Electric Potential of a system known to use Alternating Current. /// + /// + /// has been merged into , and will be removed in a later major version. If you want to map more parameters into the 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs index 591c98621e..2b66d5c1e5 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricPotentialDc.g.cs @@ -26,6 +26,10 @@ namespace UnitsNet /// /// The Electric Potential of a system known to use Direct Current. /// + /// + /// has been merged into , and will be removed in a later major version. If you want to map more parameters into the 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactance.g.cs new file mode 100644 index 0000000000..0b3394d6fc --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactance.g.cs @@ -0,0 +1,244 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// In electrical circuits, reactance is the opposition presented to alternating current by inductance and capacitance. Along with resistance, it is one of two elements of impedance. + /// + /// + /// https://en.wikipedia.org/wiki/Electrical_reactance + /// + public struct ElectricReactance + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricReactanceUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricReactanceUnit 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 ElectricReactance(double value, ElectricReactanceUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricReactance, which is Second. All conversions go via this value. + /// + public static ElectricReactanceUnit BaseUnit { get; } = ElectricReactanceUnit.Ohm; + + /// + /// Represents the largest possible value of ElectricReactance. + /// + public static ElectricReactance MaxValue { get; } = new ElectricReactance(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricReactance. + /// + public static ElectricReactance MinValue { get; } = new ElectricReactance(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricReactance Zero { get; } = new ElectricReactance(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigaohms => As(ElectricReactanceUnit.Gigaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Kiloohms => As(ElectricReactanceUnit.Kiloohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Megaohms => As(ElectricReactanceUnit.Megaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Microohms => As(ElectricReactanceUnit.Microohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Milliohms => As(ElectricReactanceUnit.Milliohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanoohms => As(ElectricReactanceUnit.Nanoohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Ohms => As(ElectricReactanceUnit.Ohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Teraohms => As(ElectricReactanceUnit.Teraohm); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricReactance FromGigaohms(double gigaohms) => new ElectricReactance(gigaohms, ElectricReactanceUnit.Gigaohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromKiloohms(double kiloohms) => new ElectricReactance(kiloohms, ElectricReactanceUnit.Kiloohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromMegaohms(double megaohms) => new ElectricReactance(megaohms, ElectricReactanceUnit.Megaohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromMicroohms(double microohms) => new ElectricReactance(microohms, ElectricReactanceUnit.Microohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromMilliohms(double milliohms) => new ElectricReactance(milliohms, ElectricReactanceUnit.Milliohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromNanoohms(double nanoohms) => new ElectricReactance(nanoohms, ElectricReactanceUnit.Nanoohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromOhms(double ohms) => new ElectricReactance(ohms, ElectricReactanceUnit.Ohm); + + /// + /// Creates a from . + /// + public static ElectricReactance FromTeraohms(double teraohms) => new ElectricReactance(teraohms, ElectricReactanceUnit.Teraohm); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricReactance unit value. + public static ElectricReactance From(double value, ElectricReactanceUnit fromUnit) + { + return new ElectricReactance(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricReactanceUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricReactance to another ElectricReactance with the unit representation . + /// + /// A ElectricReactance with the specified unit. + public ElectricReactance ToUnit(ElectricReactanceUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricReactance(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 + { + ElectricReactanceUnit.Gigaohm => (_value) * 1e9d, + ElectricReactanceUnit.Kiloohm => (_value) * 1e3d, + ElectricReactanceUnit.Megaohm => (_value) * 1e6d, + ElectricReactanceUnit.Microohm => (_value) * 1e-6d, + ElectricReactanceUnit.Milliohm => (_value) * 1e-3d, + ElectricReactanceUnit.Nanoohm => (_value) * 1e-9d, + ElectricReactanceUnit.Ohm => _value, + ElectricReactanceUnit.Teraohm => (_value) * 1e12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricReactanceUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricReactanceUnit.Gigaohm => (baseUnitValue) / 1e9d, + ElectricReactanceUnit.Kiloohm => (baseUnitValue) / 1e3d, + ElectricReactanceUnit.Megaohm => (baseUnitValue) / 1e6d, + ElectricReactanceUnit.Microohm => (baseUnitValue) / 1e-6d, + ElectricReactanceUnit.Milliohm => (baseUnitValue) / 1e-3d, + ElectricReactanceUnit.Nanoohm => (baseUnitValue) / 1e-9d, + ElectricReactanceUnit.Ohm => baseUnitValue, + ElectricReactanceUnit.Teraohm => (baseUnitValue) / 1e12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs new file mode 100644 index 0000000000..b9f634d877 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs @@ -0,0 +1,181 @@ +//------------------------------------------------------------------------------ +// +// 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. + /// + public struct ElectricReactiveEnergy + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricReactiveEnergyUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricReactiveEnergyUnit 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 ElectricReactiveEnergy(double value, ElectricReactiveEnergyUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricReactiveEnergy, which is Second. All conversions go via this value. + /// + public static ElectricReactiveEnergyUnit BaseUnit { get; } = ElectricReactiveEnergyUnit.VoltampereReactiveHour; + + /// + /// Represents the largest possible value of ElectricReactiveEnergy. + /// + public static ElectricReactiveEnergy MaxValue { get; } = new ElectricReactiveEnergy(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricReactiveEnergy. + /// + public static ElectricReactiveEnergy MinValue { get; } = new ElectricReactiveEnergy(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricReactiveEnergy Zero { get; } = new ElectricReactiveEnergy(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilovoltampereReactiveHours => As(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour); + + /// + /// Gets a value of this quantity converted into + /// + public double MegavoltampereReactiveHours => As(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour); + + /// + /// Gets a value of this quantity converted into + /// + public double VoltampereReactiveHours => As(ElectricReactiveEnergyUnit.VoltampereReactiveHour); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricReactiveEnergy FromKilovoltampereReactiveHours(double kilovoltamperereactivehours) => new ElectricReactiveEnergy(kilovoltamperereactivehours, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour); + + /// + /// Creates a from . + /// + public static ElectricReactiveEnergy FromMegavoltampereReactiveHours(double megavoltamperereactivehours) => new ElectricReactiveEnergy(megavoltamperereactivehours, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour); + + /// + /// Creates a from . + /// + public static ElectricReactiveEnergy FromVoltampereReactiveHours(double voltamperereactivehours) => new ElectricReactiveEnergy(voltamperereactivehours, ElectricReactiveEnergyUnit.VoltampereReactiveHour); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricReactiveEnergy unit value. + public static ElectricReactiveEnergy From(double value, ElectricReactiveEnergyUnit fromUnit) + { + return new ElectricReactiveEnergy(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricReactiveEnergyUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricReactiveEnergy to another ElectricReactiveEnergy with the unit representation . + /// + /// A ElectricReactiveEnergy with the specified unit. + public ElectricReactiveEnergy ToUnit(ElectricReactiveEnergyUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricReactiveEnergy(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 + { + ElectricReactiveEnergyUnit.KilovoltampereReactiveHour => (_value) * 1e3d, + ElectricReactiveEnergyUnit.MegavoltampereReactiveHour => (_value) * 1e6d, + ElectricReactiveEnergyUnit.VoltampereReactiveHour => _value, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricReactiveEnergyUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricReactiveEnergyUnit.KilovoltampereReactiveHour => (baseUnitValue) / 1e3d, + ElectricReactiveEnergyUnit.MegavoltampereReactiveHour => (baseUnitValue) / 1e6d, + ElectricReactiveEnergyUnit.VoltampereReactiveHour => baseUnitValue, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactivePower.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactivePower.g.cs new file mode 100644 index 0000000000..ea8a4ebba9 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricReactivePower.g.cs @@ -0,0 +1,196 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// In electric power transmission and distribution, volt-ampere reactive (var) is a unit of measurement of reactive power. Reactive power exists in an AC circuit when the current and voltage are not in phase. + /// + /// + /// https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state + /// + public struct ElectricReactivePower + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricReactivePowerUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricReactivePowerUnit 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 ElectricReactivePower(double value, ElectricReactivePowerUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricReactivePower, which is Second. All conversions go via this value. + /// + public static ElectricReactivePowerUnit BaseUnit { get; } = ElectricReactivePowerUnit.VoltampereReactive; + + /// + /// Represents the largest possible value of ElectricReactivePower. + /// + public static ElectricReactivePower MaxValue { get; } = new ElectricReactivePower(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricReactivePower. + /// + public static ElectricReactivePower MinValue { get; } = new ElectricReactivePower(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricReactivePower Zero { get; } = new ElectricReactivePower(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double GigavoltamperesReactive => As(ElectricReactivePowerUnit.GigavoltampereReactive); + + /// + /// Gets a value of this quantity converted into + /// + public double KilovoltamperesReactive => As(ElectricReactivePowerUnit.KilovoltampereReactive); + + /// + /// Gets a value of this quantity converted into + /// + public double MegavoltamperesReactive => As(ElectricReactivePowerUnit.MegavoltampereReactive); + + /// + /// Gets a value of this quantity converted into + /// + public double VoltamperesReactive => As(ElectricReactivePowerUnit.VoltampereReactive); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromGigavoltamperesReactive(double gigavoltamperesreactive) => new ElectricReactivePower(gigavoltamperesreactive, ElectricReactivePowerUnit.GigavoltampereReactive); + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromKilovoltamperesReactive(double kilovoltamperesreactive) => new ElectricReactivePower(kilovoltamperesreactive, ElectricReactivePowerUnit.KilovoltampereReactive); + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromMegavoltamperesReactive(double megavoltamperesreactive) => new ElectricReactivePower(megavoltamperesreactive, ElectricReactivePowerUnit.MegavoltampereReactive); + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromVoltamperesReactive(double voltamperesreactive) => new ElectricReactivePower(voltamperesreactive, ElectricReactivePowerUnit.VoltampereReactive); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricReactivePower unit value. + public static ElectricReactivePower From(double value, ElectricReactivePowerUnit fromUnit) + { + return new ElectricReactivePower(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricReactivePowerUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricReactivePower to another ElectricReactivePower with the unit representation . + /// + /// A ElectricReactivePower with the specified unit. + public ElectricReactivePower ToUnit(ElectricReactivePowerUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricReactivePower(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 + { + ElectricReactivePowerUnit.GigavoltampereReactive => (_value) * 1e9d, + ElectricReactivePowerUnit.KilovoltampereReactive => (_value) * 1e3d, + ElectricReactivePowerUnit.MegavoltampereReactive => (_value) * 1e6d, + ElectricReactivePowerUnit.VoltampereReactive => _value, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricReactivePowerUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricReactivePowerUnit.GigavoltampereReactive => (baseUnitValue) / 1e9d, + ElectricReactivePowerUnit.KilovoltampereReactive => (baseUnitValue) / 1e3d, + ElectricReactivePowerUnit.MegavoltampereReactive => (baseUnitValue) / 1e6d, + ElectricReactivePowerUnit.VoltampereReactive => baseUnitValue, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricResistance.g.cs index a58a374898..1a4badddc5 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -24,8 +24,11 @@ namespace UnitsNet { /// /// - /// The electrical resistance of an electrical conductor is the opposition to the passage of an electric current through that conductor. + /// The electrical resistance of an object is a measure of its opposition to the flow of electric current. Along with reactance, it is one of two elements of impedance. Its reciprocal quantity is electrical conductance. /// + /// + /// https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance + /// public struct ElectricResistance { /// @@ -103,6 +106,11 @@ public ElectricResistance(double value, ElectricResistanceUnit unit) /// public double Milliohms => As(ElectricResistanceUnit.Milliohm); + /// + /// Gets a value of this quantity converted into + /// + public double Nanoohms => As(ElectricResistanceUnit.Nanoohm); + /// /// Gets a value of this quantity converted into /// @@ -142,6 +150,11 @@ public ElectricResistance(double value, ElectricResistanceUnit unit) /// public static ElectricResistance FromMilliohms(double milliohms) => new ElectricResistance(milliohms, ElectricResistanceUnit.Milliohm); + /// + /// Creates a from . + /// + public static ElectricResistance FromNanoohms(double nanoohms) => new ElectricResistance(nanoohms, ElectricResistanceUnit.Nanoohm); + /// /// Creates a from . /// @@ -197,6 +210,7 @@ private double GetValueInBaseUnit() ElectricResistanceUnit.Megaohm => (_value) * 1e6d, ElectricResistanceUnit.Microohm => (_value) * 1e-6d, ElectricResistanceUnit.Milliohm => (_value) * 1e-3d, + ElectricResistanceUnit.Nanoohm => (_value) * 1e-9d, ElectricResistanceUnit.Ohm => _value, ElectricResistanceUnit.Teraohm => (_value) * 1e12d, _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") @@ -217,6 +231,7 @@ private double GetValueAs(ElectricResistanceUnit unit) ElectricResistanceUnit.Megaohm => (baseUnitValue) / 1e6d, ElectricResistanceUnit.Microohm => (baseUnitValue) / 1e-6d, ElectricResistanceUnit.Milliohm => (baseUnitValue) / 1e-3d, + ElectricResistanceUnit.Nanoohm => (baseUnitValue) / 1e-9d, ElectricResistanceUnit.Ohm => baseUnitValue, ElectricResistanceUnit.Teraohm => (baseUnitValue) / 1e12d, _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricSusceptance.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricSusceptance.g.cs new file mode 100644 index 0000000000..f891f370ed --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ElectricSusceptance.g.cs @@ -0,0 +1,340 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// Electrical susceptance is the imaginary part of admittance, where the real part is conductance. + /// + /// + /// https://en.wikipedia.org/wiki/Electrical_susceptance + /// + public struct ElectricSusceptance + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly ElectricSusceptanceUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public ElectricSusceptanceUnit 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 ElectricSusceptance(double value, ElectricSusceptanceUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of ElectricSusceptance, which is Second. All conversions go via this value. + /// + public static ElectricSusceptanceUnit BaseUnit { get; } = ElectricSusceptanceUnit.Siemens; + + /// + /// Represents the largest possible value of ElectricSusceptance. + /// + public static ElectricSusceptance MaxValue { get; } = new ElectricSusceptance(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of ElectricSusceptance. + /// + public static ElectricSusceptance MinValue { get; } = new ElectricSusceptance(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static ElectricSusceptance Zero { get; } = new ElectricSusceptance(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigamhos => As(ElectricSusceptanceUnit.Gigamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Gigasiemens => As(ElectricSusceptanceUnit.Gigasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilomhos => As(ElectricSusceptanceUnit.Kilomho); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilosiemens => As(ElectricSusceptanceUnit.Kilosiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Megamhos => As(ElectricSusceptanceUnit.Megamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Megasiemens => As(ElectricSusceptanceUnit.Megasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Mhos => As(ElectricSusceptanceUnit.Mho); + + /// + /// Gets a value of this quantity converted into + /// + public double Micromhos => As(ElectricSusceptanceUnit.Micromho); + + /// + /// Gets a value of this quantity converted into + /// + public double Microsiemens => As(ElectricSusceptanceUnit.Microsiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Millimhos => As(ElectricSusceptanceUnit.Millimho); + + /// + /// Gets a value of this quantity converted into + /// + public double Millisiemens => As(ElectricSusceptanceUnit.Millisiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanomhos => As(ElectricSusceptanceUnit.Nanomho); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanosiemens => As(ElectricSusceptanceUnit.Nanosiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Siemens => As(ElectricSusceptanceUnit.Siemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Teramhos => As(ElectricSusceptanceUnit.Teramho); + + /// + /// Gets a value of this quantity converted into + /// + public double Terasiemens => As(ElectricSusceptanceUnit.Terasiemens); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromGigamhos(double gigamhos) => new ElectricSusceptance(gigamhos, ElectricSusceptanceUnit.Gigamho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromGigasiemens(double gigasiemens) => new ElectricSusceptance(gigasiemens, ElectricSusceptanceUnit.Gigasiemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromKilomhos(double kilomhos) => new ElectricSusceptance(kilomhos, ElectricSusceptanceUnit.Kilomho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromKilosiemens(double kilosiemens) => new ElectricSusceptance(kilosiemens, ElectricSusceptanceUnit.Kilosiemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMegamhos(double megamhos) => new ElectricSusceptance(megamhos, ElectricSusceptanceUnit.Megamho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMegasiemens(double megasiemens) => new ElectricSusceptance(megasiemens, ElectricSusceptanceUnit.Megasiemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMhos(double mhos) => new ElectricSusceptance(mhos, ElectricSusceptanceUnit.Mho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMicromhos(double micromhos) => new ElectricSusceptance(micromhos, ElectricSusceptanceUnit.Micromho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMicrosiemens(double microsiemens) => new ElectricSusceptance(microsiemens, ElectricSusceptanceUnit.Microsiemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMillimhos(double millimhos) => new ElectricSusceptance(millimhos, ElectricSusceptanceUnit.Millimho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMillisiemens(double millisiemens) => new ElectricSusceptance(millisiemens, ElectricSusceptanceUnit.Millisiemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromNanomhos(double nanomhos) => new ElectricSusceptance(nanomhos, ElectricSusceptanceUnit.Nanomho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromNanosiemens(double nanosiemens) => new ElectricSusceptance(nanosiemens, ElectricSusceptanceUnit.Nanosiemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromSiemens(double siemens) => new ElectricSusceptance(siemens, ElectricSusceptanceUnit.Siemens); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromTeramhos(double teramhos) => new ElectricSusceptance(teramhos, ElectricSusceptanceUnit.Teramho); + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromTerasiemens(double terasiemens) => new ElectricSusceptance(terasiemens, ElectricSusceptanceUnit.Terasiemens); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricSusceptance unit value. + public static ElectricSusceptance From(double value, ElectricSusceptanceUnit fromUnit) + { + return new ElectricSusceptance(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(ElectricSusceptanceUnit unit) => GetValueAs(unit); + + /// + /// Converts this ElectricSusceptance to another ElectricSusceptance with the unit representation . + /// + /// A ElectricSusceptance with the specified unit. + public ElectricSusceptance ToUnit(ElectricSusceptanceUnit unit) + { + var convertedValue = GetValueAs(unit); + return new ElectricSusceptance(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 + { + ElectricSusceptanceUnit.Gigamho => (_value) * 1e9d, + ElectricSusceptanceUnit.Gigasiemens => (_value) * 1e9d, + ElectricSusceptanceUnit.Kilomho => (_value) * 1e3d, + ElectricSusceptanceUnit.Kilosiemens => (_value) * 1e3d, + ElectricSusceptanceUnit.Megamho => (_value) * 1e6d, + ElectricSusceptanceUnit.Megasiemens => (_value) * 1e6d, + ElectricSusceptanceUnit.Mho => _value, + ElectricSusceptanceUnit.Micromho => (_value) * 1e-6d, + ElectricSusceptanceUnit.Microsiemens => (_value) * 1e-6d, + ElectricSusceptanceUnit.Millimho => (_value) * 1e-3d, + ElectricSusceptanceUnit.Millisiemens => (_value) * 1e-3d, + ElectricSusceptanceUnit.Nanomho => (_value) * 1e-9d, + ElectricSusceptanceUnit.Nanosiemens => (_value) * 1e-9d, + ElectricSusceptanceUnit.Siemens => _value, + ElectricSusceptanceUnit.Teramho => (_value) * 1e12d, + ElectricSusceptanceUnit.Terasiemens => (_value) * 1e12d, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(ElectricSusceptanceUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + ElectricSusceptanceUnit.Gigamho => (baseUnitValue) / 1e9d, + ElectricSusceptanceUnit.Gigasiemens => (baseUnitValue) / 1e9d, + ElectricSusceptanceUnit.Kilomho => (baseUnitValue) / 1e3d, + ElectricSusceptanceUnit.Kilosiemens => (baseUnitValue) / 1e3d, + ElectricSusceptanceUnit.Megamho => (baseUnitValue) / 1e6d, + ElectricSusceptanceUnit.Megasiemens => (baseUnitValue) / 1e6d, + ElectricSusceptanceUnit.Mho => baseUnitValue, + ElectricSusceptanceUnit.Micromho => (baseUnitValue) / 1e-6d, + ElectricSusceptanceUnit.Microsiemens => (baseUnitValue) / 1e-6d, + ElectricSusceptanceUnit.Millimho => (baseUnitValue) / 1e-3d, + ElectricSusceptanceUnit.Millisiemens => (baseUnitValue) / 1e-3d, + ElectricSusceptanceUnit.Nanomho => (baseUnitValue) / 1e-9d, + ElectricSusceptanceUnit.Nanosiemens => (baseUnitValue) / 1e-9d, + ElectricSusceptanceUnit.Siemens => baseUnitValue, + ElectricSusceptanceUnit.Teramho => (baseUnitValue) / 1e12d, + ElectricSusceptanceUnit.Terasiemens => (baseUnitValue) / 1e12d, + _ => 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 index e9d83b176c..efcb6f03f4 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactiveEnergy.g.cs @@ -26,6 +26,10 @@ namespace UnitsNet /// /// The Volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour. /// + /// + /// has been renamed to , 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs index b07759ab78..e8ea54dea7 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/ReactivePower.g.cs @@ -26,6 +26,10 @@ 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. /// + /// + /// has been renamed to , 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 { /// diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs index 622b45de43..1e5e7c9a0b 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs @@ -25,10 +25,22 @@ namespace UnitsNet.Units public enum ElectricAdmittanceUnit { + Gigamho = 7, + Gigasiemens = 14, + Kilomho = 11, + Kilosiemens = 9, + Megamho = 8, + Megasiemens = 6, + Mho = 13, + Micromho = 5, Microsiemens = 1, + Millimho = 10, Millisiemens = 2, + Nanomho = 12, Nanosiemens = 3, Siemens = 4, + Teramho = 19, + Terasiemens = 16, } #pragma warning restore 1591 diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricApparentEnergyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricApparentEnergyUnit.g.cs new file mode 100644 index 0000000000..f46ab5ea10 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricApparentEnergyUnit.g.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricApparentEnergyUnit + { + KilovoltampereHour = 1, + MegavoltampereHour = 2, + VoltampereHour = 3, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricApparentPowerUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricApparentPowerUnit.g.cs new file mode 100644 index 0000000000..71b500b242 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricApparentPowerUnit.g.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricApparentPowerUnit + { + Gigavoltampere = 9, + Kilovoltampere = 3, + Megavoltampere = 8, + Microvoltampere = 5, + Millivoltampere = 7, + Voltampere = 1, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricCapacitanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricCapacitanceUnit.g.cs new file mode 100644 index 0000000000..b3b88398f2 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricCapacitanceUnit.g.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCapacitanceUnit + { + Farad = 5, + Kilofarad = 7, + Megafarad = 4, + Microfarad = 6, + Millifarad = 10, + Nanofarad = 9, + Picofarad = 8, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricConductanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricConductanceUnit.g.cs index f2003b8384..da5b831bde 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricConductanceUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricConductanceUnit.g.cs @@ -25,11 +25,22 @@ namespace UnitsNet.Units public enum ElectricConductanceUnit { + Gigamho = 15, + Gigasiemens = 5, + Kilomho = 7, Kilosiemens = 6, + Megamho = 13, + Megasiemens = 12, + Mho = 9, + Micromho = 11, Microsiemens = 1, + Millimho = 8, Millisiemens = 2, + Nanomho = 4, Nanosiemens = 10, Siemens = 3, + Teramho = 14, + Terasiemens = 17, } #pragma warning restore 1591 diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricImpedanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricImpedanceUnit.g.cs new file mode 100644 index 0000000000..61c6ece8b8 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricImpedanceUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricImpedanceUnit + { + Gigaohm = 10, + Kiloohm = 6, + Megaohm = 7, + Microohm = 2, + Milliohm = 1, + Nanoohm = 4, + Ohm = 9, + Teraohm = 8, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactanceUnit.g.cs new file mode 100644 index 0000000000..fc88bedac4 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactanceUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricReactanceUnit + { + Gigaohm = 3, + Kiloohm = 8, + Megaohm = 10, + Microohm = 7, + Milliohm = 4, + Nanoohm = 2, + Ohm = 1, + Teraohm = 5, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactiveEnergyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactiveEnergyUnit.g.cs new file mode 100644 index 0000000000..92cc518be5 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactiveEnergyUnit.g.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricReactiveEnergyUnit + { + KilovoltampereReactiveHour = 9, + MegavoltampereReactiveHour = 7, + VoltampereReactiveHour = 6, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactivePowerUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactivePowerUnit.g.cs new file mode 100644 index 0000000000..5f9c0a59e3 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricReactivePowerUnit.g.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricReactivePowerUnit + { + GigavoltampereReactive = 3, + KilovoltampereReactive = 8, + MegavoltampereReactive = 5, + VoltampereReactive = 2, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricResistanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricResistanceUnit.g.cs index 452a17522a..8a17f875f7 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricResistanceUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricResistanceUnit.g.cs @@ -30,6 +30,7 @@ public enum ElectricResistanceUnit Megaohm = 3, Microohm = 4, Milliohm = 5, + Nanoohm = 14, Ohm = 6, Teraohm = 12, } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricSusceptanceUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricSusceptanceUnit.g.cs new file mode 100644 index 0000000000..b657aec9ce --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/ElectricSusceptanceUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\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 ElectricSusceptanceUnit + { + Gigamho = 4, + Gigasiemens = 5, + Kilomho = 8, + Kilosiemens = 9, + Megamho = 10, + Megasiemens = 6, + Mho = 2, + Micromho = 3, + Microsiemens = 1, + Millimho = 7, + Millisiemens = 16, + Nanomho = 13, + Nanosiemens = 20, + Siemens = 15, + Teramho = 18, + Terasiemens = 17, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index 1f78a3bc57..5155751a64 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -40,6 +40,12 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "DynamicViscosity", "Dynamic EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricAdmittance", "ElectricAdmittance\ElectricAdmittance.nfproj", "{2ee55c63-d077-25dd-f076-857adfe08080}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricApparentEnergy", "ElectricApparentEnergy\ElectricApparentEnergy.nfproj", "{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}" +EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricApparentPower", "ElectricApparentPower\ElectricApparentPower.nfproj", "{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}" +EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricCapacitance", "ElectricCapacitance\ElectricCapacitance.nfproj", "{10e8cf6b-7fec-911f-770d-e3641296ac89}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricCharge", "ElectricCharge\ElectricCharge.nfproj", "{f4286cfc-484b-8466-8efa-1111696babb9}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricChargeDensity", "ElectricChargeDensity\ElectricChargeDensity.nfproj", "{b1567c85-ad77-c283-9165-777ad0e9a2eb}" @@ -56,6 +62,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricCurrentGradient", " EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricField", "ElectricField\ElectricField.nfproj", "{635581a6-f954-d0e4-9c68-02c1725e49d2}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricImpedance", "ElectricImpedance\ElectricImpedance.nfproj", "{23a79010-5c1a-9120-0992-a69c8dd80015}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricInductance", "ElectricInductance\ElectricInductance.nfproj", "{76bf8a97-e573-a5b5-286f-04ca7e00f8e9}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricPotential", "ElectricPotential\ElectricPotential.nfproj", "{66c94dc2-e546-9737-a45b-4bc60fe0e536}" @@ -66,12 +74,20 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricPotentialChangeRate 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}" +EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricReactivePower", "ElectricReactivePower\ElectricReactivePower.nfproj", "{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricResistance", "ElectricResistance\ElectricResistance.nfproj", "{78d59e90-3339-54d6-3803-f68623b72eff}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricResistivity", "ElectricResistivity\ElectricResistivity.nfproj", "{6a4a0f45-c2b4-6be4-e44a-e78d3282359f}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricSurfaceChargeDensity", "ElectricSurfaceChargeDensity\ElectricSurfaceChargeDensity.nfproj", "{006e161d-aae1-2dd1-5b94-ebd45d31f50a}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "ElectricSusceptance", "ElectricSusceptance\ElectricSusceptance.nfproj", "{544c006b-f7de-21a9-a1b4-8df710e184c8}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Energy", "Energy\Energy.nfproj", "{f7d3fcf2-cadc-19dd-4c4c-5a54a5102c95}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "EnergyDensity", "EnergyDensity\EnergyDensity.nfproj", "{c5025916-5039-97c2-b450-af1420f5fb08}" @@ -368,6 +384,24 @@ Global {2ee55c63-d077-25dd-f076-857adfe08080}.Release|Any CPU.ActiveCfg = Release|Any CPU {2ee55c63-d077-25dd-f076-857adfe08080}.Release|Any CPU.Build.0 = Release|Any CPU {2ee55c63-d077-25dd-f076-857adfe08080}.Release|Any CPU.Deploy.0 = Release|Any CPU +{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}.Debug|Any CPU.Build.0 = Debug|Any CPU +{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}.Release|Any CPU.ActiveCfg = Release|Any CPU +{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}.Release|Any CPU.Build.0 = Release|Any CPU +{f22b7bcc-5a8d-3a02-d81c-caf6c9c44d61}.Release|Any CPU.Deploy.0 = Release|Any CPU +{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}.Debug|Any CPU.Build.0 = Debug|Any CPU +{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}.Release|Any CPU.ActiveCfg = Release|Any CPU +{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}.Release|Any CPU.Build.0 = Release|Any CPU +{b7a9eb2a-4b0e-548c-2370-a33ee63b21cc}.Release|Any CPU.Deploy.0 = Release|Any CPU +{10e8cf6b-7fec-911f-770d-e3641296ac89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{10e8cf6b-7fec-911f-770d-e3641296ac89}.Debug|Any CPU.Build.0 = Debug|Any CPU +{10e8cf6b-7fec-911f-770d-e3641296ac89}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{10e8cf6b-7fec-911f-770d-e3641296ac89}.Release|Any CPU.ActiveCfg = Release|Any CPU +{10e8cf6b-7fec-911f-770d-e3641296ac89}.Release|Any CPU.Build.0 = Release|Any CPU +{10e8cf6b-7fec-911f-770d-e3641296ac89}.Release|Any CPU.Deploy.0 = Release|Any CPU {f4286cfc-484b-8466-8efa-1111696babb9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {f4286cfc-484b-8466-8efa-1111696babb9}.Debug|Any CPU.Build.0 = Debug|Any CPU {f4286cfc-484b-8466-8efa-1111696babb9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -416,6 +450,12 @@ Global {635581a6-f954-d0e4-9c68-02c1725e49d2}.Release|Any CPU.ActiveCfg = Release|Any CPU {635581a6-f954-d0e4-9c68-02c1725e49d2}.Release|Any CPU.Build.0 = Release|Any CPU {635581a6-f954-d0e4-9c68-02c1725e49d2}.Release|Any CPU.Deploy.0 = Release|Any CPU +{23a79010-5c1a-9120-0992-a69c8dd80015}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{23a79010-5c1a-9120-0992-a69c8dd80015}.Debug|Any CPU.Build.0 = Debug|Any CPU +{23a79010-5c1a-9120-0992-a69c8dd80015}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{23a79010-5c1a-9120-0992-a69c8dd80015}.Release|Any CPU.ActiveCfg = Release|Any CPU +{23a79010-5c1a-9120-0992-a69c8dd80015}.Release|Any CPU.Build.0 = Release|Any CPU +{23a79010-5c1a-9120-0992-a69c8dd80015}.Release|Any CPU.Deploy.0 = Release|Any CPU {76bf8a97-e573-a5b5-286f-04ca7e00f8e9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {76bf8a97-e573-a5b5-286f-04ca7e00f8e9}.Debug|Any CPU.Build.0 = Debug|Any CPU {76bf8a97-e573-a5b5-286f-04ca7e00f8e9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -446,6 +486,24 @@ Global {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 +{e3d3c1e3-aaa3-5d40-472e-ae837457cf73}.Release|Any CPU.ActiveCfg = Release|Any CPU +{e3d3c1e3-aaa3-5d40-472e-ae837457cf73}.Release|Any CPU.Build.0 = Release|Any CPU +{e3d3c1e3-aaa3-5d40-472e-ae837457cf73}.Release|Any CPU.Deploy.0 = Release|Any CPU +{9f892c4e-26c2-1420-a73c-08138c8f6ca2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{9f892c4e-26c2-1420-a73c-08138c8f6ca2}.Debug|Any CPU.Build.0 = Debug|Any CPU +{9f892c4e-26c2-1420-a73c-08138c8f6ca2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{9f892c4e-26c2-1420-a73c-08138c8f6ca2}.Release|Any CPU.ActiveCfg = Release|Any CPU +{9f892c4e-26c2-1420-a73c-08138c8f6ca2}.Release|Any CPU.Build.0 = Release|Any CPU +{9f892c4e-26c2-1420-a73c-08138c8f6ca2}.Release|Any CPU.Deploy.0 = Release|Any CPU +{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}.Debug|Any CPU.Build.0 = Debug|Any CPU +{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}.Release|Any CPU.ActiveCfg = Release|Any CPU +{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}.Release|Any CPU.Build.0 = Release|Any CPU +{6e5b2ba2-7712-0f4f-d2bf-2624bb877dbe}.Release|Any CPU.Deploy.0 = Release|Any CPU {78d59e90-3339-54d6-3803-f68623b72eff}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {78d59e90-3339-54d6-3803-f68623b72eff}.Debug|Any CPU.Build.0 = Debug|Any CPU {78d59e90-3339-54d6-3803-f68623b72eff}.Debug|Any CPU.Deploy.0 = Debug|Any CPU @@ -464,6 +522,12 @@ Global {006e161d-aae1-2dd1-5b94-ebd45d31f50a}.Release|Any CPU.ActiveCfg = Release|Any CPU {006e161d-aae1-2dd1-5b94-ebd45d31f50a}.Release|Any CPU.Build.0 = Release|Any CPU {006e161d-aae1-2dd1-5b94-ebd45d31f50a}.Release|Any CPU.Deploy.0 = Release|Any CPU +{544c006b-f7de-21a9-a1b4-8df710e184c8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{544c006b-f7de-21a9-a1b4-8df710e184c8}.Debug|Any CPU.Build.0 = Debug|Any CPU +{544c006b-f7de-21a9-a1b4-8df710e184c8}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{544c006b-f7de-21a9-a1b4-8df710e184c8}.Release|Any CPU.ActiveCfg = Release|Any CPU +{544c006b-f7de-21a9-a1b4-8df710e184c8}.Release|Any CPU.Build.0 = Release|Any CPU +{544c006b-f7de-21a9-a1b4-8df710e184c8}.Release|Any CPU.Deploy.0 = Release|Any CPU {f7d3fcf2-cadc-19dd-4c4c-5a54a5102c95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {f7d3fcf2-cadc-19dd-4c4c-5a54a5102c95}.Debug|Any CPU.Build.0 = Debug|Any CPU {f7d3fcf2-cadc-19dd-4c4c-5a54a5102c95}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricAdmittanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricAdmittanceExtensionsTest.g.cs index 6cb2e25259..a27e4d458d 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricAdmittanceExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricAdmittanceExtensionsTest.g.cs @@ -24,14 +24,54 @@ namespace UnitsNet.Tests { public class NumberToElectricAdmittanceExtensionsTests { + [Fact] + public void NumberToGigamhosTest() => + Assert.Equal(ElectricAdmittance.FromGigamhos(2), 2.Gigamhos()); + + [Fact] + public void NumberToGigasiemensTest() => + Assert.Equal(ElectricAdmittance.FromGigasiemens(2), 2.Gigasiemens()); + + [Fact] + public void NumberToKilomhosTest() => + Assert.Equal(ElectricAdmittance.FromKilomhos(2), 2.Kilomhos()); + + [Fact] + public void NumberToKilosiemensTest() => + Assert.Equal(ElectricAdmittance.FromKilosiemens(2), 2.Kilosiemens()); + + [Fact] + public void NumberToMegamhosTest() => + Assert.Equal(ElectricAdmittance.FromMegamhos(2), 2.Megamhos()); + + [Fact] + public void NumberToMegasiemensTest() => + Assert.Equal(ElectricAdmittance.FromMegasiemens(2), 2.Megasiemens()); + + [Fact] + public void NumberToMhosTest() => + Assert.Equal(ElectricAdmittance.FromMhos(2), 2.Mhos()); + + [Fact] + public void NumberToMicromhosTest() => + Assert.Equal(ElectricAdmittance.FromMicromhos(2), 2.Micromhos()); + [Fact] public void NumberToMicrosiemensTest() => Assert.Equal(ElectricAdmittance.FromMicrosiemens(2), 2.Microsiemens()); + [Fact] + public void NumberToMillimhosTest() => + Assert.Equal(ElectricAdmittance.FromMillimhos(2), 2.Millimhos()); + [Fact] public void NumberToMillisiemensTest() => Assert.Equal(ElectricAdmittance.FromMillisiemens(2), 2.Millisiemens()); + [Fact] + public void NumberToNanomhosTest() => + Assert.Equal(ElectricAdmittance.FromNanomhos(2), 2.Nanomhos()); + [Fact] public void NumberToNanosiemensTest() => Assert.Equal(ElectricAdmittance.FromNanosiemens(2), 2.Nanosiemens()); @@ -40,5 +80,13 @@ public void NumberToNanosiemensTest() => public void NumberToSiemensTest() => Assert.Equal(ElectricAdmittance.FromSiemens(2), 2.Siemens()); + [Fact] + public void NumberToTeramhosTest() => + Assert.Equal(ElectricAdmittance.FromTeramhos(2), 2.Teramhos()); + + [Fact] + public void NumberToTerasiemensTest() => + Assert.Equal(ElectricAdmittance.FromTerasiemens(2), 2.Terasiemens()); + } } diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricApparentEnergyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricApparentEnergyExtensionsTest.g.cs new file mode 100644 index 0000000000..af5bc914b7 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricApparentEnergyExtensionsTest.g.cs @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricApparentEnergy; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricApparentEnergyExtensionsTests + { + [Fact] + public void NumberToKilovoltampereHoursTest() => + Assert.Equal(ElectricApparentEnergy.FromKilovoltampereHours(2), 2.KilovoltampereHours()); + + [Fact] + public void NumberToMegavoltampereHoursTest() => + Assert.Equal(ElectricApparentEnergy.FromMegavoltampereHours(2), 2.MegavoltampereHours()); + + [Fact] + public void NumberToVoltampereHoursTest() => + Assert.Equal(ElectricApparentEnergy.FromVoltampereHours(2), 2.VoltampereHours()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricApparentPowerExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricApparentPowerExtensionsTest.g.cs new file mode 100644 index 0000000000..8d6d76eda6 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricApparentPowerExtensionsTest.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricApparentPower; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricApparentPowerExtensionsTests + { + [Fact] + public void NumberToGigavoltamperesTest() => + Assert.Equal(ElectricApparentPower.FromGigavoltamperes(2), 2.Gigavoltamperes()); + + [Fact] + public void NumberToKilovoltamperesTest() => + Assert.Equal(ElectricApparentPower.FromKilovoltamperes(2), 2.Kilovoltamperes()); + + [Fact] + public void NumberToMegavoltamperesTest() => + Assert.Equal(ElectricApparentPower.FromMegavoltamperes(2), 2.Megavoltamperes()); + + [Fact] + public void NumberToMicrovoltamperesTest() => + Assert.Equal(ElectricApparentPower.FromMicrovoltamperes(2), 2.Microvoltamperes()); + + [Fact] + public void NumberToMillivoltamperesTest() => + Assert.Equal(ElectricApparentPower.FromMillivoltamperes(2), 2.Millivoltamperes()); + + [Fact] + public void NumberToVoltamperesTest() => + Assert.Equal(ElectricApparentPower.FromVoltamperes(2), 2.Voltamperes()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricCapacitanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricCapacitanceExtensionsTest.g.cs new file mode 100644 index 0000000000..f5690a30a7 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricCapacitanceExtensionsTest.g.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricCapacitance; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricCapacitanceExtensionsTests + { + [Fact] + public void NumberToFaradsTest() => + Assert.Equal(ElectricCapacitance.FromFarads(2), 2.Farads()); + + [Fact] + public void NumberToKilofaradsTest() => + Assert.Equal(ElectricCapacitance.FromKilofarads(2), 2.Kilofarads()); + + [Fact] + public void NumberToMegafaradsTest() => + Assert.Equal(ElectricCapacitance.FromMegafarads(2), 2.Megafarads()); + + [Fact] + public void NumberToMicrofaradsTest() => + Assert.Equal(ElectricCapacitance.FromMicrofarads(2), 2.Microfarads()); + + [Fact] + public void NumberToMillifaradsTest() => + Assert.Equal(ElectricCapacitance.FromMillifarads(2), 2.Millifarads()); + + [Fact] + public void NumberToNanofaradsTest() => + Assert.Equal(ElectricCapacitance.FromNanofarads(2), 2.Nanofarads()); + + [Fact] + public void NumberToPicofaradsTest() => + Assert.Equal(ElectricCapacitance.FromPicofarads(2), 2.Picofarads()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricConductanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricConductanceExtensionsTest.g.cs index 354f79c390..d4c9cab72d 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricConductanceExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricConductanceExtensionsTest.g.cs @@ -24,18 +24,54 @@ namespace UnitsNet.Tests { public class NumberToElectricConductanceExtensionsTests { + [Fact] + public void NumberToGigamhosTest() => + Assert.Equal(ElectricConductance.FromGigamhos(2), 2.Gigamhos()); + + [Fact] + public void NumberToGigasiemensTest() => + Assert.Equal(ElectricConductance.FromGigasiemens(2), 2.Gigasiemens()); + + [Fact] + public void NumberToKilomhosTest() => + Assert.Equal(ElectricConductance.FromKilomhos(2), 2.Kilomhos()); + [Fact] public void NumberToKilosiemensTest() => Assert.Equal(ElectricConductance.FromKilosiemens(2), 2.Kilosiemens()); + [Fact] + public void NumberToMegamhosTest() => + Assert.Equal(ElectricConductance.FromMegamhos(2), 2.Megamhos()); + + [Fact] + public void NumberToMegasiemensTest() => + Assert.Equal(ElectricConductance.FromMegasiemens(2), 2.Megasiemens()); + + [Fact] + public void NumberToMhosTest() => + Assert.Equal(ElectricConductance.FromMhos(2), 2.Mhos()); + + [Fact] + public void NumberToMicromhosTest() => + Assert.Equal(ElectricConductance.FromMicromhos(2), 2.Micromhos()); + [Fact] public void NumberToMicrosiemensTest() => Assert.Equal(ElectricConductance.FromMicrosiemens(2), 2.Microsiemens()); + [Fact] + public void NumberToMillimhosTest() => + Assert.Equal(ElectricConductance.FromMillimhos(2), 2.Millimhos()); + [Fact] public void NumberToMillisiemensTest() => Assert.Equal(ElectricConductance.FromMillisiemens(2), 2.Millisiemens()); + [Fact] + public void NumberToNanomhosTest() => + Assert.Equal(ElectricConductance.FromNanomhos(2), 2.Nanomhos()); + [Fact] public void NumberToNanosiemensTest() => Assert.Equal(ElectricConductance.FromNanosiemens(2), 2.Nanosiemens()); @@ -44,5 +80,13 @@ public void NumberToNanosiemensTest() => public void NumberToSiemensTest() => Assert.Equal(ElectricConductance.FromSiemens(2), 2.Siemens()); + [Fact] + public void NumberToTeramhosTest() => + Assert.Equal(ElectricConductance.FromTeramhos(2), 2.Teramhos()); + + [Fact] + public void NumberToTerasiemensTest() => + Assert.Equal(ElectricConductance.FromTerasiemens(2), 2.Terasiemens()); + } } diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricImpedanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricImpedanceExtensionsTest.g.cs new file mode 100644 index 0000000000..3357beee27 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricImpedanceExtensionsTest.g.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricImpedance; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricImpedanceExtensionsTests + { + [Fact] + public void NumberToGigaohmsTest() => + Assert.Equal(ElectricImpedance.FromGigaohms(2), 2.Gigaohms()); + + [Fact] + public void NumberToKiloohmsTest() => + Assert.Equal(ElectricImpedance.FromKiloohms(2), 2.Kiloohms()); + + [Fact] + public void NumberToMegaohmsTest() => + Assert.Equal(ElectricImpedance.FromMegaohms(2), 2.Megaohms()); + + [Fact] + public void NumberToMicroohmsTest() => + Assert.Equal(ElectricImpedance.FromMicroohms(2), 2.Microohms()); + + [Fact] + public void NumberToMilliohmsTest() => + Assert.Equal(ElectricImpedance.FromMilliohms(2), 2.Milliohms()); + + [Fact] + public void NumberToNanoohmsTest() => + Assert.Equal(ElectricImpedance.FromNanoohms(2), 2.Nanoohms()); + + [Fact] + public void NumberToOhmsTest() => + Assert.Equal(ElectricImpedance.FromOhms(2), 2.Ohms()); + + [Fact] + public void NumberToTeraohmsTest() => + Assert.Equal(ElectricImpedance.FromTeraohms(2), 2.Teraohms()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactanceExtensionsTest.g.cs new file mode 100644 index 0000000000..58574611f9 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactanceExtensionsTest.g.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricReactance; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricReactanceExtensionsTests + { + [Fact] + public void NumberToGigaohmsTest() => + Assert.Equal(ElectricReactance.FromGigaohms(2), 2.Gigaohms()); + + [Fact] + public void NumberToKiloohmsTest() => + Assert.Equal(ElectricReactance.FromKiloohms(2), 2.Kiloohms()); + + [Fact] + public void NumberToMegaohmsTest() => + Assert.Equal(ElectricReactance.FromMegaohms(2), 2.Megaohms()); + + [Fact] + public void NumberToMicroohmsTest() => + Assert.Equal(ElectricReactance.FromMicroohms(2), 2.Microohms()); + + [Fact] + public void NumberToMilliohmsTest() => + Assert.Equal(ElectricReactance.FromMilliohms(2), 2.Milliohms()); + + [Fact] + public void NumberToNanoohmsTest() => + Assert.Equal(ElectricReactance.FromNanoohms(2), 2.Nanoohms()); + + [Fact] + public void NumberToOhmsTest() => + Assert.Equal(ElectricReactance.FromOhms(2), 2.Ohms()); + + [Fact] + public void NumberToTeraohmsTest() => + Assert.Equal(ElectricReactance.FromTeraohms(2), 2.Teraohms()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactiveEnergyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactiveEnergyExtensionsTest.g.cs new file mode 100644 index 0000000000..0786448426 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactiveEnergyExtensionsTest.g.cs @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricReactiveEnergy; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricReactiveEnergyExtensionsTests + { + [Fact] + public void NumberToKilovoltampereReactiveHoursTest() => + Assert.Equal(ElectricReactiveEnergy.FromKilovoltampereReactiveHours(2), 2.KilovoltampereReactiveHours()); + + [Fact] + public void NumberToMegavoltampereReactiveHoursTest() => + Assert.Equal(ElectricReactiveEnergy.FromMegavoltampereReactiveHours(2), 2.MegavoltampereReactiveHours()); + + [Fact] + public void NumberToVoltampereReactiveHoursTest() => + Assert.Equal(ElectricReactiveEnergy.FromVoltampereReactiveHours(2), 2.VoltampereReactiveHours()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactivePowerExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactivePowerExtensionsTest.g.cs new file mode 100644 index 0000000000..56f6858b80 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricReactivePowerExtensionsTest.g.cs @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricReactivePower; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricReactivePowerExtensionsTests + { + [Fact] + public void NumberToGigavoltamperesReactiveTest() => + Assert.Equal(ElectricReactivePower.FromGigavoltamperesReactive(2), 2.GigavoltamperesReactive()); + + [Fact] + public void NumberToKilovoltamperesReactiveTest() => + Assert.Equal(ElectricReactivePower.FromKilovoltamperesReactive(2), 2.KilovoltamperesReactive()); + + [Fact] + public void NumberToMegavoltamperesReactiveTest() => + Assert.Equal(ElectricReactivePower.FromMegavoltamperesReactive(2), 2.MegavoltamperesReactive()); + + [Fact] + public void NumberToVoltamperesReactiveTest() => + Assert.Equal(ElectricReactivePower.FromVoltamperesReactive(2), 2.VoltamperesReactive()); + + } +} diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricResistanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricResistanceExtensionsTest.g.cs index 68121545a5..5d841d768f 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricResistanceExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricResistanceExtensionsTest.g.cs @@ -44,6 +44,10 @@ public void NumberToMicroohmsTest() => public void NumberToMilliohmsTest() => Assert.Equal(ElectricResistance.FromMilliohms(2), 2.Milliohms()); + [Fact] + public void NumberToNanoohmsTest() => + Assert.Equal(ElectricResistance.FromNanoohms(2), 2.Nanoohms()); + [Fact] public void NumberToOhmsTest() => Assert.Equal(ElectricResistance.FromOhms(2), 2.Ohms()); diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricSusceptanceExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricSusceptanceExtensionsTest.g.cs new file mode 100644 index 0000000000..53be089919 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToElectricSusceptanceExtensionsTest.g.cs @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricSusceptance; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToElectricSusceptanceExtensionsTests + { + [Fact] + public void NumberToGigamhosTest() => + Assert.Equal(ElectricSusceptance.FromGigamhos(2), 2.Gigamhos()); + + [Fact] + public void NumberToGigasiemensTest() => + Assert.Equal(ElectricSusceptance.FromGigasiemens(2), 2.Gigasiemens()); + + [Fact] + public void NumberToKilomhosTest() => + Assert.Equal(ElectricSusceptance.FromKilomhos(2), 2.Kilomhos()); + + [Fact] + public void NumberToKilosiemensTest() => + Assert.Equal(ElectricSusceptance.FromKilosiemens(2), 2.Kilosiemens()); + + [Fact] + public void NumberToMegamhosTest() => + Assert.Equal(ElectricSusceptance.FromMegamhos(2), 2.Megamhos()); + + [Fact] + public void NumberToMegasiemensTest() => + Assert.Equal(ElectricSusceptance.FromMegasiemens(2), 2.Megasiemens()); + + [Fact] + public void NumberToMhosTest() => + Assert.Equal(ElectricSusceptance.FromMhos(2), 2.Mhos()); + + [Fact] + public void NumberToMicromhosTest() => + Assert.Equal(ElectricSusceptance.FromMicromhos(2), 2.Micromhos()); + + [Fact] + public void NumberToMicrosiemensTest() => + Assert.Equal(ElectricSusceptance.FromMicrosiemens(2), 2.Microsiemens()); + + [Fact] + public void NumberToMillimhosTest() => + Assert.Equal(ElectricSusceptance.FromMillimhos(2), 2.Millimhos()); + + [Fact] + public void NumberToMillisiemensTest() => + Assert.Equal(ElectricSusceptance.FromMillisiemens(2), 2.Millisiemens()); + + [Fact] + public void NumberToNanomhosTest() => + Assert.Equal(ElectricSusceptance.FromNanomhos(2), 2.Nanomhos()); + + [Fact] + public void NumberToNanosiemensTest() => + Assert.Equal(ElectricSusceptance.FromNanosiemens(2), 2.Nanosiemens()); + + [Fact] + public void NumberToSiemensTest() => + Assert.Equal(ElectricSusceptance.FromSiemens(2), 2.Siemens()); + + [Fact] + public void NumberToTeramhosTest() => + Assert.Equal(ElectricSusceptance.FromTeramhos(2), 2.Teramhos()); + + [Fact] + public void NumberToTerasiemensTest() => + Assert.Equal(ElectricSusceptance.FromTerasiemens(2), 2.Terasiemens()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricAdmittanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricAdmittanceExtensions.g.cs index b02da0f9f6..dda9e36911 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricAdmittanceExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricAdmittanceExtensions.g.cs @@ -32,6 +32,70 @@ namespace UnitsNet.NumberExtensions.NumberToElectricAdmittance /// public static class NumberToElectricAdmittanceExtensions { + /// + public static ElectricAdmittance Gigamhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromGigamhos(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Gigasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromGigasiemens(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Kilomhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromKilomhos(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Kilosiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromKilosiemens(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Megamhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromMegamhos(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Megasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromMegasiemens(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Mhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromMhos(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Micromhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromMicromhos(Convert.ToDouble(value)); + /// public static ElectricAdmittance Microsiemens(this T value) where T : notnull @@ -40,6 +104,14 @@ public static ElectricAdmittance Microsiemens(this T value) #endif => ElectricAdmittance.FromMicrosiemens(Convert.ToDouble(value)); + /// + public static ElectricAdmittance Millimhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromMillimhos(Convert.ToDouble(value)); + /// public static ElectricAdmittance Millisiemens(this T value) where T : notnull @@ -48,6 +120,14 @@ public static ElectricAdmittance Millisiemens(this T value) #endif => ElectricAdmittance.FromMillisiemens(Convert.ToDouble(value)); + /// + public static ElectricAdmittance Nanomhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromNanomhos(Convert.ToDouble(value)); + /// public static ElectricAdmittance Nanosiemens(this T value) where T : notnull @@ -64,5 +144,21 @@ public static ElectricAdmittance Siemens(this T value) #endif => ElectricAdmittance.FromSiemens(Convert.ToDouble(value)); + /// + public static ElectricAdmittance Teramhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromTeramhos(Convert.ToDouble(value)); + + /// + public static ElectricAdmittance Terasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricAdmittance.FromTerasiemens(Convert.ToDouble(value)); + } } diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricApparentEnergyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricApparentEnergyExtensions.g.cs new file mode 100644 index 0000000000..5ca10ac415 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricApparentEnergyExtensions.g.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricApparentEnergy +{ + /// + /// A number to ElectricApparentEnergy Extensions + /// + public static class NumberToElectricApparentEnergyExtensions + { + /// + public static ElectricApparentEnergy KilovoltampereHours(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentEnergy.FromKilovoltampereHours(Convert.ToDouble(value)); + + /// + public static ElectricApparentEnergy MegavoltampereHours(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentEnergy.FromMegavoltampereHours(Convert.ToDouble(value)); + + /// + public static ElectricApparentEnergy VoltampereHours(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentEnergy.FromVoltampereHours(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricApparentPowerExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricApparentPowerExtensions.g.cs new file mode 100644 index 0000000000..e044644358 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricApparentPowerExtensions.g.cs @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricApparentPower +{ + /// + /// A number to ElectricApparentPower Extensions + /// + public static class NumberToElectricApparentPowerExtensions + { + /// + public static ElectricApparentPower Gigavoltamperes(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentPower.FromGigavoltamperes(Convert.ToDouble(value)); + + /// + public static ElectricApparentPower Kilovoltamperes(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentPower.FromKilovoltamperes(Convert.ToDouble(value)); + + /// + public static ElectricApparentPower Megavoltamperes(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentPower.FromMegavoltamperes(Convert.ToDouble(value)); + + /// + public static ElectricApparentPower Microvoltamperes(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentPower.FromMicrovoltamperes(Convert.ToDouble(value)); + + /// + public static ElectricApparentPower Millivoltamperes(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentPower.FromMillivoltamperes(Convert.ToDouble(value)); + + /// + public static ElectricApparentPower Voltamperes(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricApparentPower.FromVoltamperes(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricCapacitanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricCapacitanceExtensions.g.cs new file mode 100644 index 0000000000..fbb35fdb75 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricCapacitanceExtensions.g.cs @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricCapacitance +{ + /// + /// A number to ElectricCapacitance Extensions + /// + public static class NumberToElectricCapacitanceExtensions + { + /// + public static ElectricCapacitance Farads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromFarads(Convert.ToDouble(value)); + + /// + public static ElectricCapacitance Kilofarads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromKilofarads(Convert.ToDouble(value)); + + /// + public static ElectricCapacitance Megafarads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromMegafarads(Convert.ToDouble(value)); + + /// + public static ElectricCapacitance Microfarads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromMicrofarads(Convert.ToDouble(value)); + + /// + public static ElectricCapacitance Millifarads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromMillifarads(Convert.ToDouble(value)); + + /// + public static ElectricCapacitance Nanofarads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromNanofarads(Convert.ToDouble(value)); + + /// + public static ElectricCapacitance Picofarads(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricCapacitance.FromPicofarads(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricConductanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricConductanceExtensions.g.cs index d656b7462b..44bf79f2d8 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricConductanceExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricConductanceExtensions.g.cs @@ -32,6 +32,30 @@ namespace UnitsNet.NumberExtensions.NumberToElectricConductance /// public static class NumberToElectricConductanceExtensions { + /// + public static ElectricConductance Gigamhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromGigamhos(Convert.ToDouble(value)); + + /// + public static ElectricConductance Gigasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromGigasiemens(Convert.ToDouble(value)); + + /// + public static ElectricConductance Kilomhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromKilomhos(Convert.ToDouble(value)); + /// public static ElectricConductance Kilosiemens(this T value) where T : notnull @@ -40,6 +64,38 @@ public static ElectricConductance Kilosiemens(this T value) #endif => ElectricConductance.FromKilosiemens(Convert.ToDouble(value)); + /// + public static ElectricConductance Megamhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromMegamhos(Convert.ToDouble(value)); + + /// + public static ElectricConductance Megasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromMegasiemens(Convert.ToDouble(value)); + + /// + public static ElectricConductance Mhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromMhos(Convert.ToDouble(value)); + + /// + public static ElectricConductance Micromhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromMicromhos(Convert.ToDouble(value)); + /// public static ElectricConductance Microsiemens(this T value) where T : notnull @@ -48,6 +104,14 @@ public static ElectricConductance Microsiemens(this T value) #endif => ElectricConductance.FromMicrosiemens(Convert.ToDouble(value)); + /// + public static ElectricConductance Millimhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromMillimhos(Convert.ToDouble(value)); + /// public static ElectricConductance Millisiemens(this T value) where T : notnull @@ -56,6 +120,14 @@ public static ElectricConductance Millisiemens(this T value) #endif => ElectricConductance.FromMillisiemens(Convert.ToDouble(value)); + /// + public static ElectricConductance Nanomhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromNanomhos(Convert.ToDouble(value)); + /// public static ElectricConductance Nanosiemens(this T value) where T : notnull @@ -72,5 +144,21 @@ public static ElectricConductance Siemens(this T value) #endif => ElectricConductance.FromSiemens(Convert.ToDouble(value)); + /// + public static ElectricConductance Teramhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromTeramhos(Convert.ToDouble(value)); + + /// + public static ElectricConductance Terasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricConductance.FromTerasiemens(Convert.ToDouble(value)); + } } diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricImpedanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricImpedanceExtensions.g.cs new file mode 100644 index 0000000000..421dfe5b7d --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricImpedanceExtensions.g.cs @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricImpedance +{ + /// + /// A number to ElectricImpedance Extensions + /// + public static class NumberToElectricImpedanceExtensions + { + /// + public static ElectricImpedance Gigaohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromGigaohms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Kiloohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromKiloohms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Megaohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromMegaohms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Microohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromMicroohms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Milliohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromMilliohms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Nanoohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromNanoohms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Ohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromOhms(Convert.ToDouble(value)); + + /// + public static ElectricImpedance Teraohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricImpedance.FromTeraohms(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactanceExtensions.g.cs new file mode 100644 index 0000000000..8c0cb0cb64 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactanceExtensions.g.cs @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricReactance +{ + /// + /// A number to ElectricReactance Extensions + /// + public static class NumberToElectricReactanceExtensions + { + /// + public static ElectricReactance Gigaohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromGigaohms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Kiloohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromKiloohms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Megaohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromMegaohms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Microohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromMicroohms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Milliohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromMilliohms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Nanoohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromNanoohms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Ohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromOhms(Convert.ToDouble(value)); + + /// + public static ElectricReactance Teraohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactance.FromTeraohms(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactiveEnergyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactiveEnergyExtensions.g.cs new file mode 100644 index 0000000000..497204c397 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactiveEnergyExtensions.g.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricReactiveEnergy +{ + /// + /// A number to ElectricReactiveEnergy Extensions + /// + public static class NumberToElectricReactiveEnergyExtensions + { + /// + public static ElectricReactiveEnergy KilovoltampereReactiveHours(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactiveEnergy.FromKilovoltampereReactiveHours(Convert.ToDouble(value)); + + /// + public static ElectricReactiveEnergy MegavoltampereReactiveHours(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactiveEnergy.FromMegavoltampereReactiveHours(Convert.ToDouble(value)); + + /// + public static ElectricReactiveEnergy VoltampereReactiveHours(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactiveEnergy.FromVoltampereReactiveHours(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactivePowerExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactivePowerExtensions.g.cs new file mode 100644 index 0000000000..0e998e2520 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricReactivePowerExtensions.g.cs @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricReactivePower +{ + /// + /// A number to ElectricReactivePower Extensions + /// + public static class NumberToElectricReactivePowerExtensions + { + /// + public static ElectricReactivePower GigavoltamperesReactive(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactivePower.FromGigavoltamperesReactive(Convert.ToDouble(value)); + + /// + public static ElectricReactivePower KilovoltamperesReactive(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactivePower.FromKilovoltamperesReactive(Convert.ToDouble(value)); + + /// + public static ElectricReactivePower MegavoltamperesReactive(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactivePower.FromMegavoltamperesReactive(Convert.ToDouble(value)); + + /// + public static ElectricReactivePower VoltamperesReactive(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricReactivePower.FromVoltamperesReactive(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricResistanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricResistanceExtensions.g.cs index 99e17110cf..7661e6b62e 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricResistanceExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricResistanceExtensions.g.cs @@ -72,6 +72,14 @@ public static ElectricResistance Milliohms(this T value) #endif => ElectricResistance.FromMilliohms(Convert.ToDouble(value)); + /// + public static ElectricResistance Nanoohms(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricResistance.FromNanoohms(Convert.ToDouble(value)); + /// public static ElectricResistance Ohms(this T value) where T : notnull diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricSusceptanceExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricSusceptanceExtensions.g.cs new file mode 100644 index 0000000000..7cbb2eca44 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToElectricSusceptanceExtensions.g.cs @@ -0,0 +1,164 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToElectricSusceptance +{ + /// + /// A number to ElectricSusceptance Extensions + /// + public static class NumberToElectricSusceptanceExtensions + { + /// + public static ElectricSusceptance Gigamhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromGigamhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Gigasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromGigasiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Kilomhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromKilomhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Kilosiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromKilosiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Megamhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMegamhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Megasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMegasiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Mhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Micromhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMicromhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Microsiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMicrosiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Millimhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMillimhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Millisiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromMillisiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Nanomhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromNanomhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Nanosiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromNanosiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Siemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromSiemens(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Teramhos(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromTeramhos(Convert.ToDouble(value)); + + /// + public static ElectricSusceptance Terasiemens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => ElectricSusceptance.FromTerasiemens(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs index c27d4b4b9c..b3817887d5 100644 --- a/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricAdmittanceTests.cs @@ -28,13 +28,28 @@ namespace UnitsNet.Tests.CustomCode public class ElectricAdmittanceTests : ElectricAdmittanceTestsBase { protected override bool SupportsSIUnitSystem => false; + protected override double NanosiemensInOneSiemens => 1E9; + protected override double NanomhosInOneSiemens => 1E9; - protected override double MicrosiemensInOneSiemens => 1e+6; + protected override double MicrosiemensInOneSiemens => 1E6; + protected override double MicromhosInOneSiemens => 1E6; - protected override double MillisiemensInOneSiemens => 1000; - - protected override double NanosiemensInOneSiemens => 1e+9; + protected override double MillisiemensInOneSiemens => 1E3; + protected override double MillimhosInOneSiemens => 1E3; protected override double SiemensInOneSiemens => 1; + protected override double MhosInOneSiemens => 1; + + protected override double KilosiemensInOneSiemens => 1E-3; + protected override double KilomhosInOneSiemens => 1E-3; + + protected override double MegasiemensInOneSiemens => 1E-6; + protected override double MegamhosInOneSiemens => 1E-6; + + protected override double GigasiemensInOneSiemens => 1E-9; + protected override double GigamhosInOneSiemens => 1E-9; + + protected override double TerasiemensInOneSiemens => 1E-12; + protected override double TeramhosInOneSiemens => 1E-12; } } diff --git a/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs b/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs new file mode 100644 index 0000000000..919fa27c9b --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricApparentEnergyTests.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricApparentEnergyTests : ElectricApparentEnergyTestsBase + { + 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/ElectricApparentPowerTests.cs b/UnitsNet.Tests/CustomCode/ElectricApparentPowerTests.cs new file mode 100644 index 0000000000..150dd10961 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricApparentPowerTests.cs @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricApparentPowerTests : ElectricApparentPowerTestsBase + { + 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/ElectricCapacitanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricCapacitanceTests.cs new file mode 100644 index 0000000000..176c2f892b --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricCapacitanceTests.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricCapacitanceTests : ElectricCapacitanceTestsBase + { + 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/ElectricConductanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs index 1ac770eba4..253e071237 100644 --- a/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricConductanceTests.cs @@ -28,14 +28,28 @@ namespace UnitsNet.Tests.CustomCode public class ElectricConductanceTests : ElectricConductanceTestsBase { protected override bool SupportsSIUnitSystem => false; - protected override double SiemensInOneSiemens => 1; + protected override double NanosiemensInOneSiemens => 1E9; + protected override double NanomhosInOneSiemens => 1E9; + + protected override double MicrosiemensInOneSiemens => 1E6; + protected override double MicromhosInOneSiemens => 1E6; protected override double MillisiemensInOneSiemens => 1E3; + protected override double MillimhosInOneSiemens => 1E3; - protected override double MicrosiemensInOneSiemens => 1E6; + protected override double SiemensInOneSiemens => 1; + protected override double MhosInOneSiemens => 1; protected override double KilosiemensInOneSiemens => 1E-3; + protected override double KilomhosInOneSiemens => 1E-3; - protected override double NanosiemensInOneSiemens => 1E9; + protected override double MegasiemensInOneSiemens => 1E-6; + protected override double MegamhosInOneSiemens => 1E-6; + + protected override double GigasiemensInOneSiemens => 1E-9; + protected override double GigamhosInOneSiemens => 1E-9; + + protected override double TerasiemensInOneSiemens => 1E-12; + protected override double TeramhosInOneSiemens => 1E-12; } } diff --git a/UnitsNet.Tests/CustomCode/ElectricImpedanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricImpedanceTests.cs new file mode 100644 index 0000000000..59152a115e --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricImpedanceTests.cs @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricImpedanceTests : ElectricImpedanceTestsBase + { + protected override bool SupportsSIUnitSystem => false; + protected override double NanoohmsInOneOhm => 1e9; + + protected override double MicroohmsInOneOhm => 1e6; + + protected override double MilliohmsInOneOhm => 1000; + + protected override double OhmsInOneOhm => 1; + + protected override double KiloohmsInOneOhm => 1e-3; + + protected override double MegaohmsInOneOhm => 1e-6; + + protected override double GigaohmsInOneOhm => 1e-9; + + protected override double TeraohmsInOneOhm => 1e-12; + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricReactanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricReactanceTests.cs new file mode 100644 index 0000000000..93158a3fd7 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricReactanceTests.cs @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricReactanceTests : ElectricReactanceTestsBase + { + protected override bool SupportsSIUnitSystem => false; + protected override double NanoohmsInOneOhm => 1e9; + + protected override double MicroohmsInOneOhm => 1e6; + + protected override double MilliohmsInOneOhm => 1000; + + protected override double OhmsInOneOhm => 1; + + protected override double KiloohmsInOneOhm => 1e-3; + + protected override double MegaohmsInOneOhm => 1e-6; + + protected override double GigaohmsInOneOhm => 1e-9; + + protected override double TeraohmsInOneOhm => 1e-12; + } +} diff --git a/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs b/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs new file mode 100644 index 0000000000..fa691f0a7a --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricReactiveEnergyTests.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricReactiveEnergyTests : ElectricReactiveEnergyTestsBase + { + 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/ElectricReactivePowerTests.cs b/UnitsNet.Tests/CustomCode/ElectricReactivePowerTests.cs new file mode 100644 index 0000000000..1ee3157806 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricReactivePowerTests.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricReactivePowerTests : ElectricReactivePowerTestsBase + { + 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/CustomCode/ElectricResistanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs index 3b88d7baa4..898b7f2000 100644 --- a/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs +++ b/UnitsNet.Tests/CustomCode/ElectricResistanceTests.cs @@ -8,6 +8,8 @@ namespace UnitsNet.Tests public class ElectricResistanceTests : ElectricResistanceTestsBase { protected override bool SupportsSIUnitSystem => false; + protected override double NanoohmsInOneOhm => 1e9; + protected override double MicroohmsInOneOhm => 1e6; protected override double MilliohmsInOneOhm => 1000; diff --git a/UnitsNet.Tests/CustomCode/ElectricSusceptanceTests.cs b/UnitsNet.Tests/CustomCode/ElectricSusceptanceTests.cs new file mode 100644 index 0000000000..4f7b8cd9a9 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/ElectricSusceptanceTests.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// +// 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; + +namespace UnitsNet.Tests.CustomCode +{ + public class ElectricSusceptanceTests : ElectricSusceptanceTestsBase + { + protected override bool SupportsSIUnitSystem => false; + protected override double NanosiemensInOneSiemens => 1E9; + protected override double NanomhosInOneSiemens => 1E9; + + protected override double MicrosiemensInOneSiemens => 1E6; + protected override double MicromhosInOneSiemens => 1E6; + + protected override double MillisiemensInOneSiemens => 1E3; + protected override double MillimhosInOneSiemens => 1E3; + + protected override double SiemensInOneSiemens => 1; + protected override double MhosInOneSiemens => 1; + + protected override double KilosiemensInOneSiemens => 1E-3; + protected override double KilomhosInOneSiemens => 1E-3; + + protected override double MegasiemensInOneSiemens => 1E-6; + protected override double MegamhosInOneSiemens => 1E-6; + + protected override double GigasiemensInOneSiemens => 1E-9; + protected override double GigamhosInOneSiemens => 1E-9; + + protected override double TerasiemensInOneSiemens => 1E-12; + protected override double TeramhosInOneSiemens => 1E-12; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 25f186ef56..85f7fc82be 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -52,23 +52,31 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, DensityUnit.TonnePerCubicMillimeter, Quantity.From(3, DensityUnit.TonnePerCubicMillimeter)); Assertion(3, DurationUnit.Year365, Quantity.From(3, DurationUnit.Year365)); Assertion(3, DynamicViscosityUnit.Reyn, Quantity.From(3, DynamicViscosityUnit.Reyn)); - Assertion(3, ElectricAdmittanceUnit.Siemens, Quantity.From(3, ElectricAdmittanceUnit.Siemens)); + Assertion(3, ElectricAdmittanceUnit.Terasiemens, Quantity.From(3, ElectricAdmittanceUnit.Terasiemens)); + Assertion(3, ElectricApparentEnergyUnit.VoltampereHour, Quantity.From(3, ElectricApparentEnergyUnit.VoltampereHour)); + Assertion(3, ElectricApparentPowerUnit.Voltampere, Quantity.From(3, ElectricApparentPowerUnit.Voltampere)); + Assertion(3, ElectricCapacitanceUnit.Picofarad, Quantity.From(3, ElectricCapacitanceUnit.Picofarad)); Assertion(3, ElectricChargeUnit.Picocoulomb, Quantity.From(3, ElectricChargeUnit.Picocoulomb)); Assertion(3, ElectricChargeDensityUnit.CoulombPerCubicMeter, Quantity.From(3, ElectricChargeDensityUnit.CoulombPerCubicMeter)); - Assertion(3, ElectricConductanceUnit.Siemens, Quantity.From(3, ElectricConductanceUnit.Siemens)); + Assertion(3, ElectricConductanceUnit.Terasiemens, Quantity.From(3, ElectricConductanceUnit.Terasiemens)); Assertion(3, ElectricConductivityUnit.SiemensPerMeter, Quantity.From(3, ElectricConductivityUnit.SiemensPerMeter)); Assertion(3, ElectricCurrentUnit.Picoampere, Quantity.From(3, ElectricCurrentUnit.Picoampere)); Assertion(3, ElectricCurrentDensityUnit.AmperePerSquareMeter, Quantity.From(3, ElectricCurrentDensityUnit.AmperePerSquareMeter)); Assertion(3, ElectricCurrentGradientUnit.MilliamperePerSecond, Quantity.From(3, ElectricCurrentGradientUnit.MilliamperePerSecond)); Assertion(3, ElectricFieldUnit.VoltPerMeter, Quantity.From(3, ElectricFieldUnit.VoltPerMeter)); + 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)); Assertion(3, ElectricResistanceUnit.Teraohm, Quantity.From(3, ElectricResistanceUnit.Teraohm)); Assertion(3, ElectricResistivityUnit.PicoohmMeter, Quantity.From(3, ElectricResistivityUnit.PicoohmMeter)); Assertion(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, Quantity.From(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)); + Assertion(3, ElectricSusceptanceUnit.Terasiemens, Quantity.From(3, ElectricSusceptanceUnit.Terasiemens)); Assertion(3, EnergyUnit.WattHour, Quantity.From(3, EnergyUnit.WattHour)); Assertion(3, EnergyDensityUnit.WattHourPerCubicMeter, Quantity.From(3, EnergyDensityUnit.WattHourPerCubicMeter)); Assertion(3, EntropyUnit.MegajoulePerKelvin, Quantity.From(3, EntropyUnit.MegajoulePerKelvin)); @@ -183,6 +191,9 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(Duration.Info, Duration.Zero); Assertion(DynamicViscosity.Info, DynamicViscosity.Zero); Assertion(ElectricAdmittance.Info, ElectricAdmittance.Zero); + Assertion(ElectricApparentEnergy.Info, ElectricApparentEnergy.Zero); + Assertion(ElectricApparentPower.Info, ElectricApparentPower.Zero); + Assertion(ElectricCapacitance.Info, ElectricCapacitance.Zero); Assertion(ElectricCharge.Info, ElectricCharge.Zero); Assertion(ElectricChargeDensity.Info, ElectricChargeDensity.Zero); Assertion(ElectricConductance.Info, ElectricConductance.Zero); @@ -191,14 +202,19 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(ElectricCurrentDensity.Info, ElectricCurrentDensity.Zero); Assertion(ElectricCurrentGradient.Info, ElectricCurrentGradient.Zero); Assertion(ElectricField.Info, ElectricField.Zero); + 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); Assertion(ElectricResistance.Info, ElectricResistance.Zero); Assertion(ElectricResistivity.Info, ElectricResistivity.Zero); Assertion(ElectricSurfaceChargeDensity.Info, ElectricSurfaceChargeDensity.Zero); + Assertion(ElectricSusceptance.Info, ElectricSusceptance.Zero); Assertion(Energy.Info, Energy.Zero); Assertion(EnergyDensity.Info, EnergyDensity.Zero); Assertion(Entropy.Info, Entropy.Zero); @@ -313,6 +329,9 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(Duration.BaseDimensions, Duration.Zero); Assertion(DynamicViscosity.BaseDimensions, DynamicViscosity.Zero); Assertion(ElectricAdmittance.BaseDimensions, ElectricAdmittance.Zero); + Assertion(ElectricApparentEnergy.BaseDimensions, ElectricApparentEnergy.Zero); + Assertion(ElectricApparentPower.BaseDimensions, ElectricApparentPower.Zero); + Assertion(ElectricCapacitance.BaseDimensions, ElectricCapacitance.Zero); Assertion(ElectricCharge.BaseDimensions, ElectricCharge.Zero); Assertion(ElectricChargeDensity.BaseDimensions, ElectricChargeDensity.Zero); Assertion(ElectricConductance.BaseDimensions, ElectricConductance.Zero); @@ -321,14 +340,19 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(ElectricCurrentDensity.BaseDimensions, ElectricCurrentDensity.Zero); Assertion(ElectricCurrentGradient.BaseDimensions, ElectricCurrentGradient.Zero); Assertion(ElectricField.BaseDimensions, ElectricField.Zero); + 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); Assertion(ElectricResistance.BaseDimensions, ElectricResistance.Zero); Assertion(ElectricResistivity.BaseDimensions, ElectricResistivity.Zero); Assertion(ElectricSurfaceChargeDensity.BaseDimensions, ElectricSurfaceChargeDensity.Zero); + Assertion(ElectricSusceptance.BaseDimensions, ElectricSusceptance.Zero); Assertion(Energy.BaseDimensions, Energy.Zero); Assertion(EnergyDensity.BaseDimensions, EnergyDensity.Zero); Assertion(Entropy.BaseDimensions, Entropy.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index f50a20dad0..1ee9d98ae6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -38,36 +38,84 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class ElectricAdmittanceTestsBase : QuantityTestsBase { + protected abstract double GigamhosInOneSiemens { get; } + protected abstract double GigasiemensInOneSiemens { get; } + protected abstract double KilomhosInOneSiemens { get; } + protected abstract double KilosiemensInOneSiemens { get; } + protected abstract double MegamhosInOneSiemens { get; } + protected abstract double MegasiemensInOneSiemens { get; } + protected abstract double MhosInOneSiemens { get; } + protected abstract double MicromhosInOneSiemens { get; } protected abstract double MicrosiemensInOneSiemens { get; } + protected abstract double MillimhosInOneSiemens { get; } protected abstract double MillisiemensInOneSiemens { get; } + protected abstract double NanomhosInOneSiemens { get; } protected abstract double NanosiemensInOneSiemens { get; } protected abstract double SiemensInOneSiemens { get; } + protected abstract double TeramhosInOneSiemens { get; } + protected abstract double TerasiemensInOneSiemens { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GigamhosTolerance { get { return 1e-5; } } + protected virtual double GigasiemensTolerance { get { return 1e-5; } } + protected virtual double KilomhosTolerance { get { return 1e-5; } } + protected virtual double KilosiemensTolerance { get { return 1e-5; } } + protected virtual double MegamhosTolerance { get { return 1e-5; } } + protected virtual double MegasiemensTolerance { get { return 1e-5; } } + protected virtual double MhosTolerance { get { return 1e-5; } } + protected virtual double MicromhosTolerance { get { return 1e-5; } } protected virtual double MicrosiemensTolerance { get { return 1e-5; } } + protected virtual double MillimhosTolerance { get { return 1e-5; } } protected virtual double MillisiemensTolerance { get { return 1e-5; } } + protected virtual double NanomhosTolerance { get { return 1e-5; } } protected virtual double NanosiemensTolerance { get { return 1e-5; } } protected virtual double SiemensTolerance { get { return 1e-5; } } + protected virtual double TeramhosTolerance { get { return 1e-5; } } + protected virtual double TerasiemensTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricAdmittanceUnit unit) { return unit switch { + ElectricAdmittanceUnit.Gigamho => (GigamhosInOneSiemens, GigamhosTolerance), + ElectricAdmittanceUnit.Gigasiemens => (GigasiemensInOneSiemens, GigasiemensTolerance), + ElectricAdmittanceUnit.Kilomho => (KilomhosInOneSiemens, KilomhosTolerance), + ElectricAdmittanceUnit.Kilosiemens => (KilosiemensInOneSiemens, KilosiemensTolerance), + ElectricAdmittanceUnit.Megamho => (MegamhosInOneSiemens, MegamhosTolerance), + ElectricAdmittanceUnit.Megasiemens => (MegasiemensInOneSiemens, MegasiemensTolerance), + ElectricAdmittanceUnit.Mho => (MhosInOneSiemens, MhosTolerance), + ElectricAdmittanceUnit.Micromho => (MicromhosInOneSiemens, MicromhosTolerance), ElectricAdmittanceUnit.Microsiemens => (MicrosiemensInOneSiemens, MicrosiemensTolerance), + ElectricAdmittanceUnit.Millimho => (MillimhosInOneSiemens, MillimhosTolerance), ElectricAdmittanceUnit.Millisiemens => (MillisiemensInOneSiemens, MillisiemensTolerance), + ElectricAdmittanceUnit.Nanomho => (NanomhosInOneSiemens, NanomhosTolerance), ElectricAdmittanceUnit.Nanosiemens => (NanosiemensInOneSiemens, NanosiemensTolerance), ElectricAdmittanceUnit.Siemens => (SiemensInOneSiemens, SiemensTolerance), + ElectricAdmittanceUnit.Teramho => (TeramhosInOneSiemens, TeramhosTolerance), + ElectricAdmittanceUnit.Terasiemens => (TerasiemensInOneSiemens, TerasiemensTolerance), _ => throw new NotSupportedException() }; } public static IEnumerable UnitTypes = new List { + new object[] { ElectricAdmittanceUnit.Gigamho }, + new object[] { ElectricAdmittanceUnit.Gigasiemens }, + new object[] { ElectricAdmittanceUnit.Kilomho }, + new object[] { ElectricAdmittanceUnit.Kilosiemens }, + new object[] { ElectricAdmittanceUnit.Megamho }, + new object[] { ElectricAdmittanceUnit.Megasiemens }, + new object[] { ElectricAdmittanceUnit.Mho }, + new object[] { ElectricAdmittanceUnit.Micromho }, new object[] { ElectricAdmittanceUnit.Microsiemens }, + new object[] { ElectricAdmittanceUnit.Millimho }, new object[] { ElectricAdmittanceUnit.Millisiemens }, + new object[] { ElectricAdmittanceUnit.Nanomho }, new object[] { ElectricAdmittanceUnit.Nanosiemens }, new object[] { ElectricAdmittanceUnit.Siemens }, + new object[] { ElectricAdmittanceUnit.Teramho }, + new object[] { ElectricAdmittanceUnit.Terasiemens }, }; [Fact] @@ -135,30 +183,90 @@ public void ElectricAdmittance_QuantityInfo_ReturnsQuantityInfoDescribingQuantit public void SiemensToElectricAdmittanceUnits() { ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); + AssertEx.EqualTolerance(GigamhosInOneSiemens, siemens.Gigamhos, GigamhosTolerance); + AssertEx.EqualTolerance(GigasiemensInOneSiemens, siemens.Gigasiemens, GigasiemensTolerance); + AssertEx.EqualTolerance(KilomhosInOneSiemens, siemens.Kilomhos, KilomhosTolerance); + AssertEx.EqualTolerance(KilosiemensInOneSiemens, siemens.Kilosiemens, KilosiemensTolerance); + AssertEx.EqualTolerance(MegamhosInOneSiemens, siemens.Megamhos, MegamhosTolerance); + AssertEx.EqualTolerance(MegasiemensInOneSiemens, siemens.Megasiemens, MegasiemensTolerance); + AssertEx.EqualTolerance(MhosInOneSiemens, siemens.Mhos, MhosTolerance); + AssertEx.EqualTolerance(MicromhosInOneSiemens, siemens.Micromhos, MicromhosTolerance); AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(MillimhosInOneSiemens, siemens.Millimhos, MillimhosTolerance); AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance); + AssertEx.EqualTolerance(NanomhosInOneSiemens, siemens.Nanomhos, NanomhosTolerance); AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.Nanosiemens, NanosiemensTolerance); AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance); + AssertEx.EqualTolerance(TeramhosInOneSiemens, siemens.Teramhos, TeramhosTolerance); + AssertEx.EqualTolerance(TerasiemensInOneSiemens, siemens.Terasiemens, TerasiemensTolerance); } [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { - var quantity00 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Microsiemens); - AssertEx.EqualTolerance(1, quantity00.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Microsiemens, quantity00.Unit); + var quantity00 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Gigamho); + AssertEx.EqualTolerance(1, quantity00.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Gigamho, quantity00.Unit); - var quantity01 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Millisiemens); - AssertEx.EqualTolerance(1, quantity01.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, quantity01.Unit); + var quantity01 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Gigasiemens); + AssertEx.EqualTolerance(1, quantity01.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, quantity01.Unit); - var quantity02 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Nanosiemens); - AssertEx.EqualTolerance(1, quantity02.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, quantity02.Unit); + var quantity02 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Kilomho); + AssertEx.EqualTolerance(1, quantity02.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Kilomho, quantity02.Unit); - var quantity03 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Siemens); - AssertEx.EqualTolerance(1, quantity03.Siemens, SiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Siemens, quantity03.Unit); + var quantity03 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Kilosiemens); + AssertEx.EqualTolerance(1, quantity03.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, quantity03.Unit); + + var quantity04 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Megamho); + AssertEx.EqualTolerance(1, quantity04.Megamhos, MegamhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Megamho, quantity04.Unit); + + var quantity05 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Megasiemens); + AssertEx.EqualTolerance(1, quantity05.Megasiemens, MegasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Megasiemens, quantity05.Unit); + + var quantity06 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Mho); + AssertEx.EqualTolerance(1, quantity06.Mhos, MhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Mho, quantity06.Unit); + + var quantity07 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Micromho); + AssertEx.EqualTolerance(1, quantity07.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Micromho, quantity07.Unit); + + var quantity08 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Microsiemens); + AssertEx.EqualTolerance(1, quantity08.Microsiemens, MicrosiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Microsiemens, quantity08.Unit); + + var quantity09 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Millimho); + AssertEx.EqualTolerance(1, quantity09.Millimhos, MillimhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Millimho, quantity09.Unit); + + var quantity10 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Millisiemens); + AssertEx.EqualTolerance(1, quantity10.Millisiemens, MillisiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Millisiemens, quantity10.Unit); + + var quantity11 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Nanomho); + AssertEx.EqualTolerance(1, quantity11.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Nanomho, quantity11.Unit); + + var quantity12 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Nanosiemens); + AssertEx.EqualTolerance(1, quantity12.Nanosiemens, NanosiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, quantity12.Unit); + + var quantity13 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Siemens); + AssertEx.EqualTolerance(1, quantity13.Siemens, SiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Siemens, quantity13.Unit); + + var quantity14 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Teramho); + AssertEx.EqualTolerance(1, quantity14.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Teramho, quantity14.Unit); + + var quantity15 = ElectricAdmittance.From(1, ElectricAdmittanceUnit.Terasiemens); + AssertEx.EqualTolerance(1, quantity15.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Terasiemens, quantity15.Unit); } @@ -184,10 +292,22 @@ public void FromSiemens_WithNanValue_DoNotThrowsArgumentException() public void As() { var siemens = ElectricAdmittance.FromSiemens(1); + AssertEx.EqualTolerance(GigamhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Gigamho), GigamhosTolerance); + AssertEx.EqualTolerance(GigasiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Gigasiemens), GigasiemensTolerance); + AssertEx.EqualTolerance(KilomhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Kilomho), KilomhosTolerance); + AssertEx.EqualTolerance(KilosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Kilosiemens), KilosiemensTolerance); + AssertEx.EqualTolerance(MegamhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Megamho), MegamhosTolerance); + AssertEx.EqualTolerance(MegasiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Megasiemens), MegasiemensTolerance); + AssertEx.EqualTolerance(MhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Mho), MhosTolerance); + AssertEx.EqualTolerance(MicromhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Micromho), MicromhosTolerance); AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Microsiemens), MicrosiemensTolerance); + AssertEx.EqualTolerance(MillimhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Millimho), MillimhosTolerance); AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Millisiemens), MillisiemensTolerance); + AssertEx.EqualTolerance(NanomhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Nanomho), NanomhosTolerance); AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Nanosiemens), NanosiemensTolerance); AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Siemens), SiemensTolerance); + AssertEx.EqualTolerance(TeramhosInOneSiemens, siemens.As(ElectricAdmittanceUnit.Teramho), TeramhosTolerance); + AssertEx.EqualTolerance(TerasiemensInOneSiemens, siemens.As(ElectricAdmittanceUnit.Terasiemens), TerasiemensTolerance); } [Fact] @@ -210,6 +330,62 @@ public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() [Fact] public void Parse() { + try + { + var parsed = ElectricAdmittance.Parse("1 G?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Gigamho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 GS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 k?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Kilomho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 kS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 M?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megamhos, MegamhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Megamho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 MS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megasiemens, MegasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Megasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 ?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Mho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 µ?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Micromho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricAdmittance.Parse("1 µS", CultureInfo.GetCultureInfo("en-US")); @@ -217,6 +393,13 @@ public void Parse() Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricAdmittance.Parse("1 m?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Millimhos, MillimhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Millimho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricAdmittance.Parse("1 mS", CultureInfo.GetCultureInfo("en-US")); @@ -224,6 +407,13 @@ public void Parse() Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricAdmittance.Parse("1 n?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Nanomho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricAdmittance.Parse("1 nS", CultureInfo.GetCultureInfo("en-US")); @@ -238,11 +428,61 @@ public void Parse() Assert.Equal(ElectricAdmittanceUnit.Siemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricAdmittance.Parse("1 T?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Teramho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricAdmittance.Parse("1 TS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Terasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] public void TryParse() { + { + Assert.True(ElectricAdmittance.TryParse("1 G?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Gigamho, parsed.Unit); + } + + { + Assert.True(ElectricAdmittance.TryParse("1 GS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, parsed.Unit); + } + + { + Assert.True(ElectricAdmittance.TryParse("1 k?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Kilomho, parsed.Unit); + } + + { + Assert.True(ElectricAdmittance.TryParse("1 kS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, parsed.Unit); + } + + { + Assert.True(ElectricAdmittance.TryParse("1 ?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Mho, parsed.Unit); + } + + { + Assert.True(ElectricAdmittance.TryParse("1 µ?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Micromho, parsed.Unit); + } + { Assert.True(ElectricAdmittance.TryParse("1 µS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); @@ -250,9 +490,9 @@ public void TryParse() } { - Assert.True(ElectricAdmittance.TryParse("1 mS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsed.Unit); + Assert.True(ElectricAdmittance.TryParse("1 n?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Nanomho, parsed.Unit); } { @@ -267,23 +507,95 @@ public void TryParse() Assert.Equal(ElectricAdmittanceUnit.Siemens, parsed.Unit); } + { + Assert.True(ElectricAdmittance.TryParse("1 T?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricAdmittanceUnit.Teramho, parsed.Unit); + } + + { + Assert.True(ElectricAdmittance.TryParse("1 TS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricAdmittanceUnit.Terasiemens, parsed.Unit); + } + } [Fact] public void ParseUnit() { + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("G?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Gigamho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("GS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("k?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Kilomho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("kS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("M?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Megamho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("MS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Megasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Mho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("µ?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Micromho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricAdmittance.ParseUnit("µS", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("m?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Millimho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricAdmittance.ParseUnit("mS", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("n?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Nanomho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricAdmittance.ParseUnit("nS", CultureInfo.GetCultureInfo("en-US")); @@ -296,19 +608,61 @@ public void ParseUnit() Assert.Equal(ElectricAdmittanceUnit.Siemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("T?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Teramho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricAdmittance.ParseUnit("TS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricAdmittanceUnit.Terasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] public void TryParseUnit() { + { + Assert.True(ElectricAdmittance.TryParseUnit("G?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Gigamho, parsedUnit); + } + + { + Assert.True(ElectricAdmittance.TryParseUnit("GS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Gigasiemens, parsedUnit); + } + + { + Assert.True(ElectricAdmittance.TryParseUnit("k?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Kilomho, parsedUnit); + } + + { + Assert.True(ElectricAdmittance.TryParseUnit("kS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Kilosiemens, parsedUnit); + } + + { + Assert.True(ElectricAdmittance.TryParseUnit("?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Mho, parsedUnit); + } + + { + Assert.True(ElectricAdmittance.TryParseUnit("µ?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Micromho, parsedUnit); + } + { Assert.True(ElectricAdmittance.TryParseUnit("µS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsedUnit); } { - Assert.True(ElectricAdmittance.TryParseUnit("mS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsedUnit); + Assert.True(ElectricAdmittance.TryParseUnit("n?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Nanomho, parsedUnit); } { @@ -321,6 +675,16 @@ public void TryParseUnit() Assert.Equal(ElectricAdmittanceUnit.Siemens, parsedUnit); } + { + Assert.True(ElectricAdmittance.TryParseUnit("T?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Teramho, parsedUnit); + } + + { + Assert.True(ElectricAdmittance.TryParseUnit("TS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricAdmittanceUnit.Terasiemens, parsedUnit); + } + } [Theory] @@ -369,10 +733,22 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec public void ConversionRoundTrip() { ElectricAdmittance siemens = ElectricAdmittance.FromSiemens(1); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromGigamhos(siemens.Gigamhos).Siemens, GigamhosTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromGigasiemens(siemens.Gigasiemens).Siemens, GigasiemensTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromKilomhos(siemens.Kilomhos).Siemens, KilomhosTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromKilosiemens(siemens.Kilosiemens).Siemens, KilosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromMegamhos(siemens.Megamhos).Siemens, MegamhosTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromMegasiemens(siemens.Megasiemens).Siemens, MegasiemensTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromMhos(siemens.Mhos).Siemens, MhosTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromMicromhos(siemens.Micromhos).Siemens, MicromhosTolerance); AssertEx.EqualTolerance(1, ElectricAdmittance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromMillimhos(siemens.Millimhos).Siemens, MillimhosTolerance); AssertEx.EqualTolerance(1, ElectricAdmittance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromNanomhos(siemens.Nanomhos).Siemens, NanomhosTolerance); AssertEx.EqualTolerance(1, ElectricAdmittance.FromNanosiemens(siemens.Nanosiemens).Siemens, NanosiemensTolerance); AssertEx.EqualTolerance(1, ElectricAdmittance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromTeramhos(siemens.Teramhos).Siemens, TeramhosTolerance); + AssertEx.EqualTolerance(1, ElectricAdmittance.FromTerasiemens(siemens.Terasiemens).Siemens, TerasiemensTolerance); } [Fact] @@ -431,8 +807,8 @@ public void CompareToThrowsOnNull() [Theory] [InlineData(1, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Siemens, true)] // Same value and unit. [InlineData(1, ElectricAdmittanceUnit.Siemens, 2, ElectricAdmittanceUnit.Siemens, false)] // Different value. - [InlineData(2, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Microsiemens, false)] // Different value and unit. - [InlineData(1, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Microsiemens, false)] // Different unit. + [InlineData(2, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Gigamho, false)] // Different value and unit. + [InlineData(1, ElectricAdmittanceUnit.Siemens, 1, ElectricAdmittanceUnit.Gigamho, false)] // Different unit. public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricAdmittanceUnit unitA, double valueB, ElectricAdmittanceUnit unitB, bool expectEqual) { var a = new ElectricAdmittance(valueA, unitA); @@ -522,10 +898,22 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { + Assert.Equal("1 G?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Gigamho).ToString()); + Assert.Equal("1 GS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Gigasiemens).ToString()); + Assert.Equal("1 k?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Kilomho).ToString()); + Assert.Equal("1 kS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Kilosiemens).ToString()); + Assert.Equal("1 M?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Megamho).ToString()); + Assert.Equal("1 MS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Megasiemens).ToString()); + Assert.Equal("1 ?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Mho).ToString()); + Assert.Equal("1 µ?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Micromho).ToString()); Assert.Equal("1 µS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Microsiemens).ToString()); + Assert.Equal("1 m?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Millimho).ToString()); Assert.Equal("1 mS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Millisiemens).ToString()); + Assert.Equal("1 n?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Nanomho).ToString()); Assert.Equal("1 nS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Nanosiemens).ToString()); Assert.Equal("1 S", new ElectricAdmittance(1, ElectricAdmittanceUnit.Siemens).ToString()); + Assert.Equal("1 T?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Teramho).ToString()); + Assert.Equal("1 TS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Terasiemens).ToString()); } finally { @@ -539,10 +927,22 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // 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 G?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Gigamho).ToString(swedishCulture)); + Assert.Equal("1 GS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Gigasiemens).ToString(swedishCulture)); + Assert.Equal("1 k?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Kilomho).ToString(swedishCulture)); + Assert.Equal("1 kS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Kilosiemens).ToString(swedishCulture)); + Assert.Equal("1 M?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Megamho).ToString(swedishCulture)); + Assert.Equal("1 MS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Megasiemens).ToString(swedishCulture)); + Assert.Equal("1 ?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Mho).ToString(swedishCulture)); + Assert.Equal("1 µ?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Micromho).ToString(swedishCulture)); Assert.Equal("1 µS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Microsiemens).ToString(swedishCulture)); + Assert.Equal("1 m?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Millimho).ToString(swedishCulture)); Assert.Equal("1 mS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Millisiemens).ToString(swedishCulture)); + Assert.Equal("1 n?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Nanomho).ToString(swedishCulture)); Assert.Equal("1 nS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Nanosiemens).ToString(swedishCulture)); Assert.Equal("1 S", new ElectricAdmittance(1, ElectricAdmittanceUnit.Siemens).ToString(swedishCulture)); + Assert.Equal("1 T?", new ElectricAdmittance(1, ElectricAdmittanceUnit.Teramho).ToString(swedishCulture)); + Assert.Equal("1 TS", new ElectricAdmittance(1, ElectricAdmittanceUnit.Terasiemens).ToString(swedishCulture)); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs new file mode 100644 index 0000000000..18ee60b0e9 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentEnergyTestsBase.g.cs @@ -0,0 +1,717 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricApparentEnergy. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricApparentEnergyTestsBase : 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(ElectricApparentEnergyUnit unit) + { + return unit switch + { + ElectricApparentEnergyUnit.KilovoltampereHour => (KilovoltampereHoursInOneVoltampereHour, KilovoltampereHoursTolerance), + ElectricApparentEnergyUnit.MegavoltampereHour => (MegavoltampereHoursInOneVoltampereHour, MegavoltampereHoursTolerance), + ElectricApparentEnergyUnit.VoltampereHour => (VoltampereHoursInOneVoltampereHour, VoltampereHoursTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricApparentEnergyUnit.KilovoltampereHour }, + new object[] { ElectricApparentEnergyUnit.MegavoltampereHour }, + new object[] { ElectricApparentEnergyUnit.VoltampereHour }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricApparentEnergy(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricApparentEnergy(double.PositiveInfinity, ElectricApparentEnergyUnit.VoltampereHour)); + var exception2 = Record.Exception(() => new ElectricApparentEnergy(double.NegativeInfinity, ElectricApparentEnergyUnit.VoltampereHour)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricApparentEnergy(double.NaN, ElectricApparentEnergyUnit.VoltampereHour)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricApparentEnergy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricApparentEnergy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricApparentEnergy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricApparentEnergy_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.VoltampereHour); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricApparentEnergy.Zero, quantityInfo.Zero); + Assert.Equal("ElectricApparentEnergy", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void VoltampereHourToElectricApparentEnergyUnits() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.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 = ElectricApparentEnergy.From(1, ElectricApparentEnergyUnit.KilovoltampereHour); + AssertEx.EqualTolerance(1, quantity00.KilovoltampereHours, KilovoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, quantity00.Unit); + + var quantity01 = ElectricApparentEnergy.From(1, ElectricApparentEnergyUnit.MegavoltampereHour); + AssertEx.EqualTolerance(1, quantity01.MegavoltampereHours, MegavoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, quantity01.Unit); + + var quantity02 = ElectricApparentEnergy.From(1, ElectricApparentEnergyUnit.VoltampereHour); + AssertEx.EqualTolerance(1, quantity02.VoltampereHours, VoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, quantity02.Unit); + + } + + [Fact] + public void FromVoltampereHours_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricApparentEnergy.FromVoltampereHours(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricApparentEnergy.FromVoltampereHours(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromVoltampereHours_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricApparentEnergy.FromVoltampereHours(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + AssertEx.EqualTolerance(KilovoltampereHoursInOneVoltampereHour, voltamperehour.As(ElectricApparentEnergyUnit.KilovoltampereHour), KilovoltampereHoursTolerance); + AssertEx.EqualTolerance(MegavoltampereHoursInOneVoltampereHour, voltamperehour.As(ElectricApparentEnergyUnit.MegavoltampereHour), MegavoltampereHoursTolerance); + AssertEx.EqualTolerance(VoltampereHoursInOneVoltampereHour, voltamperehour.As(ElectricApparentEnergyUnit.VoltampereHour), VoltampereHoursTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricApparentEnergy(value: 1, unit: ElectricApparentEnergy.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 = ElectricApparentEnergy.Parse("1 kVAh", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilovoltampereHours, KilovoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentEnergy.Parse("1 MVAh", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MegavoltampereHours, MegavoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentEnergy.Parse("1 VAh", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.VoltampereHours, VoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricApparentEnergy.TryParse("1 kVAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilovoltampereHours, KilovoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, parsed.Unit); + } + + { + Assert.True(ElectricApparentEnergy.TryParse("1 MVAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MegavoltampereHours, MegavoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, parsed.Unit); + } + + { + Assert.True(ElectricApparentEnergy.TryParse("1 VAh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.VoltampereHours, VoltampereHoursTolerance); + Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricApparentEnergy.ParseUnit("kVAh", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentEnergy.ParseUnit("MVAh", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentEnergy.ParseUnit("VAh", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricApparentEnergy.TryParseUnit("kVAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentEnergyUnit.KilovoltampereHour, parsedUnit); + } + + { + Assert.True(ElectricApparentEnergy.TryParseUnit("MVAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentEnergyUnit.MegavoltampereHour, parsedUnit); + } + + { + Assert.True(ElectricApparentEnergy.TryParseUnit("VAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentEnergyUnit.VoltampereHour, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricApparentEnergyUnit unit) + { + var inBaseUnits = ElectricApparentEnergy.From(1.0, ElectricApparentEnergy.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(ElectricApparentEnergyUnit unit) + { + var quantity = ElectricApparentEnergy.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricApparentEnergyUnit 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 = ElectricApparentEnergy.Units.First(u => u != ElectricApparentEnergy.BaseUnit); + + var quantity = ElectricApparentEnergy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricApparentEnergyUnit unit) + { + var quantity = default(ElectricApparentEnergy); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + AssertEx.EqualTolerance(1, ElectricApparentEnergy.FromKilovoltampereHours(voltamperehour.KilovoltampereHours).VoltampereHours, KilovoltampereHoursTolerance); + AssertEx.EqualTolerance(1, ElectricApparentEnergy.FromMegavoltampereHours(voltamperehour.MegavoltampereHours).VoltampereHours, MegavoltampereHoursTolerance); + AssertEx.EqualTolerance(1, ElectricApparentEnergy.FromVoltampereHours(voltamperehour.VoltampereHours).VoltampereHours, VoltampereHoursTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricApparentEnergy v = ElectricApparentEnergy.FromVoltampereHours(1); + AssertEx.EqualTolerance(-1, -v.VoltampereHours, VoltampereHoursTolerance); + AssertEx.EqualTolerance(2, (ElectricApparentEnergy.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, (ElectricApparentEnergy.FromVoltampereHours(10)/5).VoltampereHours, VoltampereHoursTolerance); + AssertEx.EqualTolerance(2, ElectricApparentEnergy.FromVoltampereHours(10)/ElectricApparentEnergy.FromVoltampereHours(5), VoltampereHoursTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricApparentEnergy oneVoltampereHour = ElectricApparentEnergy.FromVoltampereHours(1); + ElectricApparentEnergy twoVoltampereHours = ElectricApparentEnergy.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() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.Equal(0, voltamperehour.CompareTo(voltamperehour)); + Assert.True(voltamperehour.CompareTo(ElectricApparentEnergy.Zero) > 0); + Assert.True(ElectricApparentEnergy.Zero.CompareTo(voltamperehour) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.Throws(() => voltamperehour.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.Throws(() => voltamperehour.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricApparentEnergyUnit.VoltampereHour, 1, ElectricApparentEnergyUnit.VoltampereHour, true)] // Same value and unit. + [InlineData(1, ElectricApparentEnergyUnit.VoltampereHour, 2, ElectricApparentEnergyUnit.VoltampereHour, false)] // Different value. + [InlineData(2, ElectricApparentEnergyUnit.VoltampereHour, 1, ElectricApparentEnergyUnit.KilovoltampereHour, false)] // Different value and unit. + [InlineData(1, ElectricApparentEnergyUnit.VoltampereHour, 1, ElectricApparentEnergyUnit.KilovoltampereHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricApparentEnergyUnit unitA, double valueB, ElectricApparentEnergyUnit unitB, bool expectEqual) + { + var a = new ElectricApparentEnergy(valueA, unitA); + var b = new ElectricApparentEnergy(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 = ElectricApparentEnergy.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 = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.True(v.Equals(ElectricApparentEnergy.FromVoltampereHours(1), VoltampereHoursTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricApparentEnergy.Zero, VoltampereHoursTolerance, ComparisonType.Relative)); + Assert.True(ElectricApparentEnergy.FromVoltampereHours(100).Equals(ElectricApparentEnergy.FromVoltampereHours(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricApparentEnergy.FromVoltampereHours(100).Equals(ElectricApparentEnergy.FromVoltampereHours(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.Throws(() => v.Equals(ElectricApparentEnergy.FromVoltampereHours(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.False(voltamperehour.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricApparentEnergy voltamperehour = ElectricApparentEnergy.FromVoltampereHours(1); + Assert.False(voltamperehour.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricApparentEnergyUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricApparentEnergy.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 kVAh", new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.KilovoltampereHour).ToString()); + Assert.Equal("1 MVAh", new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.MegavoltampereHour).ToString()); + Assert.Equal("1 VAh", new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.VoltampereHour).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 kVAh", new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.KilovoltampereHour).ToString(swedishCulture)); + Assert.Equal("1 MVAh", new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.MegavoltampereHour).ToString(swedishCulture)); + Assert.Equal("1 VAh", new ElectricApparentEnergy(1, ElectricApparentEnergyUnit.VoltampereHour).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s1")); + Assert.Equal("0.12 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s2")); + Assert.Equal("0.123 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s3")); + Assert.Equal("0.1235 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s1", culture)); + Assert.Equal("0.12 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s2", culture)); + Assert.Equal("0.123 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s3", culture)); + Assert.Equal("0.1235 VAh", new ElectricApparentEnergy(0.123456, ElectricApparentEnergyUnit.VoltampereHour).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricApparentEnergy.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 = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricApparentEnergy))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricApparentEnergyUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(ElectricApparentEnergy.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(ElectricApparentEnergy.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricApparentEnergy.FromVoltampereHours(1.0); + Assert.Equal(new {ElectricApparentEnergy.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 = ElectricApparentEnergy.FromVoltampereHours(value); + Assert.Equal(ElectricApparentEnergy.FromVoltampereHours(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs new file mode 100644 index 0000000000..f0d0c64544 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricApparentPowerTestsBase.g.cs @@ -0,0 +1,806 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricApparentPower. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricApparentPowerTestsBase : 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(ElectricApparentPowerUnit unit) + { + return unit switch + { + ElectricApparentPowerUnit.Gigavoltampere => (GigavoltamperesInOneVoltampere, GigavoltamperesTolerance), + ElectricApparentPowerUnit.Kilovoltampere => (KilovoltamperesInOneVoltampere, KilovoltamperesTolerance), + ElectricApparentPowerUnit.Megavoltampere => (MegavoltamperesInOneVoltampere, MegavoltamperesTolerance), + ElectricApparentPowerUnit.Microvoltampere => (MicrovoltamperesInOneVoltampere, MicrovoltamperesTolerance), + ElectricApparentPowerUnit.Millivoltampere => (MillivoltamperesInOneVoltampere, MillivoltamperesTolerance), + ElectricApparentPowerUnit.Voltampere => (VoltamperesInOneVoltampere, VoltamperesTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricApparentPowerUnit.Gigavoltampere }, + new object[] { ElectricApparentPowerUnit.Kilovoltampere }, + new object[] { ElectricApparentPowerUnit.Megavoltampere }, + new object[] { ElectricApparentPowerUnit.Microvoltampere }, + new object[] { ElectricApparentPowerUnit.Millivoltampere }, + new object[] { ElectricApparentPowerUnit.Voltampere }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricApparentPower(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricApparentPowerUnit.Voltampere, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricApparentPower(double.PositiveInfinity, ElectricApparentPowerUnit.Voltampere)); + var exception2 = Record.Exception(() => new ElectricApparentPower(double.NegativeInfinity, ElectricApparentPowerUnit.Voltampere)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricApparentPower(double.NaN, ElectricApparentPowerUnit.Voltampere)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricApparentPower(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricApparentPower(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricApparentPower) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricApparentPower_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricApparentPower(1, ElectricApparentPowerUnit.Voltampere); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricApparentPower.Zero, quantityInfo.Zero); + Assert.Equal("ElectricApparentPower", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void VoltampereToElectricApparentPowerUnits() + { + ElectricApparentPower voltampere = ElectricApparentPower.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 = ElectricApparentPower.From(1, ElectricApparentPowerUnit.Gigavoltampere); + AssertEx.EqualTolerance(1, quantity00.Gigavoltamperes, GigavoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, quantity00.Unit); + + var quantity01 = ElectricApparentPower.From(1, ElectricApparentPowerUnit.Kilovoltampere); + AssertEx.EqualTolerance(1, quantity01.Kilovoltamperes, KilovoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, quantity01.Unit); + + var quantity02 = ElectricApparentPower.From(1, ElectricApparentPowerUnit.Megavoltampere); + AssertEx.EqualTolerance(1, quantity02.Megavoltamperes, MegavoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Megavoltampere, quantity02.Unit); + + var quantity03 = ElectricApparentPower.From(1, ElectricApparentPowerUnit.Microvoltampere); + AssertEx.EqualTolerance(1, quantity03.Microvoltamperes, MicrovoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, quantity03.Unit); + + var quantity04 = ElectricApparentPower.From(1, ElectricApparentPowerUnit.Millivoltampere); + AssertEx.EqualTolerance(1, quantity04.Millivoltamperes, MillivoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Millivoltampere, quantity04.Unit); + + var quantity05 = ElectricApparentPower.From(1, ElectricApparentPowerUnit.Voltampere); + AssertEx.EqualTolerance(1, quantity05.Voltamperes, VoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Voltampere, quantity05.Unit); + + } + + [Fact] + public void FromVoltamperes_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricApparentPower.FromVoltamperes(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricApparentPower.FromVoltamperes(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromVoltamperes_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricApparentPower.FromVoltamperes(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var voltampere = ElectricApparentPower.FromVoltamperes(1); + AssertEx.EqualTolerance(GigavoltamperesInOneVoltampere, voltampere.As(ElectricApparentPowerUnit.Gigavoltampere), GigavoltamperesTolerance); + AssertEx.EqualTolerance(KilovoltamperesInOneVoltampere, voltampere.As(ElectricApparentPowerUnit.Kilovoltampere), KilovoltamperesTolerance); + AssertEx.EqualTolerance(MegavoltamperesInOneVoltampere, voltampere.As(ElectricApparentPowerUnit.Megavoltampere), MegavoltamperesTolerance); + AssertEx.EqualTolerance(MicrovoltamperesInOneVoltampere, voltampere.As(ElectricApparentPowerUnit.Microvoltampere), MicrovoltamperesTolerance); + AssertEx.EqualTolerance(MillivoltamperesInOneVoltampere, voltampere.As(ElectricApparentPowerUnit.Millivoltampere), MillivoltamperesTolerance); + AssertEx.EqualTolerance(VoltamperesInOneVoltampere, voltampere.As(ElectricApparentPowerUnit.Voltampere), VoltamperesTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricApparentPower(value: 1, unit: ElectricApparentPower.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 = ElectricApparentPower.Parse("1 GVA", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigavoltamperes, GigavoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentPower.Parse("1 kVA", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilovoltamperes, KilovoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentPower.Parse("1 MVA", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megavoltamperes, MegavoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Megavoltampere, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentPower.Parse("1 µVA", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Microvoltamperes, MicrovoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentPower.Parse("1 mVA", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Millivoltamperes, MillivoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Millivoltampere, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricApparentPower.Parse("1 VA", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Voltamperes, VoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Voltampere, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricApparentPower.TryParse("1 GVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigavoltamperes, GigavoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, parsed.Unit); + } + + { + Assert.True(ElectricApparentPower.TryParse("1 kVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilovoltamperes, KilovoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, parsed.Unit); + } + + { + Assert.True(ElectricApparentPower.TryParse("1 µVA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Microvoltamperes, MicrovoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, parsed.Unit); + } + + { + Assert.True(ElectricApparentPower.TryParse("1 VA", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Voltamperes, VoltamperesTolerance); + Assert.Equal(ElectricApparentPowerUnit.Voltampere, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricApparentPower.ParseUnit("GVA", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentPower.ParseUnit("kVA", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentPower.ParseUnit("MVA", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentPowerUnit.Megavoltampere, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentPower.ParseUnit("µVA", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentPower.ParseUnit("mVA", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentPowerUnit.Millivoltampere, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricApparentPower.ParseUnit("VA", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricApparentPowerUnit.Voltampere, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricApparentPower.TryParseUnit("GVA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentPowerUnit.Gigavoltampere, parsedUnit); + } + + { + Assert.True(ElectricApparentPower.TryParseUnit("kVA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentPowerUnit.Kilovoltampere, parsedUnit); + } + + { + Assert.True(ElectricApparentPower.TryParseUnit("µVA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentPowerUnit.Microvoltampere, parsedUnit); + } + + { + Assert.True(ElectricApparentPower.TryParseUnit("VA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricApparentPowerUnit.Voltampere, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricApparentPowerUnit unit) + { + var inBaseUnits = ElectricApparentPower.From(1.0, ElectricApparentPower.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(ElectricApparentPowerUnit unit) + { + var quantity = ElectricApparentPower.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricApparentPowerUnit 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 = ElectricApparentPower.Units.First(u => u != ElectricApparentPower.BaseUnit); + + var quantity = ElectricApparentPower.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricApparentPowerUnit unit) + { + var quantity = default(ElectricApparentPower); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricApparentPower voltampere = ElectricApparentPower.FromVoltamperes(1); + AssertEx.EqualTolerance(1, ElectricApparentPower.FromGigavoltamperes(voltampere.Gigavoltamperes).Voltamperes, GigavoltamperesTolerance); + AssertEx.EqualTolerance(1, ElectricApparentPower.FromKilovoltamperes(voltampere.Kilovoltamperes).Voltamperes, KilovoltamperesTolerance); + AssertEx.EqualTolerance(1, ElectricApparentPower.FromMegavoltamperes(voltampere.Megavoltamperes).Voltamperes, MegavoltamperesTolerance); + AssertEx.EqualTolerance(1, ElectricApparentPower.FromMicrovoltamperes(voltampere.Microvoltamperes).Voltamperes, MicrovoltamperesTolerance); + AssertEx.EqualTolerance(1, ElectricApparentPower.FromMillivoltamperes(voltampere.Millivoltamperes).Voltamperes, MillivoltamperesTolerance); + AssertEx.EqualTolerance(1, ElectricApparentPower.FromVoltamperes(voltampere.Voltamperes).Voltamperes, VoltamperesTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricApparentPower v = ElectricApparentPower.FromVoltamperes(1); + AssertEx.EqualTolerance(-1, -v.Voltamperes, VoltamperesTolerance); + AssertEx.EqualTolerance(2, (ElectricApparentPower.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, (ElectricApparentPower.FromVoltamperes(10)/5).Voltamperes, VoltamperesTolerance); + AssertEx.EqualTolerance(2, ElectricApparentPower.FromVoltamperes(10)/ElectricApparentPower.FromVoltamperes(5), VoltamperesTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricApparentPower oneVoltampere = ElectricApparentPower.FromVoltamperes(1); + ElectricApparentPower twoVoltamperes = ElectricApparentPower.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() + { + ElectricApparentPower voltampere = ElectricApparentPower.FromVoltamperes(1); + Assert.Equal(0, voltampere.CompareTo(voltampere)); + Assert.True(voltampere.CompareTo(ElectricApparentPower.Zero) > 0); + Assert.True(ElectricApparentPower.Zero.CompareTo(voltampere) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricApparentPower voltampere = ElectricApparentPower.FromVoltamperes(1); + Assert.Throws(() => voltampere.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricApparentPower voltampere = ElectricApparentPower.FromVoltamperes(1); + Assert.Throws(() => voltampere.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricApparentPowerUnit.Voltampere, 1, ElectricApparentPowerUnit.Voltampere, true)] // Same value and unit. + [InlineData(1, ElectricApparentPowerUnit.Voltampere, 2, ElectricApparentPowerUnit.Voltampere, false)] // Different value. + [InlineData(2, ElectricApparentPowerUnit.Voltampere, 1, ElectricApparentPowerUnit.Gigavoltampere, false)] // Different value and unit. + [InlineData(1, ElectricApparentPowerUnit.Voltampere, 1, ElectricApparentPowerUnit.Gigavoltampere, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricApparentPowerUnit unitA, double valueB, ElectricApparentPowerUnit unitB, bool expectEqual) + { + var a = new ElectricApparentPower(valueA, unitA); + var b = new ElectricApparentPower(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 = ElectricApparentPower.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 = ElectricApparentPower.FromVoltamperes(1); + Assert.True(v.Equals(ElectricApparentPower.FromVoltamperes(1), VoltamperesTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricApparentPower.Zero, VoltamperesTolerance, ComparisonType.Relative)); + Assert.True(ElectricApparentPower.FromVoltamperes(100).Equals(ElectricApparentPower.FromVoltamperes(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricApparentPower.FromVoltamperes(100).Equals(ElectricApparentPower.FromVoltamperes(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricApparentPower.FromVoltamperes(1); + Assert.Throws(() => v.Equals(ElectricApparentPower.FromVoltamperes(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricApparentPower voltampere = ElectricApparentPower.FromVoltamperes(1); + Assert.False(voltampere.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricApparentPower voltampere = ElectricApparentPower.FromVoltamperes(1); + Assert.False(voltampere.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricApparentPowerUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricApparentPower.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 GVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Gigavoltampere).ToString()); + Assert.Equal("1 kVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Kilovoltampere).ToString()); + Assert.Equal("1 MVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Megavoltampere).ToString()); + Assert.Equal("1 µVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Microvoltampere).ToString()); + Assert.Equal("1 mVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Millivoltampere).ToString()); + Assert.Equal("1 VA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Voltampere).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 GVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Gigavoltampere).ToString(swedishCulture)); + Assert.Equal("1 kVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Kilovoltampere).ToString(swedishCulture)); + Assert.Equal("1 MVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Megavoltampere).ToString(swedishCulture)); + Assert.Equal("1 µVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Microvoltampere).ToString(swedishCulture)); + Assert.Equal("1 mVA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Millivoltampere).ToString(swedishCulture)); + Assert.Equal("1 VA", new ElectricApparentPower(1, ElectricApparentPowerUnit.Voltampere).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s1")); + Assert.Equal("0.12 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s2")); + Assert.Equal("0.123 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s3")); + Assert.Equal("0.1235 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s1", culture)); + Assert.Equal("0.12 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s2", culture)); + Assert.Equal("0.123 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s3", culture)); + Assert.Equal("0.1235 VA", new ElectricApparentPower(0.123456, ElectricApparentPowerUnit.Voltampere).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricApparentPower.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 = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricApparentPower))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricApparentPowerUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(ElectricApparentPower.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(ElectricApparentPower.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricApparentPower.FromVoltamperes(1.0); + Assert.Equal(new {ElectricApparentPower.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 = ElectricApparentPower.FromVoltamperes(value); + Assert.Equal(ElectricApparentPower.FromVoltamperes(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs new file mode 100644 index 0000000000..c30641f8e5 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCapacitanceTestsBase.g.cs @@ -0,0 +1,843 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricCapacitance. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricCapacitanceTestsBase : 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(ElectricCapacitanceUnit unit) + { + return unit switch + { + ElectricCapacitanceUnit.Farad => (FaradsInOneFarad, FaradsTolerance), + ElectricCapacitanceUnit.Kilofarad => (KilofaradsInOneFarad, KilofaradsTolerance), + ElectricCapacitanceUnit.Megafarad => (MegafaradsInOneFarad, MegafaradsTolerance), + ElectricCapacitanceUnit.Microfarad => (MicrofaradsInOneFarad, MicrofaradsTolerance), + ElectricCapacitanceUnit.Millifarad => (MillifaradsInOneFarad, MillifaradsTolerance), + ElectricCapacitanceUnit.Nanofarad => (NanofaradsInOneFarad, NanofaradsTolerance), + ElectricCapacitanceUnit.Picofarad => (PicofaradsInOneFarad, PicofaradsTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricCapacitanceUnit.Farad }, + new object[] { ElectricCapacitanceUnit.Kilofarad }, + new object[] { ElectricCapacitanceUnit.Megafarad }, + new object[] { ElectricCapacitanceUnit.Microfarad }, + new object[] { ElectricCapacitanceUnit.Millifarad }, + new object[] { ElectricCapacitanceUnit.Nanofarad }, + new object[] { ElectricCapacitanceUnit.Picofarad }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricCapacitance(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricCapacitanceUnit.Farad, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricCapacitance(double.PositiveInfinity, ElectricCapacitanceUnit.Farad)); + var exception2 = Record.Exception(() => new ElectricCapacitance(double.NegativeInfinity, ElectricCapacitanceUnit.Farad)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricCapacitance(double.NaN, ElectricCapacitanceUnit.Farad)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricCapacitance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricCapacitance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricCapacitance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricCapacitance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricCapacitance(1, ElectricCapacitanceUnit.Farad); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricCapacitance.Zero, quantityInfo.Zero); + Assert.Equal("ElectricCapacitance", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void FaradToElectricCapacitanceUnits() + { + ElectricCapacitance farad = ElectricCapacitance.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 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Farad); + AssertEx.EqualTolerance(1, quantity00.Farads, FaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Farad, quantity00.Unit); + + var quantity01 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Kilofarad); + AssertEx.EqualTolerance(1, quantity01.Kilofarads, KilofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Kilofarad, quantity01.Unit); + + var quantity02 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Megafarad); + AssertEx.EqualTolerance(1, quantity02.Megafarads, MegafaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Megafarad, quantity02.Unit); + + var quantity03 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Microfarad); + AssertEx.EqualTolerance(1, quantity03.Microfarads, MicrofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Microfarad, quantity03.Unit); + + var quantity04 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Millifarad); + AssertEx.EqualTolerance(1, quantity04.Millifarads, MillifaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Millifarad, quantity04.Unit); + + var quantity05 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Nanofarad); + AssertEx.EqualTolerance(1, quantity05.Nanofarads, NanofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Nanofarad, quantity05.Unit); + + var quantity06 = ElectricCapacitance.From(1, ElectricCapacitanceUnit.Picofarad); + AssertEx.EqualTolerance(1, quantity06.Picofarads, PicofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Picofarad, quantity06.Unit); + + } + + [Fact] + public void FromFarads_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricCapacitance.FromFarads(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricCapacitance.FromFarads(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromFarads_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricCapacitance.FromFarads(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var farad = ElectricCapacitance.FromFarads(1); + AssertEx.EqualTolerance(FaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Farad), FaradsTolerance); + AssertEx.EqualTolerance(KilofaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Kilofarad), KilofaradsTolerance); + AssertEx.EqualTolerance(MegafaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Megafarad), MegafaradsTolerance); + AssertEx.EqualTolerance(MicrofaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Microfarad), MicrofaradsTolerance); + AssertEx.EqualTolerance(MillifaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Millifarad), MillifaradsTolerance); + AssertEx.EqualTolerance(NanofaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Nanofarad), NanofaradsTolerance); + AssertEx.EqualTolerance(PicofaradsInOneFarad, farad.As(ElectricCapacitanceUnit.Picofarad), PicofaradsTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricCapacitance(value: 1, unit: ElectricCapacitance.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 = ElectricCapacitance.Parse("1 F", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Farads, FaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Farad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricCapacitance.Parse("1 kF", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilofarads, KilofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Kilofarad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricCapacitance.Parse("1 MF", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megafarads, MegafaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Megafarad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricCapacitance.Parse("1 µF", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Microfarads, MicrofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Microfarad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricCapacitance.Parse("1 mF", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Millifarads, MillifaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Millifarad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricCapacitance.Parse("1 nF", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanofarads, NanofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Nanofarad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricCapacitance.Parse("1 pF", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Picofarads, PicofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Picofarad, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricCapacitance.TryParse("1 F", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Farads, FaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Farad, parsed.Unit); + } + + { + Assert.True(ElectricCapacitance.TryParse("1 kF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilofarads, KilofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Kilofarad, parsed.Unit); + } + + { + Assert.True(ElectricCapacitance.TryParse("1 µF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Microfarads, MicrofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Microfarad, parsed.Unit); + } + + { + Assert.True(ElectricCapacitance.TryParse("1 nF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanofarads, NanofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Nanofarad, parsed.Unit); + } + + { + Assert.True(ElectricCapacitance.TryParse("1 pF", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Picofarads, PicofaradsTolerance); + Assert.Equal(ElectricCapacitanceUnit.Picofarad, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("F", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Farad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("kF", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Kilofarad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("MF", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Megafarad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("µF", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Microfarad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("mF", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Millifarad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("nF", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Nanofarad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricCapacitance.ParseUnit("pF", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricCapacitanceUnit.Picofarad, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricCapacitance.TryParseUnit("F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricCapacitanceUnit.Farad, parsedUnit); + } + + { + Assert.True(ElectricCapacitance.TryParseUnit("kF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricCapacitanceUnit.Kilofarad, parsedUnit); + } + + { + Assert.True(ElectricCapacitance.TryParseUnit("µF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricCapacitanceUnit.Microfarad, parsedUnit); + } + + { + Assert.True(ElectricCapacitance.TryParseUnit("nF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricCapacitanceUnit.Nanofarad, parsedUnit); + } + + { + Assert.True(ElectricCapacitance.TryParseUnit("pF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricCapacitanceUnit.Picofarad, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricCapacitanceUnit unit) + { + var inBaseUnits = ElectricCapacitance.From(1.0, ElectricCapacitance.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(ElectricCapacitanceUnit unit) + { + var quantity = ElectricCapacitance.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricCapacitanceUnit 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 = ElectricCapacitance.Units.First(u => u != ElectricCapacitance.BaseUnit); + + var quantity = ElectricCapacitance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricCapacitanceUnit unit) + { + var quantity = default(ElectricCapacitance); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricCapacitance farad = ElectricCapacitance.FromFarads(1); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromFarads(farad.Farads).Farads, FaradsTolerance); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromKilofarads(farad.Kilofarads).Farads, KilofaradsTolerance); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromMegafarads(farad.Megafarads).Farads, MegafaradsTolerance); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromMicrofarads(farad.Microfarads).Farads, MicrofaradsTolerance); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromMillifarads(farad.Millifarads).Farads, MillifaradsTolerance); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromNanofarads(farad.Nanofarads).Farads, NanofaradsTolerance); + AssertEx.EqualTolerance(1, ElectricCapacitance.FromPicofarads(farad.Picofarads).Farads, PicofaradsTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricCapacitance v = ElectricCapacitance.FromFarads(1); + AssertEx.EqualTolerance(-1, -v.Farads, FaradsTolerance); + AssertEx.EqualTolerance(2, (ElectricCapacitance.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, (ElectricCapacitance.FromFarads(10)/5).Farads, FaradsTolerance); + AssertEx.EqualTolerance(2, ElectricCapacitance.FromFarads(10)/ElectricCapacitance.FromFarads(5), FaradsTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricCapacitance oneFarad = ElectricCapacitance.FromFarads(1); + ElectricCapacitance twoFarads = ElectricCapacitance.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() + { + ElectricCapacitance farad = ElectricCapacitance.FromFarads(1); + Assert.Equal(0, farad.CompareTo(farad)); + Assert.True(farad.CompareTo(ElectricCapacitance.Zero) > 0); + Assert.True(ElectricCapacitance.Zero.CompareTo(farad) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricCapacitance farad = ElectricCapacitance.FromFarads(1); + Assert.Throws(() => farad.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricCapacitance farad = ElectricCapacitance.FromFarads(1); + Assert.Throws(() => farad.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricCapacitanceUnit.Farad, 1, ElectricCapacitanceUnit.Farad, true)] // Same value and unit. + [InlineData(1, ElectricCapacitanceUnit.Farad, 2, ElectricCapacitanceUnit.Farad, false)] // Different value. + [InlineData(2, ElectricCapacitanceUnit.Farad, 1, ElectricCapacitanceUnit.Kilofarad, false)] // Different value and unit. + [InlineData(1, ElectricCapacitanceUnit.Farad, 1, ElectricCapacitanceUnit.Kilofarad, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricCapacitanceUnit unitA, double valueB, ElectricCapacitanceUnit unitB, bool expectEqual) + { + var a = new ElectricCapacitance(valueA, unitA); + var b = new ElectricCapacitance(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 = ElectricCapacitance.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 = ElectricCapacitance.FromFarads(1); + Assert.True(v.Equals(ElectricCapacitance.FromFarads(1), FaradsTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricCapacitance.Zero, FaradsTolerance, ComparisonType.Relative)); + Assert.True(ElectricCapacitance.FromFarads(100).Equals(ElectricCapacitance.FromFarads(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricCapacitance.FromFarads(100).Equals(ElectricCapacitance.FromFarads(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricCapacitance.FromFarads(1); + Assert.Throws(() => v.Equals(ElectricCapacitance.FromFarads(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricCapacitance farad = ElectricCapacitance.FromFarads(1); + Assert.False(farad.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricCapacitance farad = ElectricCapacitance.FromFarads(1); + Assert.False(farad.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricCapacitanceUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricCapacitance.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 F", new ElectricCapacitance(1, ElectricCapacitanceUnit.Farad).ToString()); + Assert.Equal("1 kF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Kilofarad).ToString()); + Assert.Equal("1 MF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Megafarad).ToString()); + Assert.Equal("1 µF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Microfarad).ToString()); + Assert.Equal("1 mF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Millifarad).ToString()); + Assert.Equal("1 nF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Nanofarad).ToString()); + Assert.Equal("1 pF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Picofarad).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 F", new ElectricCapacitance(1, ElectricCapacitanceUnit.Farad).ToString(swedishCulture)); + Assert.Equal("1 kF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Kilofarad).ToString(swedishCulture)); + Assert.Equal("1 MF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Megafarad).ToString(swedishCulture)); + Assert.Equal("1 µF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Microfarad).ToString(swedishCulture)); + Assert.Equal("1 mF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Millifarad).ToString(swedishCulture)); + Assert.Equal("1 nF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Nanofarad).ToString(swedishCulture)); + Assert.Equal("1 pF", new ElectricCapacitance(1, ElectricCapacitanceUnit.Picofarad).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s1")); + Assert.Equal("0.12 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s2")); + Assert.Equal("0.123 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s3")); + Assert.Equal("0.1235 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s1", culture)); + Assert.Equal("0.12 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s2", culture)); + Assert.Equal("0.123 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s3", culture)); + Assert.Equal("0.1235 F", new ElectricCapacitance(0.123456, ElectricCapacitanceUnit.Farad).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricCapacitance.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 = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricCapacitance))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricCapacitanceUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(ElectricCapacitance.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(ElectricCapacitance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricCapacitance.FromFarads(1.0); + Assert.Equal(new {ElectricCapacitance.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 = ElectricCapacitance.FromFarads(value); + Assert.Equal(ElectricCapacitance.FromFarads(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index 4b2ff1f6b1..fff673f4c6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -38,40 +38,84 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class ElectricConductanceTestsBase : QuantityTestsBase { + protected abstract double GigamhosInOneSiemens { get; } + protected abstract double GigasiemensInOneSiemens { get; } + protected abstract double KilomhosInOneSiemens { get; } protected abstract double KilosiemensInOneSiemens { get; } + protected abstract double MegamhosInOneSiemens { get; } + protected abstract double MegasiemensInOneSiemens { get; } + protected abstract double MhosInOneSiemens { get; } + protected abstract double MicromhosInOneSiemens { get; } protected abstract double MicrosiemensInOneSiemens { get; } + protected abstract double MillimhosInOneSiemens { get; } protected abstract double MillisiemensInOneSiemens { get; } + protected abstract double NanomhosInOneSiemens { get; } protected abstract double NanosiemensInOneSiemens { get; } protected abstract double SiemensInOneSiemens { get; } + protected abstract double TeramhosInOneSiemens { get; } + protected abstract double TerasiemensInOneSiemens { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GigamhosTolerance { get { return 1e-5; } } + protected virtual double GigasiemensTolerance { get { return 1e-5; } } + protected virtual double KilomhosTolerance { get { return 1e-5; } } protected virtual double KilosiemensTolerance { get { return 1e-5; } } + protected virtual double MegamhosTolerance { get { return 1e-5; } } + protected virtual double MegasiemensTolerance { get { return 1e-5; } } + protected virtual double MhosTolerance { get { return 1e-5; } } + protected virtual double MicromhosTolerance { get { return 1e-5; } } protected virtual double MicrosiemensTolerance { get { return 1e-5; } } + protected virtual double MillimhosTolerance { get { return 1e-5; } } protected virtual double MillisiemensTolerance { get { return 1e-5; } } + protected virtual double NanomhosTolerance { get { return 1e-5; } } protected virtual double NanosiemensTolerance { get { return 1e-5; } } protected virtual double SiemensTolerance { get { return 1e-5; } } + protected virtual double TeramhosTolerance { get { return 1e-5; } } + protected virtual double TerasiemensTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricConductanceUnit unit) { return unit switch { + ElectricConductanceUnit.Gigamho => (GigamhosInOneSiemens, GigamhosTolerance), + ElectricConductanceUnit.Gigasiemens => (GigasiemensInOneSiemens, GigasiemensTolerance), + ElectricConductanceUnit.Kilomho => (KilomhosInOneSiemens, KilomhosTolerance), ElectricConductanceUnit.Kilosiemens => (KilosiemensInOneSiemens, KilosiemensTolerance), + ElectricConductanceUnit.Megamho => (MegamhosInOneSiemens, MegamhosTolerance), + ElectricConductanceUnit.Megasiemens => (MegasiemensInOneSiemens, MegasiemensTolerance), + ElectricConductanceUnit.Mho => (MhosInOneSiemens, MhosTolerance), + ElectricConductanceUnit.Micromho => (MicromhosInOneSiemens, MicromhosTolerance), ElectricConductanceUnit.Microsiemens => (MicrosiemensInOneSiemens, MicrosiemensTolerance), + ElectricConductanceUnit.Millimho => (MillimhosInOneSiemens, MillimhosTolerance), ElectricConductanceUnit.Millisiemens => (MillisiemensInOneSiemens, MillisiemensTolerance), + ElectricConductanceUnit.Nanomho => (NanomhosInOneSiemens, NanomhosTolerance), ElectricConductanceUnit.Nanosiemens => (NanosiemensInOneSiemens, NanosiemensTolerance), ElectricConductanceUnit.Siemens => (SiemensInOneSiemens, SiemensTolerance), + ElectricConductanceUnit.Teramho => (TeramhosInOneSiemens, TeramhosTolerance), + ElectricConductanceUnit.Terasiemens => (TerasiemensInOneSiemens, TerasiemensTolerance), _ => throw new NotSupportedException() }; } public static IEnumerable UnitTypes = new List { + new object[] { ElectricConductanceUnit.Gigamho }, + new object[] { ElectricConductanceUnit.Gigasiemens }, + new object[] { ElectricConductanceUnit.Kilomho }, new object[] { ElectricConductanceUnit.Kilosiemens }, + new object[] { ElectricConductanceUnit.Megamho }, + new object[] { ElectricConductanceUnit.Megasiemens }, + new object[] { ElectricConductanceUnit.Mho }, + new object[] { ElectricConductanceUnit.Micromho }, new object[] { ElectricConductanceUnit.Microsiemens }, + new object[] { ElectricConductanceUnit.Millimho }, new object[] { ElectricConductanceUnit.Millisiemens }, + new object[] { ElectricConductanceUnit.Nanomho }, new object[] { ElectricConductanceUnit.Nanosiemens }, new object[] { ElectricConductanceUnit.Siemens }, + new object[] { ElectricConductanceUnit.Teramho }, + new object[] { ElectricConductanceUnit.Terasiemens }, }; [Fact] @@ -139,35 +183,90 @@ public void ElectricConductance_QuantityInfo_ReturnsQuantityInfoDescribingQuanti public void SiemensToElectricConductanceUnits() { ElectricConductance siemens = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(GigamhosInOneSiemens, siemens.Gigamhos, GigamhosTolerance); + AssertEx.EqualTolerance(GigasiemensInOneSiemens, siemens.Gigasiemens, GigasiemensTolerance); + AssertEx.EqualTolerance(KilomhosInOneSiemens, siemens.Kilomhos, KilomhosTolerance); AssertEx.EqualTolerance(KilosiemensInOneSiemens, siemens.Kilosiemens, KilosiemensTolerance); + AssertEx.EqualTolerance(MegamhosInOneSiemens, siemens.Megamhos, MegamhosTolerance); + AssertEx.EqualTolerance(MegasiemensInOneSiemens, siemens.Megasiemens, MegasiemensTolerance); + AssertEx.EqualTolerance(MhosInOneSiemens, siemens.Mhos, MhosTolerance); + AssertEx.EqualTolerance(MicromhosInOneSiemens, siemens.Micromhos, MicromhosTolerance); AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(MillimhosInOneSiemens, siemens.Millimhos, MillimhosTolerance); AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance); + AssertEx.EqualTolerance(NanomhosInOneSiemens, siemens.Nanomhos, NanomhosTolerance); AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.Nanosiemens, NanosiemensTolerance); AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance); + AssertEx.EqualTolerance(TeramhosInOneSiemens, siemens.Teramhos, TeramhosTolerance); + AssertEx.EqualTolerance(TerasiemensInOneSiemens, siemens.Terasiemens, TerasiemensTolerance); } [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { - var quantity00 = ElectricConductance.From(1, ElectricConductanceUnit.Kilosiemens); - AssertEx.EqualTolerance(1, quantity00.Kilosiemens, KilosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Kilosiemens, quantity00.Unit); + var quantity00 = ElectricConductance.From(1, ElectricConductanceUnit.Gigamho); + AssertEx.EqualTolerance(1, quantity00.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricConductanceUnit.Gigamho, quantity00.Unit); - var quantity01 = ElectricConductance.From(1, ElectricConductanceUnit.Microsiemens); - AssertEx.EqualTolerance(1, quantity01.Microsiemens, MicrosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Microsiemens, quantity01.Unit); + var quantity01 = ElectricConductance.From(1, ElectricConductanceUnit.Gigasiemens); + AssertEx.EqualTolerance(1, quantity01.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Gigasiemens, quantity01.Unit); - var quantity02 = ElectricConductance.From(1, ElectricConductanceUnit.Millisiemens); - AssertEx.EqualTolerance(1, quantity02.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Millisiemens, quantity02.Unit); + var quantity02 = ElectricConductance.From(1, ElectricConductanceUnit.Kilomho); + AssertEx.EqualTolerance(1, quantity02.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricConductanceUnit.Kilomho, quantity02.Unit); - var quantity03 = ElectricConductance.From(1, ElectricConductanceUnit.Nanosiemens); - AssertEx.EqualTolerance(1, quantity03.Nanosiemens, NanosiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Nanosiemens, quantity03.Unit); + var quantity03 = ElectricConductance.From(1, ElectricConductanceUnit.Kilosiemens); + AssertEx.EqualTolerance(1, quantity03.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Kilosiemens, quantity03.Unit); - var quantity04 = ElectricConductance.From(1, ElectricConductanceUnit.Siemens); - AssertEx.EqualTolerance(1, quantity04.Siemens, SiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Siemens, quantity04.Unit); + var quantity04 = ElectricConductance.From(1, ElectricConductanceUnit.Megamho); + AssertEx.EqualTolerance(1, quantity04.Megamhos, MegamhosTolerance); + Assert.Equal(ElectricConductanceUnit.Megamho, quantity04.Unit); + + var quantity05 = ElectricConductance.From(1, ElectricConductanceUnit.Megasiemens); + AssertEx.EqualTolerance(1, quantity05.Megasiemens, MegasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Megasiemens, quantity05.Unit); + + var quantity06 = ElectricConductance.From(1, ElectricConductanceUnit.Mho); + AssertEx.EqualTolerance(1, quantity06.Mhos, MhosTolerance); + Assert.Equal(ElectricConductanceUnit.Mho, quantity06.Unit); + + var quantity07 = ElectricConductance.From(1, ElectricConductanceUnit.Micromho); + AssertEx.EqualTolerance(1, quantity07.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricConductanceUnit.Micromho, quantity07.Unit); + + var quantity08 = ElectricConductance.From(1, ElectricConductanceUnit.Microsiemens); + AssertEx.EqualTolerance(1, quantity08.Microsiemens, MicrosiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Microsiemens, quantity08.Unit); + + var quantity09 = ElectricConductance.From(1, ElectricConductanceUnit.Millimho); + AssertEx.EqualTolerance(1, quantity09.Millimhos, MillimhosTolerance); + Assert.Equal(ElectricConductanceUnit.Millimho, quantity09.Unit); + + var quantity10 = ElectricConductance.From(1, ElectricConductanceUnit.Millisiemens); + AssertEx.EqualTolerance(1, quantity10.Millisiemens, MillisiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Millisiemens, quantity10.Unit); + + var quantity11 = ElectricConductance.From(1, ElectricConductanceUnit.Nanomho); + AssertEx.EqualTolerance(1, quantity11.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricConductanceUnit.Nanomho, quantity11.Unit); + + var quantity12 = ElectricConductance.From(1, ElectricConductanceUnit.Nanosiemens); + AssertEx.EqualTolerance(1, quantity12.Nanosiemens, NanosiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Nanosiemens, quantity12.Unit); + + var quantity13 = ElectricConductance.From(1, ElectricConductanceUnit.Siemens); + AssertEx.EqualTolerance(1, quantity13.Siemens, SiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Siemens, quantity13.Unit); + + var quantity14 = ElectricConductance.From(1, ElectricConductanceUnit.Teramho); + AssertEx.EqualTolerance(1, quantity14.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricConductanceUnit.Teramho, quantity14.Unit); + + var quantity15 = ElectricConductance.From(1, ElectricConductanceUnit.Terasiemens); + AssertEx.EqualTolerance(1, quantity15.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Terasiemens, quantity15.Unit); } @@ -193,11 +292,22 @@ public void FromSiemens_WithNanValue_DoNotThrowsArgumentException() public void As() { var siemens = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(GigamhosInOneSiemens, siemens.As(ElectricConductanceUnit.Gigamho), GigamhosTolerance); + AssertEx.EqualTolerance(GigasiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Gigasiemens), GigasiemensTolerance); + AssertEx.EqualTolerance(KilomhosInOneSiemens, siemens.As(ElectricConductanceUnit.Kilomho), KilomhosTolerance); AssertEx.EqualTolerance(KilosiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Kilosiemens), KilosiemensTolerance); + AssertEx.EqualTolerance(MegamhosInOneSiemens, siemens.As(ElectricConductanceUnit.Megamho), MegamhosTolerance); + AssertEx.EqualTolerance(MegasiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Megasiemens), MegasiemensTolerance); + AssertEx.EqualTolerance(MhosInOneSiemens, siemens.As(ElectricConductanceUnit.Mho), MhosTolerance); + AssertEx.EqualTolerance(MicromhosInOneSiemens, siemens.As(ElectricConductanceUnit.Micromho), MicromhosTolerance); AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Microsiemens), MicrosiemensTolerance); + AssertEx.EqualTolerance(MillimhosInOneSiemens, siemens.As(ElectricConductanceUnit.Millimho), MillimhosTolerance); AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Millisiemens), MillisiemensTolerance); + AssertEx.EqualTolerance(NanomhosInOneSiemens, siemens.As(ElectricConductanceUnit.Nanomho), NanomhosTolerance); AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Nanosiemens), NanosiemensTolerance); AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Siemens), SiemensTolerance); + AssertEx.EqualTolerance(TeramhosInOneSiemens, siemens.As(ElectricConductanceUnit.Teramho), TeramhosTolerance); + AssertEx.EqualTolerance(TerasiemensInOneSiemens, siemens.As(ElectricConductanceUnit.Terasiemens), TerasiemensTolerance); } [Fact] @@ -220,6 +330,27 @@ public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() [Fact] public void Parse() { + try + { + var parsed = ElectricConductance.Parse("1 G?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricConductanceUnit.Gigamho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricConductance.Parse("1 GS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Gigasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricConductance.Parse("1 k?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricConductanceUnit.Kilomho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricConductance.Parse("1 kS", CultureInfo.GetCultureInfo("en-US")); @@ -227,6 +358,34 @@ public void Parse() Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricConductance.Parse("1 M?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megamhos, MegamhosTolerance); + Assert.Equal(ElectricConductanceUnit.Megamho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricConductance.Parse("1 MS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megasiemens, MegasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Megasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricConductance.Parse("1 ?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); + Assert.Equal(ElectricConductanceUnit.Mho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricConductance.Parse("1 µ?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricConductanceUnit.Micromho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricConductance.Parse("1 µS", CultureInfo.GetCultureInfo("en-US")); @@ -234,6 +393,13 @@ public void Parse() Assert.Equal(ElectricConductanceUnit.Microsiemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricConductance.Parse("1 m?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Millimhos, MillimhosTolerance); + Assert.Equal(ElectricConductanceUnit.Millimho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricConductance.Parse("1 mS", CultureInfo.GetCultureInfo("en-US")); @@ -241,6 +407,13 @@ public void Parse() Assert.Equal(ElectricConductanceUnit.Millisiemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricConductance.Parse("1 n?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricConductanceUnit.Nanomho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricConductance.Parse("1 nS", CultureInfo.GetCultureInfo("en-US")); @@ -255,17 +428,61 @@ public void Parse() Assert.Equal(ElectricConductanceUnit.Siemens, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricConductance.Parse("1 T?", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricConductanceUnit.Teramho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricConductance.Parse("1 TS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Terasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] public void TryParse() { + { + Assert.True(ElectricConductance.TryParse("1 G?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricConductanceUnit.Gigamho, parsed.Unit); + } + + { + Assert.True(ElectricConductance.TryParse("1 GS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Gigasiemens, parsed.Unit); + } + + { + Assert.True(ElectricConductance.TryParse("1 k?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricConductanceUnit.Kilomho, parsed.Unit); + } + { Assert.True(ElectricConductance.TryParse("1 kS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsed.Unit); } + { + Assert.True(ElectricConductance.TryParse("1 ?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); + Assert.Equal(ElectricConductanceUnit.Mho, parsed.Unit); + } + + { + Assert.True(ElectricConductance.TryParse("1 µ?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricConductanceUnit.Micromho, parsed.Unit); + } + { Assert.True(ElectricConductance.TryParse("1 µS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); @@ -273,9 +490,9 @@ public void TryParse() } { - Assert.True(ElectricConductance.TryParse("1 mS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); - AssertEx.EqualTolerance(1, parsed.Millisiemens, MillisiemensTolerance); - Assert.Equal(ElectricConductanceUnit.Millisiemens, parsed.Unit); + Assert.True(ElectricConductance.TryParse("1 n?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricConductanceUnit.Nanomho, parsed.Unit); } { @@ -290,29 +507,95 @@ public void TryParse() Assert.Equal(ElectricConductanceUnit.Siemens, parsed.Unit); } + { + Assert.True(ElectricConductance.TryParse("1 T?", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricConductanceUnit.Teramho, parsed.Unit); + } + + { + Assert.True(ElectricConductance.TryParse("1 TS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricConductanceUnit.Terasiemens, parsed.Unit); + } + } [Fact] public void ParseUnit() { + try + { + var parsedUnit = ElectricConductance.ParseUnit("G?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Gigamho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricConductance.ParseUnit("GS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Gigasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricConductance.ParseUnit("k?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Kilomho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricConductance.ParseUnit("kS", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricConductance.ParseUnit("M?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Megamho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricConductance.ParseUnit("MS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Megasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricConductance.ParseUnit("?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Mho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricConductance.ParseUnit("µ?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Micromho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricConductance.ParseUnit("µS", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(ElectricConductanceUnit.Microsiemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricConductance.ParseUnit("m?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Millimho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricConductance.ParseUnit("mS", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(ElectricConductanceUnit.Millisiemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricConductance.ParseUnit("n?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Nanomho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricConductance.ParseUnit("nS", CultureInfo.GetCultureInfo("en-US")); @@ -325,24 +608,61 @@ public void ParseUnit() Assert.Equal(ElectricConductanceUnit.Siemens, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricConductance.ParseUnit("T?", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Teramho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricConductance.ParseUnit("TS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricConductanceUnit.Terasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] public void TryParseUnit() { + { + Assert.True(ElectricConductance.TryParseUnit("G?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Gigamho, parsedUnit); + } + + { + Assert.True(ElectricConductance.TryParseUnit("GS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Gigasiemens, parsedUnit); + } + + { + Assert.True(ElectricConductance.TryParseUnit("k?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Kilomho, parsedUnit); + } + { Assert.True(ElectricConductance.TryParseUnit("kS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsedUnit); } + { + Assert.True(ElectricConductance.TryParseUnit("?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Mho, parsedUnit); + } + + { + Assert.True(ElectricConductance.TryParseUnit("µ?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Micromho, parsedUnit); + } + { Assert.True(ElectricConductance.TryParseUnit("µS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(ElectricConductanceUnit.Microsiemens, parsedUnit); } { - Assert.True(ElectricConductance.TryParseUnit("mS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductanceUnit.Millisiemens, parsedUnit); + Assert.True(ElectricConductance.TryParseUnit("n?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Nanomho, parsedUnit); } { @@ -355,6 +675,16 @@ public void TryParseUnit() Assert.Equal(ElectricConductanceUnit.Siemens, parsedUnit); } + { + Assert.True(ElectricConductance.TryParseUnit("T?", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Teramho, parsedUnit); + } + + { + Assert.True(ElectricConductance.TryParseUnit("TS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricConductanceUnit.Terasiemens, parsedUnit); + } + } [Theory] @@ -403,11 +733,22 @@ public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(Elec public void ConversionRoundTrip() { ElectricConductance siemens = ElectricConductance.FromSiemens(1); + AssertEx.EqualTolerance(1, ElectricConductance.FromGigamhos(siemens.Gigamhos).Siemens, GigamhosTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromGigasiemens(siemens.Gigasiemens).Siemens, GigasiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromKilomhos(siemens.Kilomhos).Siemens, KilomhosTolerance); AssertEx.EqualTolerance(1, ElectricConductance.FromKilosiemens(siemens.Kilosiemens).Siemens, KilosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromMegamhos(siemens.Megamhos).Siemens, MegamhosTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromMegasiemens(siemens.Megasiemens).Siemens, MegasiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromMhos(siemens.Mhos).Siemens, MhosTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromMicromhos(siemens.Micromhos).Siemens, MicromhosTolerance); AssertEx.EqualTolerance(1, ElectricConductance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromMillimhos(siemens.Millimhos).Siemens, MillimhosTolerance); AssertEx.EqualTolerance(1, ElectricConductance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromNanomhos(siemens.Nanomhos).Siemens, NanomhosTolerance); AssertEx.EqualTolerance(1, ElectricConductance.FromNanosiemens(siemens.Nanosiemens).Siemens, NanosiemensTolerance); AssertEx.EqualTolerance(1, ElectricConductance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromTeramhos(siemens.Teramhos).Siemens, TeramhosTolerance); + AssertEx.EqualTolerance(1, ElectricConductance.FromTerasiemens(siemens.Terasiemens).Siemens, TerasiemensTolerance); } [Fact] @@ -466,8 +807,8 @@ public void CompareToThrowsOnNull() [Theory] [InlineData(1, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Siemens, true)] // Same value and unit. [InlineData(1, ElectricConductanceUnit.Siemens, 2, ElectricConductanceUnit.Siemens, false)] // Different value. - [InlineData(2, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Kilosiemens, false)] // Different value and unit. - [InlineData(1, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Kilosiemens, false)] // Different unit. + [InlineData(2, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Gigamho, false)] // Different value and unit. + [InlineData(1, ElectricConductanceUnit.Siemens, 1, ElectricConductanceUnit.Gigamho, false)] // Different unit. public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricConductanceUnit unitA, double valueB, ElectricConductanceUnit unitB, bool expectEqual) { var a = new ElectricConductance(valueA, unitA); @@ -557,11 +898,22 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); try { + Assert.Equal("1 G?", new ElectricConductance(1, ElectricConductanceUnit.Gigamho).ToString()); + Assert.Equal("1 GS", new ElectricConductance(1, ElectricConductanceUnit.Gigasiemens).ToString()); + Assert.Equal("1 k?", new ElectricConductance(1, ElectricConductanceUnit.Kilomho).ToString()); Assert.Equal("1 kS", new ElectricConductance(1, ElectricConductanceUnit.Kilosiemens).ToString()); + Assert.Equal("1 M?", new ElectricConductance(1, ElectricConductanceUnit.Megamho).ToString()); + Assert.Equal("1 MS", new ElectricConductance(1, ElectricConductanceUnit.Megasiemens).ToString()); + Assert.Equal("1 ?", new ElectricConductance(1, ElectricConductanceUnit.Mho).ToString()); + Assert.Equal("1 µ?", new ElectricConductance(1, ElectricConductanceUnit.Micromho).ToString()); Assert.Equal("1 µS", new ElectricConductance(1, ElectricConductanceUnit.Microsiemens).ToString()); + Assert.Equal("1 m?", new ElectricConductance(1, ElectricConductanceUnit.Millimho).ToString()); Assert.Equal("1 mS", new ElectricConductance(1, ElectricConductanceUnit.Millisiemens).ToString()); + Assert.Equal("1 n?", new ElectricConductance(1, ElectricConductanceUnit.Nanomho).ToString()); Assert.Equal("1 nS", new ElectricConductance(1, ElectricConductanceUnit.Nanosiemens).ToString()); Assert.Equal("1 S", new ElectricConductance(1, ElectricConductanceUnit.Siemens).ToString()); + Assert.Equal("1 T?", new ElectricConductance(1, ElectricConductanceUnit.Teramho).ToString()); + Assert.Equal("1 TS", new ElectricConductance(1, ElectricConductanceUnit.Terasiemens).ToString()); } finally { @@ -575,11 +927,22 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // 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 G?", new ElectricConductance(1, ElectricConductanceUnit.Gigamho).ToString(swedishCulture)); + Assert.Equal("1 GS", new ElectricConductance(1, ElectricConductanceUnit.Gigasiemens).ToString(swedishCulture)); + Assert.Equal("1 k?", new ElectricConductance(1, ElectricConductanceUnit.Kilomho).ToString(swedishCulture)); Assert.Equal("1 kS", new ElectricConductance(1, ElectricConductanceUnit.Kilosiemens).ToString(swedishCulture)); + Assert.Equal("1 M?", new ElectricConductance(1, ElectricConductanceUnit.Megamho).ToString(swedishCulture)); + Assert.Equal("1 MS", new ElectricConductance(1, ElectricConductanceUnit.Megasiemens).ToString(swedishCulture)); + Assert.Equal("1 ?", new ElectricConductance(1, ElectricConductanceUnit.Mho).ToString(swedishCulture)); + Assert.Equal("1 µ?", new ElectricConductance(1, ElectricConductanceUnit.Micromho).ToString(swedishCulture)); Assert.Equal("1 µS", new ElectricConductance(1, ElectricConductanceUnit.Microsiemens).ToString(swedishCulture)); + Assert.Equal("1 m?", new ElectricConductance(1, ElectricConductanceUnit.Millimho).ToString(swedishCulture)); Assert.Equal("1 mS", new ElectricConductance(1, ElectricConductanceUnit.Millisiemens).ToString(swedishCulture)); + Assert.Equal("1 n?", new ElectricConductance(1, ElectricConductanceUnit.Nanomho).ToString(swedishCulture)); Assert.Equal("1 nS", new ElectricConductance(1, ElectricConductanceUnit.Nanosiemens).ToString(swedishCulture)); Assert.Equal("1 S", new ElectricConductance(1, ElectricConductanceUnit.Siemens).ToString(swedishCulture)); + Assert.Equal("1 T?", new ElectricConductance(1, ElectricConductanceUnit.Teramho).ToString(swedishCulture)); + Assert.Equal("1 TS", new ElectricConductance(1, ElectricConductanceUnit.Terasiemens).ToString(swedishCulture)); } [Fact] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs new file mode 100644 index 0000000000..d9bebeb977 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricImpedanceTestsBase.g.cs @@ -0,0 +1,880 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricImpedance. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricImpedanceTestsBase : QuantityTestsBase + { + protected abstract double GigaohmsInOneOhm { get; } + protected abstract double KiloohmsInOneOhm { get; } + protected abstract double MegaohmsInOneOhm { get; } + protected abstract double MicroohmsInOneOhm { get; } + protected abstract double MilliohmsInOneOhm { get; } + protected abstract double NanoohmsInOneOhm { get; } + protected abstract double OhmsInOneOhm { get; } + protected abstract double TeraohmsInOneOhm { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GigaohmsTolerance { get { return 1e-5; } } + protected virtual double KiloohmsTolerance { get { return 1e-5; } } + protected virtual double MegaohmsTolerance { get { return 1e-5; } } + protected virtual double MicroohmsTolerance { get { return 1e-5; } } + protected virtual double MilliohmsTolerance { get { return 1e-5; } } + protected virtual double NanoohmsTolerance { get { return 1e-5; } } + protected virtual double OhmsTolerance { get { return 1e-5; } } + protected virtual double TeraohmsTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricImpedanceUnit unit) + { + return unit switch + { + ElectricImpedanceUnit.Gigaohm => (GigaohmsInOneOhm, GigaohmsTolerance), + ElectricImpedanceUnit.Kiloohm => (KiloohmsInOneOhm, KiloohmsTolerance), + ElectricImpedanceUnit.Megaohm => (MegaohmsInOneOhm, MegaohmsTolerance), + ElectricImpedanceUnit.Microohm => (MicroohmsInOneOhm, MicroohmsTolerance), + ElectricImpedanceUnit.Milliohm => (MilliohmsInOneOhm, MilliohmsTolerance), + ElectricImpedanceUnit.Nanoohm => (NanoohmsInOneOhm, NanoohmsTolerance), + ElectricImpedanceUnit.Ohm => (OhmsInOneOhm, OhmsTolerance), + ElectricImpedanceUnit.Teraohm => (TeraohmsInOneOhm, TeraohmsTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricImpedanceUnit.Gigaohm }, + new object[] { ElectricImpedanceUnit.Kiloohm }, + new object[] { ElectricImpedanceUnit.Megaohm }, + new object[] { ElectricImpedanceUnit.Microohm }, + new object[] { ElectricImpedanceUnit.Milliohm }, + new object[] { ElectricImpedanceUnit.Nanoohm }, + new object[] { ElectricImpedanceUnit.Ohm }, + new object[] { ElectricImpedanceUnit.Teraohm }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricImpedance(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricImpedanceUnit.Ohm, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricImpedance(double.PositiveInfinity, ElectricImpedanceUnit.Ohm)); + var exception2 = Record.Exception(() => new ElectricImpedance(double.NegativeInfinity, ElectricImpedanceUnit.Ohm)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricImpedance(double.NaN, ElectricImpedanceUnit.Ohm)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricImpedance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricImpedance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricImpedance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricImpedance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricImpedance(1, ElectricImpedanceUnit.Ohm); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricImpedance.Zero, quantityInfo.Zero); + Assert.Equal("ElectricImpedance", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void OhmToElectricImpedanceUnits() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + AssertEx.EqualTolerance(GigaohmsInOneOhm, ohm.Gigaohms, GigaohmsTolerance); + AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.Kiloohms, KiloohmsTolerance); + AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.Megaohms, MegaohmsTolerance); + AssertEx.EqualTolerance(MicroohmsInOneOhm, ohm.Microohms, MicroohmsTolerance); + AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.Milliohms, MilliohmsTolerance); + AssertEx.EqualTolerance(NanoohmsInOneOhm, ohm.Nanoohms, NanoohmsTolerance); + AssertEx.EqualTolerance(OhmsInOneOhm, ohm.Ohms, OhmsTolerance); + AssertEx.EqualTolerance(TeraohmsInOneOhm, ohm.Teraohms, TeraohmsTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = ElectricImpedance.From(1, ElectricImpedanceUnit.Gigaohm); + AssertEx.EqualTolerance(1, quantity00.Gigaohms, GigaohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Gigaohm, quantity00.Unit); + + var quantity01 = ElectricImpedance.From(1, ElectricImpedanceUnit.Kiloohm); + AssertEx.EqualTolerance(1, quantity01.Kiloohms, KiloohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Kiloohm, quantity01.Unit); + + var quantity02 = ElectricImpedance.From(1, ElectricImpedanceUnit.Megaohm); + AssertEx.EqualTolerance(1, quantity02.Megaohms, MegaohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Megaohm, quantity02.Unit); + + var quantity03 = ElectricImpedance.From(1, ElectricImpedanceUnit.Microohm); + AssertEx.EqualTolerance(1, quantity03.Microohms, MicroohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Microohm, quantity03.Unit); + + var quantity04 = ElectricImpedance.From(1, ElectricImpedanceUnit.Milliohm); + AssertEx.EqualTolerance(1, quantity04.Milliohms, MilliohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Milliohm, quantity04.Unit); + + var quantity05 = ElectricImpedance.From(1, ElectricImpedanceUnit.Nanoohm); + AssertEx.EqualTolerance(1, quantity05.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Nanoohm, quantity05.Unit); + + var quantity06 = ElectricImpedance.From(1, ElectricImpedanceUnit.Ohm); + AssertEx.EqualTolerance(1, quantity06.Ohms, OhmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Ohm, quantity06.Unit); + + var quantity07 = ElectricImpedance.From(1, ElectricImpedanceUnit.Teraohm); + AssertEx.EqualTolerance(1, quantity07.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Teraohm, quantity07.Unit); + + } + + [Fact] + public void FromOhms_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricImpedance.FromOhms(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricImpedance.FromOhms(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromOhms_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricImpedance.FromOhms(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var ohm = ElectricImpedance.FromOhms(1); + AssertEx.EqualTolerance(GigaohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Gigaohm), GigaohmsTolerance); + AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Kiloohm), KiloohmsTolerance); + AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Megaohm), MegaohmsTolerance); + AssertEx.EqualTolerance(MicroohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Microohm), MicroohmsTolerance); + AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Milliohm), MilliohmsTolerance); + AssertEx.EqualTolerance(NanoohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Nanoohm), NanoohmsTolerance); + AssertEx.EqualTolerance(OhmsInOneOhm, ohm.As(ElectricImpedanceUnit.Ohm), OhmsTolerance); + AssertEx.EqualTolerance(TeraohmsInOneOhm, ohm.As(ElectricImpedanceUnit.Teraohm), TeraohmsTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricImpedance(value: 1, unit: ElectricImpedance.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 = ElectricImpedance.Parse("1 GΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Gigaohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 kΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Kiloohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 MΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megaohms, MegaohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Megaohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 µΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Microohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 mΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Milliohms, MilliohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Milliohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 nΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Nanoohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 Ω", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Ohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricImpedance.Parse("1 TΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Teraohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricImpedance.TryParse("1 GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Gigaohm, parsed.Unit); + } + + { + Assert.True(ElectricImpedance.TryParse("1 kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Kiloohm, parsed.Unit); + } + + { + Assert.True(ElectricImpedance.TryParse("1 µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Microohm, parsed.Unit); + } + + { + Assert.True(ElectricImpedance.TryParse("1 nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Nanoohm, parsed.Unit); + } + + { + Assert.True(ElectricImpedance.TryParse("1 Ω", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Ohm, parsed.Unit); + } + + { + Assert.True(ElectricImpedance.TryParse("1 TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricImpedanceUnit.Teraohm, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricImpedance.ParseUnit("GΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Gigaohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("kΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Kiloohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("MΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Megaohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("µΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Microohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("mΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Milliohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("nΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Nanoohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("Ω", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Ohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricImpedance.ParseUnit("TΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricImpedanceUnit.Teraohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricImpedance.TryParseUnit("GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricImpedanceUnit.Gigaohm, parsedUnit); + } + + { + Assert.True(ElectricImpedance.TryParseUnit("kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricImpedanceUnit.Kiloohm, parsedUnit); + } + + { + Assert.True(ElectricImpedance.TryParseUnit("µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricImpedanceUnit.Microohm, parsedUnit); + } + + { + Assert.True(ElectricImpedance.TryParseUnit("nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricImpedanceUnit.Nanoohm, parsedUnit); + } + + { + Assert.True(ElectricImpedance.TryParseUnit("Ω", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricImpedanceUnit.Ohm, parsedUnit); + } + + { + Assert.True(ElectricImpedance.TryParseUnit("TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricImpedanceUnit.Teraohm, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricImpedanceUnit unit) + { + var inBaseUnits = ElectricImpedance.From(1.0, ElectricImpedance.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(ElectricImpedanceUnit unit) + { + var quantity = ElectricImpedance.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricImpedanceUnit 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 = ElectricImpedance.Units.First(u => u != ElectricImpedance.BaseUnit); + + var quantity = ElectricImpedance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricImpedanceUnit unit) + { + var quantity = default(ElectricImpedance); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + AssertEx.EqualTolerance(1, ElectricImpedance.FromGigaohms(ohm.Gigaohms).Ohms, GigaohmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromMicroohms(ohm.Microohms).Ohms, MicroohmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromMilliohms(ohm.Milliohms).Ohms, MilliohmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromNanoohms(ohm.Nanoohms).Ohms, NanoohmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(1, ElectricImpedance.FromTeraohms(ohm.Teraohms).Ohms, TeraohmsTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricImpedance v = ElectricImpedance.FromOhms(1); + AssertEx.EqualTolerance(-1, -v.Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, (ElectricImpedance.FromOhms(3)-v).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, (v + v).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(10, (v*10).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(10, (10*v).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, (ElectricImpedance.FromOhms(10)/5).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, ElectricImpedance.FromOhms(10)/ElectricImpedance.FromOhms(5), OhmsTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricImpedance oneOhm = ElectricImpedance.FromOhms(1); + ElectricImpedance twoOhms = ElectricImpedance.FromOhms(2); + + Assert.True(oneOhm < twoOhms); + Assert.True(oneOhm <= twoOhms); + Assert.True(twoOhms > oneOhm); + Assert.True(twoOhms >= oneOhm); + + Assert.False(oneOhm > twoOhms); + Assert.False(oneOhm >= twoOhms); + Assert.False(twoOhms < oneOhm); + Assert.False(twoOhms <= oneOhm); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + Assert.Equal(0, ohm.CompareTo(ohm)); + Assert.True(ohm.CompareTo(ElectricImpedance.Zero) > 0); + Assert.True(ElectricImpedance.Zero.CompareTo(ohm) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + Assert.Throws(() => ohm.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + Assert.Throws(() => ohm.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricImpedanceUnit.Ohm, 1, ElectricImpedanceUnit.Ohm, true)] // Same value and unit. + [InlineData(1, ElectricImpedanceUnit.Ohm, 2, ElectricImpedanceUnit.Ohm, false)] // Different value. + [InlineData(2, ElectricImpedanceUnit.Ohm, 1, ElectricImpedanceUnit.Gigaohm, false)] // Different value and unit. + [InlineData(1, ElectricImpedanceUnit.Ohm, 1, ElectricImpedanceUnit.Gigaohm, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricImpedanceUnit unitA, double valueB, ElectricImpedanceUnit unitB, bool expectEqual) + { + var a = new ElectricImpedance(valueA, unitA); + var b = new ElectricImpedance(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 = ElectricImpedance.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 = ElectricImpedance.FromOhms(1); + Assert.True(v.Equals(ElectricImpedance.FromOhms(1), OhmsTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricImpedance.Zero, OhmsTolerance, ComparisonType.Relative)); + Assert.True(ElectricImpedance.FromOhms(100).Equals(ElectricImpedance.FromOhms(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricImpedance.FromOhms(100).Equals(ElectricImpedance.FromOhms(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricImpedance.FromOhms(1); + Assert.Throws(() => v.Equals(ElectricImpedance.FromOhms(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + Assert.False(ohm.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricImpedance ohm = ElectricImpedance.FromOhms(1); + Assert.False(ohm.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricImpedanceUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricImpedance.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 GΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Gigaohm).ToString()); + Assert.Equal("1 kΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Kiloohm).ToString()); + Assert.Equal("1 MΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Megaohm).ToString()); + Assert.Equal("1 µΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Microohm).ToString()); + Assert.Equal("1 mΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Milliohm).ToString()); + Assert.Equal("1 nΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Nanoohm).ToString()); + Assert.Equal("1 Ω", new ElectricImpedance(1, ElectricImpedanceUnit.Ohm).ToString()); + Assert.Equal("1 TΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Teraohm).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 GΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Gigaohm).ToString(swedishCulture)); + Assert.Equal("1 kΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Kiloohm).ToString(swedishCulture)); + Assert.Equal("1 MΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Megaohm).ToString(swedishCulture)); + Assert.Equal("1 µΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Microohm).ToString(swedishCulture)); + Assert.Equal("1 mΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Milliohm).ToString(swedishCulture)); + Assert.Equal("1 nΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Nanoohm).ToString(swedishCulture)); + Assert.Equal("1 Ω", new ElectricImpedance(1, ElectricImpedanceUnit.Ohm).ToString(swedishCulture)); + Assert.Equal("1 TΩ", new ElectricImpedance(1, ElectricImpedanceUnit.Teraohm).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s1")); + Assert.Equal("0.12 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s2")); + Assert.Equal("0.123 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s3")); + Assert.Equal("0.1235 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s1", culture)); + Assert.Equal("0.12 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s2", culture)); + Assert.Equal("0.123 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s3", culture)); + Assert.Equal("0.1235 Ω", new ElectricImpedance(0.123456, ElectricImpedanceUnit.Ohm).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricImpedance.FromOhms(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 = ElectricImpedance.FromOhms(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricImpedance))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricImpedanceUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(ElectricImpedance.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(ElectricImpedance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricImpedance.FromOhms(1.0); + Assert.Equal(new {ElectricImpedance.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 = ElectricImpedance.FromOhms(value); + Assert.Equal(ElectricImpedance.FromOhms(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs new file mode 100644 index 0000000000..d5ce7dfd5b --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactanceTestsBase.g.cs @@ -0,0 +1,880 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricReactance. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricReactanceTestsBase : QuantityTestsBase + { + protected abstract double GigaohmsInOneOhm { get; } + protected abstract double KiloohmsInOneOhm { get; } + protected abstract double MegaohmsInOneOhm { get; } + protected abstract double MicroohmsInOneOhm { get; } + protected abstract double MilliohmsInOneOhm { get; } + protected abstract double NanoohmsInOneOhm { get; } + protected abstract double OhmsInOneOhm { get; } + protected abstract double TeraohmsInOneOhm { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GigaohmsTolerance { get { return 1e-5; } } + protected virtual double KiloohmsTolerance { get { return 1e-5; } } + protected virtual double MegaohmsTolerance { get { return 1e-5; } } + protected virtual double MicroohmsTolerance { get { return 1e-5; } } + protected virtual double MilliohmsTolerance { get { return 1e-5; } } + protected virtual double NanoohmsTolerance { get { return 1e-5; } } + protected virtual double OhmsTolerance { get { return 1e-5; } } + protected virtual double TeraohmsTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricReactanceUnit unit) + { + return unit switch + { + ElectricReactanceUnit.Gigaohm => (GigaohmsInOneOhm, GigaohmsTolerance), + ElectricReactanceUnit.Kiloohm => (KiloohmsInOneOhm, KiloohmsTolerance), + ElectricReactanceUnit.Megaohm => (MegaohmsInOneOhm, MegaohmsTolerance), + ElectricReactanceUnit.Microohm => (MicroohmsInOneOhm, MicroohmsTolerance), + ElectricReactanceUnit.Milliohm => (MilliohmsInOneOhm, MilliohmsTolerance), + ElectricReactanceUnit.Nanoohm => (NanoohmsInOneOhm, NanoohmsTolerance), + ElectricReactanceUnit.Ohm => (OhmsInOneOhm, OhmsTolerance), + ElectricReactanceUnit.Teraohm => (TeraohmsInOneOhm, TeraohmsTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricReactanceUnit.Gigaohm }, + new object[] { ElectricReactanceUnit.Kiloohm }, + new object[] { ElectricReactanceUnit.Megaohm }, + new object[] { ElectricReactanceUnit.Microohm }, + new object[] { ElectricReactanceUnit.Milliohm }, + new object[] { ElectricReactanceUnit.Nanoohm }, + new object[] { ElectricReactanceUnit.Ohm }, + new object[] { ElectricReactanceUnit.Teraohm }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricReactance(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricReactanceUnit.Ohm, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricReactance(double.PositiveInfinity, ElectricReactanceUnit.Ohm)); + var exception2 = Record.Exception(() => new ElectricReactance(double.NegativeInfinity, ElectricReactanceUnit.Ohm)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricReactance(double.NaN, ElectricReactanceUnit.Ohm)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricReactance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricReactance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricReactance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricReactance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricReactance(1, ElectricReactanceUnit.Ohm); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricReactance.Zero, quantityInfo.Zero); + Assert.Equal("ElectricReactance", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void OhmToElectricReactanceUnits() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + AssertEx.EqualTolerance(GigaohmsInOneOhm, ohm.Gigaohms, GigaohmsTolerance); + AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.Kiloohms, KiloohmsTolerance); + AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.Megaohms, MegaohmsTolerance); + AssertEx.EqualTolerance(MicroohmsInOneOhm, ohm.Microohms, MicroohmsTolerance); + AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.Milliohms, MilliohmsTolerance); + AssertEx.EqualTolerance(NanoohmsInOneOhm, ohm.Nanoohms, NanoohmsTolerance); + AssertEx.EqualTolerance(OhmsInOneOhm, ohm.Ohms, OhmsTolerance); + AssertEx.EqualTolerance(TeraohmsInOneOhm, ohm.Teraohms, TeraohmsTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = ElectricReactance.From(1, ElectricReactanceUnit.Gigaohm); + AssertEx.EqualTolerance(1, quantity00.Gigaohms, GigaohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Gigaohm, quantity00.Unit); + + var quantity01 = ElectricReactance.From(1, ElectricReactanceUnit.Kiloohm); + AssertEx.EqualTolerance(1, quantity01.Kiloohms, KiloohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Kiloohm, quantity01.Unit); + + var quantity02 = ElectricReactance.From(1, ElectricReactanceUnit.Megaohm); + AssertEx.EqualTolerance(1, quantity02.Megaohms, MegaohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Megaohm, quantity02.Unit); + + var quantity03 = ElectricReactance.From(1, ElectricReactanceUnit.Microohm); + AssertEx.EqualTolerance(1, quantity03.Microohms, MicroohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Microohm, quantity03.Unit); + + var quantity04 = ElectricReactance.From(1, ElectricReactanceUnit.Milliohm); + AssertEx.EqualTolerance(1, quantity04.Milliohms, MilliohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Milliohm, quantity04.Unit); + + var quantity05 = ElectricReactance.From(1, ElectricReactanceUnit.Nanoohm); + AssertEx.EqualTolerance(1, quantity05.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Nanoohm, quantity05.Unit); + + var quantity06 = ElectricReactance.From(1, ElectricReactanceUnit.Ohm); + AssertEx.EqualTolerance(1, quantity06.Ohms, OhmsTolerance); + Assert.Equal(ElectricReactanceUnit.Ohm, quantity06.Unit); + + var quantity07 = ElectricReactance.From(1, ElectricReactanceUnit.Teraohm); + AssertEx.EqualTolerance(1, quantity07.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Teraohm, quantity07.Unit); + + } + + [Fact] + public void FromOhms_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricReactance.FromOhms(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricReactance.FromOhms(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromOhms_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricReactance.FromOhms(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var ohm = ElectricReactance.FromOhms(1); + AssertEx.EqualTolerance(GigaohmsInOneOhm, ohm.As(ElectricReactanceUnit.Gigaohm), GigaohmsTolerance); + AssertEx.EqualTolerance(KiloohmsInOneOhm, ohm.As(ElectricReactanceUnit.Kiloohm), KiloohmsTolerance); + AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.As(ElectricReactanceUnit.Megaohm), MegaohmsTolerance); + AssertEx.EqualTolerance(MicroohmsInOneOhm, ohm.As(ElectricReactanceUnit.Microohm), MicroohmsTolerance); + AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.As(ElectricReactanceUnit.Milliohm), MilliohmsTolerance); + AssertEx.EqualTolerance(NanoohmsInOneOhm, ohm.As(ElectricReactanceUnit.Nanoohm), NanoohmsTolerance); + AssertEx.EqualTolerance(OhmsInOneOhm, ohm.As(ElectricReactanceUnit.Ohm), OhmsTolerance); + AssertEx.EqualTolerance(TeraohmsInOneOhm, ohm.As(ElectricReactanceUnit.Teraohm), TeraohmsTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricReactance(value: 1, unit: ElectricReactance.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 = ElectricReactance.Parse("1 GΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Gigaohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 kΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Kiloohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 MΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megaohms, MegaohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Megaohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 µΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Microohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 mΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Milliohms, MilliohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Milliohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 nΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Nanoohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 Ω", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); + Assert.Equal(ElectricReactanceUnit.Ohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactance.Parse("1 TΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Teraohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricReactance.TryParse("1 GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigaohms, GigaohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Gigaohm, parsed.Unit); + } + + { + Assert.True(ElectricReactance.TryParse("1 kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kiloohms, KiloohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Kiloohm, parsed.Unit); + } + + { + Assert.True(ElectricReactance.TryParse("1 µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Microohms, MicroohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Microohm, parsed.Unit); + } + + { + Assert.True(ElectricReactance.TryParse("1 nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Nanoohm, parsed.Unit); + } + + { + Assert.True(ElectricReactance.TryParse("1 Ω", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); + Assert.Equal(ElectricReactanceUnit.Ohm, parsed.Unit); + } + + { + Assert.True(ElectricReactance.TryParse("1 TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricReactanceUnit.Teraohm, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricReactance.ParseUnit("GΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Gigaohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("kΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Kiloohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("MΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Megaohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("µΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Microohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("mΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Milliohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("nΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Nanoohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("Ω", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Ohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactance.ParseUnit("TΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactanceUnit.Teraohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricReactance.TryParseUnit("GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactanceUnit.Gigaohm, parsedUnit); + } + + { + Assert.True(ElectricReactance.TryParseUnit("kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactanceUnit.Kiloohm, parsedUnit); + } + + { + Assert.True(ElectricReactance.TryParseUnit("µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactanceUnit.Microohm, parsedUnit); + } + + { + Assert.True(ElectricReactance.TryParseUnit("nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactanceUnit.Nanoohm, parsedUnit); + } + + { + Assert.True(ElectricReactance.TryParseUnit("Ω", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactanceUnit.Ohm, parsedUnit); + } + + { + Assert.True(ElectricReactance.TryParseUnit("TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactanceUnit.Teraohm, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricReactanceUnit unit) + { + var inBaseUnits = ElectricReactance.From(1.0, ElectricReactance.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(ElectricReactanceUnit unit) + { + var quantity = ElectricReactance.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricReactanceUnit 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 = ElectricReactance.Units.First(u => u != ElectricReactance.BaseUnit); + + var quantity = ElectricReactance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricReactanceUnit unit) + { + var quantity = default(ElectricReactance); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + AssertEx.EqualTolerance(1, ElectricReactance.FromGigaohms(ohm.Gigaohms).Ohms, GigaohmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromKiloohms(ohm.Kiloohms).Ohms, KiloohmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromMicroohms(ohm.Microohms).Ohms, MicroohmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromMilliohms(ohm.Milliohms).Ohms, MilliohmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromNanoohms(ohm.Nanoohms).Ohms, NanoohmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(1, ElectricReactance.FromTeraohms(ohm.Teraohms).Ohms, TeraohmsTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricReactance v = ElectricReactance.FromOhms(1); + AssertEx.EqualTolerance(-1, -v.Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, (ElectricReactance.FromOhms(3)-v).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, (v + v).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(10, (v*10).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(10, (10*v).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, (ElectricReactance.FromOhms(10)/5).Ohms, OhmsTolerance); + AssertEx.EqualTolerance(2, ElectricReactance.FromOhms(10)/ElectricReactance.FromOhms(5), OhmsTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricReactance oneOhm = ElectricReactance.FromOhms(1); + ElectricReactance twoOhms = ElectricReactance.FromOhms(2); + + Assert.True(oneOhm < twoOhms); + Assert.True(oneOhm <= twoOhms); + Assert.True(twoOhms > oneOhm); + Assert.True(twoOhms >= oneOhm); + + Assert.False(oneOhm > twoOhms); + Assert.False(oneOhm >= twoOhms); + Assert.False(twoOhms < oneOhm); + Assert.False(twoOhms <= oneOhm); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + Assert.Equal(0, ohm.CompareTo(ohm)); + Assert.True(ohm.CompareTo(ElectricReactance.Zero) > 0); + Assert.True(ElectricReactance.Zero.CompareTo(ohm) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + Assert.Throws(() => ohm.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + Assert.Throws(() => ohm.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricReactanceUnit.Ohm, 1, ElectricReactanceUnit.Ohm, true)] // Same value and unit. + [InlineData(1, ElectricReactanceUnit.Ohm, 2, ElectricReactanceUnit.Ohm, false)] // Different value. + [InlineData(2, ElectricReactanceUnit.Ohm, 1, ElectricReactanceUnit.Gigaohm, false)] // Different value and unit. + [InlineData(1, ElectricReactanceUnit.Ohm, 1, ElectricReactanceUnit.Gigaohm, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricReactanceUnit unitA, double valueB, ElectricReactanceUnit unitB, bool expectEqual) + { + var a = new ElectricReactance(valueA, unitA); + var b = new ElectricReactance(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 = ElectricReactance.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 = ElectricReactance.FromOhms(1); + Assert.True(v.Equals(ElectricReactance.FromOhms(1), OhmsTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricReactance.Zero, OhmsTolerance, ComparisonType.Relative)); + Assert.True(ElectricReactance.FromOhms(100).Equals(ElectricReactance.FromOhms(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricReactance.FromOhms(100).Equals(ElectricReactance.FromOhms(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricReactance.FromOhms(1); + Assert.Throws(() => v.Equals(ElectricReactance.FromOhms(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + Assert.False(ohm.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricReactance ohm = ElectricReactance.FromOhms(1); + Assert.False(ohm.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricReactanceUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricReactance.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 GΩ", new ElectricReactance(1, ElectricReactanceUnit.Gigaohm).ToString()); + Assert.Equal("1 kΩ", new ElectricReactance(1, ElectricReactanceUnit.Kiloohm).ToString()); + Assert.Equal("1 MΩ", new ElectricReactance(1, ElectricReactanceUnit.Megaohm).ToString()); + Assert.Equal("1 µΩ", new ElectricReactance(1, ElectricReactanceUnit.Microohm).ToString()); + Assert.Equal("1 mΩ", new ElectricReactance(1, ElectricReactanceUnit.Milliohm).ToString()); + Assert.Equal("1 nΩ", new ElectricReactance(1, ElectricReactanceUnit.Nanoohm).ToString()); + Assert.Equal("1 Ω", new ElectricReactance(1, ElectricReactanceUnit.Ohm).ToString()); + Assert.Equal("1 TΩ", new ElectricReactance(1, ElectricReactanceUnit.Teraohm).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 GΩ", new ElectricReactance(1, ElectricReactanceUnit.Gigaohm).ToString(swedishCulture)); + Assert.Equal("1 kΩ", new ElectricReactance(1, ElectricReactanceUnit.Kiloohm).ToString(swedishCulture)); + Assert.Equal("1 MΩ", new ElectricReactance(1, ElectricReactanceUnit.Megaohm).ToString(swedishCulture)); + Assert.Equal("1 µΩ", new ElectricReactance(1, ElectricReactanceUnit.Microohm).ToString(swedishCulture)); + Assert.Equal("1 mΩ", new ElectricReactance(1, ElectricReactanceUnit.Milliohm).ToString(swedishCulture)); + Assert.Equal("1 nΩ", new ElectricReactance(1, ElectricReactanceUnit.Nanoohm).ToString(swedishCulture)); + Assert.Equal("1 Ω", new ElectricReactance(1, ElectricReactanceUnit.Ohm).ToString(swedishCulture)); + Assert.Equal("1 TΩ", new ElectricReactance(1, ElectricReactanceUnit.Teraohm).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s1")); + Assert.Equal("0.12 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s2")); + Assert.Equal("0.123 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s3")); + Assert.Equal("0.1235 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s1", culture)); + Assert.Equal("0.12 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s2", culture)); + Assert.Equal("0.123 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s3", culture)); + Assert.Equal("0.1235 Ω", new ElectricReactance(0.123456, ElectricReactanceUnit.Ohm).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricReactance.FromOhms(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 = ElectricReactance.FromOhms(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricReactance))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricReactanceUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(ElectricReactance.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(ElectricReactance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricReactance.FromOhms(1.0); + Assert.Equal(new {ElectricReactance.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 = ElectricReactance.FromOhms(value); + Assert.Equal(ElectricReactance.FromOhms(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs new file mode 100644 index 0000000000..1c5ccd67b6 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactiveEnergyTestsBase.g.cs @@ -0,0 +1,717 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricReactiveEnergy. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricReactiveEnergyTestsBase : 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(ElectricReactiveEnergyUnit unit) + { + return unit switch + { + ElectricReactiveEnergyUnit.KilovoltampereReactiveHour => (KilovoltampereReactiveHoursInOneVoltampereReactiveHour, KilovoltampereReactiveHoursTolerance), + ElectricReactiveEnergyUnit.MegavoltampereReactiveHour => (MegavoltampereReactiveHoursInOneVoltampereReactiveHour, MegavoltampereReactiveHoursTolerance), + ElectricReactiveEnergyUnit.VoltampereReactiveHour => (VoltampereReactiveHoursInOneVoltampereReactiveHour, VoltampereReactiveHoursTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricReactiveEnergyUnit.KilovoltampereReactiveHour }, + new object[] { ElectricReactiveEnergyUnit.MegavoltampereReactiveHour }, + new object[] { ElectricReactiveEnergyUnit.VoltampereReactiveHour }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricReactiveEnergy(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricReactiveEnergy(double.PositiveInfinity, ElectricReactiveEnergyUnit.VoltampereReactiveHour)); + var exception2 = Record.Exception(() => new ElectricReactiveEnergy(double.NegativeInfinity, ElectricReactiveEnergyUnit.VoltampereReactiveHour)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricReactiveEnergy(double.NaN, ElectricReactiveEnergyUnit.VoltampereReactiveHour)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricReactiveEnergy(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricReactiveEnergy(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricReactiveEnergy) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricReactiveEnergy_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricReactiveEnergy.Zero, quantityInfo.Zero); + Assert.Equal("ElectricReactiveEnergy", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void VoltampereReactiveHourToElectricReactiveEnergyUnits() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.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 = ElectricReactiveEnergy.From(1, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour); + AssertEx.EqualTolerance(1, quantity00.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, quantity00.Unit); + + var quantity01 = ElectricReactiveEnergy.From(1, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour); + AssertEx.EqualTolerance(1, quantity01.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, quantity01.Unit); + + var quantity02 = ElectricReactiveEnergy.From(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour); + AssertEx.EqualTolerance(1, quantity02.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, quantity02.Unit); + + } + + [Fact] + public void FromVoltampereReactiveHours_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricReactiveEnergy.FromVoltampereReactiveHours(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricReactiveEnergy.FromVoltampereReactiveHours(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromVoltampereReactiveHours_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricReactiveEnergy.FromVoltampereReactiveHours(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + AssertEx.EqualTolerance(KilovoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour), KilovoltampereReactiveHoursTolerance); + AssertEx.EqualTolerance(MegavoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour), MegavoltampereReactiveHoursTolerance); + AssertEx.EqualTolerance(VoltampereReactiveHoursInOneVoltampereReactiveHour, voltamperereactivehour.As(ElectricReactiveEnergyUnit.VoltampereReactiveHour), VoltampereReactiveHoursTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricReactiveEnergy(value: 1, unit: ElectricReactiveEnergy.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 = ElectricReactiveEnergy.Parse("1 kvarh", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactiveEnergy.Parse("1 Mvarh", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactiveEnergy.Parse("1 varh", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricReactiveEnergy.TryParse("1 kvarh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilovoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, parsed.Unit); + } + + { + Assert.True(ElectricReactiveEnergy.TryParse("1 Mvarh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MegavoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, parsed.Unit); + } + + { + Assert.True(ElectricReactiveEnergy.TryParse("1 varh", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); + Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricReactiveEnergy.ParseUnit("kvarh", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactiveEnergy.ParseUnit("Mvarh", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactiveEnergy.ParseUnit("varh", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricReactiveEnergy.TryParseUnit("kvarh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, parsedUnit); + } + + { + Assert.True(ElectricReactiveEnergy.TryParseUnit("Mvarh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, parsedUnit); + } + + { + Assert.True(ElectricReactiveEnergy.TryParseUnit("varh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactiveEnergyUnit.VoltampereReactiveHour, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricReactiveEnergyUnit unit) + { + var inBaseUnits = ElectricReactiveEnergy.From(1.0, ElectricReactiveEnergy.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(ElectricReactiveEnergyUnit unit) + { + var quantity = ElectricReactiveEnergy.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricReactiveEnergyUnit 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 = ElectricReactiveEnergy.Units.First(u => u != ElectricReactiveEnergy.BaseUnit); + + var quantity = ElectricReactiveEnergy.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricReactiveEnergyUnit unit) + { + var quantity = default(ElectricReactiveEnergy); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + AssertEx.EqualTolerance(1, ElectricReactiveEnergy.FromKilovoltampereReactiveHours(voltamperereactivehour.KilovoltampereReactiveHours).VoltampereReactiveHours, KilovoltampereReactiveHoursTolerance); + AssertEx.EqualTolerance(1, ElectricReactiveEnergy.FromMegavoltampereReactiveHours(voltamperereactivehour.MegavoltampereReactiveHours).VoltampereReactiveHours, MegavoltampereReactiveHoursTolerance); + AssertEx.EqualTolerance(1, ElectricReactiveEnergy.FromVoltampereReactiveHours(voltamperereactivehour.VoltampereReactiveHours).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricReactiveEnergy v = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + AssertEx.EqualTolerance(-1, -v.VoltampereReactiveHours, VoltampereReactiveHoursTolerance); + AssertEx.EqualTolerance(2, (ElectricReactiveEnergy.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, (ElectricReactiveEnergy.FromVoltampereReactiveHours(10)/5).VoltampereReactiveHours, VoltampereReactiveHoursTolerance); + AssertEx.EqualTolerance(2, ElectricReactiveEnergy.FromVoltampereReactiveHours(10)/ElectricReactiveEnergy.FromVoltampereReactiveHours(5), VoltampereReactiveHoursTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricReactiveEnergy oneVoltampereReactiveHour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + ElectricReactiveEnergy twoVoltampereReactiveHours = ElectricReactiveEnergy.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() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.Equal(0, voltamperereactivehour.CompareTo(voltamperereactivehour)); + Assert.True(voltamperereactivehour.CompareTo(ElectricReactiveEnergy.Zero) > 0); + Assert.True(ElectricReactiveEnergy.Zero.CompareTo(voltamperereactivehour) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.Throws(() => voltamperereactivehour.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.Throws(() => voltamperereactivehour.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour, 1, ElectricReactiveEnergyUnit.VoltampereReactiveHour, true)] // Same value and unit. + [InlineData(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour, 2, ElectricReactiveEnergyUnit.VoltampereReactiveHour, false)] // Different value. + [InlineData(2, ElectricReactiveEnergyUnit.VoltampereReactiveHour, 1, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, false)] // Different value and unit. + [InlineData(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour, 1, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricReactiveEnergyUnit unitA, double valueB, ElectricReactiveEnergyUnit unitB, bool expectEqual) + { + var a = new ElectricReactiveEnergy(valueA, unitA); + var b = new ElectricReactiveEnergy(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 = ElectricReactiveEnergy.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 = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.True(v.Equals(ElectricReactiveEnergy.FromVoltampereReactiveHours(1), VoltampereReactiveHoursTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricReactiveEnergy.Zero, VoltampereReactiveHoursTolerance, ComparisonType.Relative)); + Assert.True(ElectricReactiveEnergy.FromVoltampereReactiveHours(100).Equals(ElectricReactiveEnergy.FromVoltampereReactiveHours(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricReactiveEnergy.FromVoltampereReactiveHours(100).Equals(ElectricReactiveEnergy.FromVoltampereReactiveHours(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.Throws(() => v.Equals(ElectricReactiveEnergy.FromVoltampereReactiveHours(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.False(voltamperereactivehour.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricReactiveEnergy voltamperereactivehour = ElectricReactiveEnergy.FromVoltampereReactiveHours(1); + Assert.False(voltamperereactivehour.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricReactiveEnergyUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricReactiveEnergy.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 kvarh", new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour).ToString()); + Assert.Equal("1 Mvarh", new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour).ToString()); + Assert.Equal("1 varh", new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 kvarh", new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour).ToString(swedishCulture)); + Assert.Equal("1 Mvarh", new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour).ToString(swedishCulture)); + Assert.Equal("1 varh", new ElectricReactiveEnergy(1, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s1")); + Assert.Equal("0.12 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s2")); + Assert.Equal("0.123 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s3")); + Assert.Equal("0.1235 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s1", culture)); + Assert.Equal("0.12 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s2", culture)); + Assert.Equal("0.123 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s3", culture)); + Assert.Equal("0.1235 varh", new ElectricReactiveEnergy(0.123456, ElectricReactiveEnergyUnit.VoltampereReactiveHour).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricReactiveEnergy.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 = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricReactiveEnergy))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricReactiveEnergyUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(ElectricReactiveEnergy.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(ElectricReactiveEnergy.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricReactiveEnergy.FromVoltampereReactiveHours(1.0); + Assert.Equal(new {ElectricReactiveEnergy.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 = ElectricReactiveEnergy.FromVoltampereReactiveHours(value); + Assert.Equal(ElectricReactiveEnergy.FromVoltampereReactiveHours(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs new file mode 100644 index 0000000000..1660988640 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricReactivePowerTestsBase.g.cs @@ -0,0 +1,754 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricReactivePower. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricReactivePowerTestsBase : 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(ElectricReactivePowerUnit unit) + { + return unit switch + { + ElectricReactivePowerUnit.GigavoltampereReactive => (GigavoltamperesReactiveInOneVoltampereReactive, GigavoltamperesReactiveTolerance), + ElectricReactivePowerUnit.KilovoltampereReactive => (KilovoltamperesReactiveInOneVoltampereReactive, KilovoltamperesReactiveTolerance), + ElectricReactivePowerUnit.MegavoltampereReactive => (MegavoltamperesReactiveInOneVoltampereReactive, MegavoltamperesReactiveTolerance), + ElectricReactivePowerUnit.VoltampereReactive => (VoltamperesReactiveInOneVoltampereReactive, VoltamperesReactiveTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricReactivePowerUnit.GigavoltampereReactive }, + new object[] { ElectricReactivePowerUnit.KilovoltampereReactive }, + new object[] { ElectricReactivePowerUnit.MegavoltampereReactive }, + new object[] { ElectricReactivePowerUnit.VoltampereReactive }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricReactivePower(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricReactivePower(double.PositiveInfinity, ElectricReactivePowerUnit.VoltampereReactive)); + var exception2 = Record.Exception(() => new ElectricReactivePower(double.NegativeInfinity, ElectricReactivePowerUnit.VoltampereReactive)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricReactivePower(double.NaN, ElectricReactivePowerUnit.VoltampereReactive)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricReactivePower(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricReactivePower(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricReactivePower) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricReactivePower_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricReactivePower(1, ElectricReactivePowerUnit.VoltampereReactive); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricReactivePower.Zero, quantityInfo.Zero); + Assert.Equal("ElectricReactivePower", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void VoltampereReactiveToElectricReactivePowerUnits() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.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 = ElectricReactivePower.From(1, ElectricReactivePowerUnit.GigavoltampereReactive); + AssertEx.EqualTolerance(1, quantity00.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, quantity00.Unit); + + var quantity01 = ElectricReactivePower.From(1, ElectricReactivePowerUnit.KilovoltampereReactive); + AssertEx.EqualTolerance(1, quantity01.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, quantity01.Unit); + + var quantity02 = ElectricReactivePower.From(1, ElectricReactivePowerUnit.MegavoltampereReactive); + AssertEx.EqualTolerance(1, quantity02.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, quantity02.Unit); + + var quantity03 = ElectricReactivePower.From(1, ElectricReactivePowerUnit.VoltampereReactive); + AssertEx.EqualTolerance(1, quantity03.VoltamperesReactive, VoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, quantity03.Unit); + + } + + [Fact] + public void FromVoltamperesReactive_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricReactivePower.FromVoltamperesReactive(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricReactivePower.FromVoltamperesReactive(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromVoltamperesReactive_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricReactivePower.FromVoltamperesReactive(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + AssertEx.EqualTolerance(GigavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ElectricReactivePowerUnit.GigavoltampereReactive), GigavoltamperesReactiveTolerance); + AssertEx.EqualTolerance(KilovoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ElectricReactivePowerUnit.KilovoltampereReactive), KilovoltamperesReactiveTolerance); + AssertEx.EqualTolerance(MegavoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ElectricReactivePowerUnit.MegavoltampereReactive), MegavoltamperesReactiveTolerance); + AssertEx.EqualTolerance(VoltamperesReactiveInOneVoltampereReactive, voltamperereactive.As(ElectricReactivePowerUnit.VoltampereReactive), VoltamperesReactiveTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricReactivePower(value: 1, unit: ElectricReactivePower.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 = ElectricReactivePower.Parse("1 Gvar", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactivePower.Parse("1 kvar", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactivePower.Parse("1 Mvar", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricReactivePower.Parse("1 var", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.VoltamperesReactive, VoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricReactivePower.TryParse("1 Gvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.GigavoltamperesReactive, GigavoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, parsed.Unit); + } + + { + Assert.True(ElectricReactivePower.TryParse("1 kvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilovoltamperesReactive, KilovoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, parsed.Unit); + } + + { + Assert.True(ElectricReactivePower.TryParse("1 Mvar", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MegavoltamperesReactive, MegavoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, parsed.Unit); + } + + { + Assert.True(ElectricReactivePower.TryParse("1 var", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.VoltamperesReactive, VoltamperesReactiveTolerance); + Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricReactivePower.ParseUnit("Gvar", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactivePower.ParseUnit("kvar", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactivePower.ParseUnit("Mvar", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricReactivePower.ParseUnit("var", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricReactivePower.TryParseUnit("Gvar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactivePowerUnit.GigavoltampereReactive, parsedUnit); + } + + { + Assert.True(ElectricReactivePower.TryParseUnit("kvar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactivePowerUnit.KilovoltampereReactive, parsedUnit); + } + + { + Assert.True(ElectricReactivePower.TryParseUnit("Mvar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactivePowerUnit.MegavoltampereReactive, parsedUnit); + } + + { + Assert.True(ElectricReactivePower.TryParseUnit("var", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricReactivePowerUnit.VoltampereReactive, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricReactivePowerUnit unit) + { + var inBaseUnits = ElectricReactivePower.From(1.0, ElectricReactivePower.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(ElectricReactivePowerUnit unit) + { + var quantity = ElectricReactivePower.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricReactivePowerUnit 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 = ElectricReactivePower.Units.First(u => u != ElectricReactivePower.BaseUnit); + + var quantity = ElectricReactivePower.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricReactivePowerUnit unit) + { + var quantity = default(ElectricReactivePower); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + AssertEx.EqualTolerance(1, ElectricReactivePower.FromGigavoltamperesReactive(voltamperereactive.GigavoltamperesReactive).VoltamperesReactive, GigavoltamperesReactiveTolerance); + AssertEx.EqualTolerance(1, ElectricReactivePower.FromKilovoltamperesReactive(voltamperereactive.KilovoltamperesReactive).VoltamperesReactive, KilovoltamperesReactiveTolerance); + AssertEx.EqualTolerance(1, ElectricReactivePower.FromMegavoltamperesReactive(voltamperereactive.MegavoltamperesReactive).VoltamperesReactive, MegavoltamperesReactiveTolerance); + AssertEx.EqualTolerance(1, ElectricReactivePower.FromVoltamperesReactive(voltamperereactive.VoltamperesReactive).VoltamperesReactive, VoltamperesReactiveTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricReactivePower v = ElectricReactivePower.FromVoltamperesReactive(1); + AssertEx.EqualTolerance(-1, -v.VoltamperesReactive, VoltamperesReactiveTolerance); + AssertEx.EqualTolerance(2, (ElectricReactivePower.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, (ElectricReactivePower.FromVoltamperesReactive(10)/5).VoltamperesReactive, VoltamperesReactiveTolerance); + AssertEx.EqualTolerance(2, ElectricReactivePower.FromVoltamperesReactive(10)/ElectricReactivePower.FromVoltamperesReactive(5), VoltamperesReactiveTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricReactivePower oneVoltampereReactive = ElectricReactivePower.FromVoltamperesReactive(1); + ElectricReactivePower twoVoltamperesReactive = ElectricReactivePower.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() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.Equal(0, voltamperereactive.CompareTo(voltamperereactive)); + Assert.True(voltamperereactive.CompareTo(ElectricReactivePower.Zero) > 0); + Assert.True(ElectricReactivePower.Zero.CompareTo(voltamperereactive) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.Throws(() => voltamperereactive.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.Throws(() => voltamperereactive.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricReactivePowerUnit.VoltampereReactive, 1, ElectricReactivePowerUnit.VoltampereReactive, true)] // Same value and unit. + [InlineData(1, ElectricReactivePowerUnit.VoltampereReactive, 2, ElectricReactivePowerUnit.VoltampereReactive, false)] // Different value. + [InlineData(2, ElectricReactivePowerUnit.VoltampereReactive, 1, ElectricReactivePowerUnit.GigavoltampereReactive, false)] // Different value and unit. + [InlineData(1, ElectricReactivePowerUnit.VoltampereReactive, 1, ElectricReactivePowerUnit.GigavoltampereReactive, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricReactivePowerUnit unitA, double valueB, ElectricReactivePowerUnit unitB, bool expectEqual) + { + var a = new ElectricReactivePower(valueA, unitA); + var b = new ElectricReactivePower(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 = ElectricReactivePower.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 = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.True(v.Equals(ElectricReactivePower.FromVoltamperesReactive(1), VoltamperesReactiveTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricReactivePower.Zero, VoltamperesReactiveTolerance, ComparisonType.Relative)); + Assert.True(ElectricReactivePower.FromVoltamperesReactive(100).Equals(ElectricReactivePower.FromVoltamperesReactive(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricReactivePower.FromVoltamperesReactive(100).Equals(ElectricReactivePower.FromVoltamperesReactive(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.Throws(() => v.Equals(ElectricReactivePower.FromVoltamperesReactive(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.False(voltamperereactive.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricReactivePower voltamperereactive = ElectricReactivePower.FromVoltamperesReactive(1); + Assert.False(voltamperereactive.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricReactivePowerUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricReactivePower.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 Gvar", new ElectricReactivePower(1, ElectricReactivePowerUnit.GigavoltampereReactive).ToString()); + Assert.Equal("1 kvar", new ElectricReactivePower(1, ElectricReactivePowerUnit.KilovoltampereReactive).ToString()); + Assert.Equal("1 Mvar", new ElectricReactivePower(1, ElectricReactivePowerUnit.MegavoltampereReactive).ToString()); + Assert.Equal("1 var", new ElectricReactivePower(1, ElectricReactivePowerUnit.VoltampereReactive).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 Gvar", new ElectricReactivePower(1, ElectricReactivePowerUnit.GigavoltampereReactive).ToString(swedishCulture)); + Assert.Equal("1 kvar", new ElectricReactivePower(1, ElectricReactivePowerUnit.KilovoltampereReactive).ToString(swedishCulture)); + Assert.Equal("1 Mvar", new ElectricReactivePower(1, ElectricReactivePowerUnit.MegavoltampereReactive).ToString(swedishCulture)); + Assert.Equal("1 var", new ElectricReactivePower(1, ElectricReactivePowerUnit.VoltampereReactive).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s1")); + Assert.Equal("0.12 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s2")); + Assert.Equal("0.123 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s3")); + Assert.Equal("0.1235 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s1", culture)); + Assert.Equal("0.12 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s2", culture)); + Assert.Equal("0.123 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s3", culture)); + Assert.Equal("0.1235 var", new ElectricReactivePower(0.123456, ElectricReactivePowerUnit.VoltampereReactive).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricReactivePower.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 = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricReactivePower))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricReactivePowerUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(ElectricReactivePower.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(ElectricReactivePower.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricReactivePower.FromVoltamperesReactive(1.0); + Assert.Equal(new {ElectricReactivePower.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 = ElectricReactivePower.FromVoltamperesReactive(value); + Assert.Equal(ElectricReactivePower.FromVoltamperesReactive(-value), -quantity); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index b3991642f0..acd0a85bf4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -43,6 +43,7 @@ public abstract partial class ElectricResistanceTestsBase : QuantityTestsBase protected abstract double MegaohmsInOneOhm { get; } protected abstract double MicroohmsInOneOhm { get; } protected abstract double MilliohmsInOneOhm { get; } + protected abstract double NanoohmsInOneOhm { get; } protected abstract double OhmsInOneOhm { get; } protected abstract double TeraohmsInOneOhm { get; } @@ -52,6 +53,7 @@ public abstract partial class ElectricResistanceTestsBase : QuantityTestsBase protected virtual double MegaohmsTolerance { get { return 1e-5; } } protected virtual double MicroohmsTolerance { get { return 1e-5; } } protected virtual double MilliohmsTolerance { get { return 1e-5; } } + protected virtual double NanoohmsTolerance { get { return 1e-5; } } protected virtual double OhmsTolerance { get { return 1e-5; } } protected virtual double TeraohmsTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -65,6 +67,7 @@ public abstract partial class ElectricResistanceTestsBase : QuantityTestsBase ElectricResistanceUnit.Megaohm => (MegaohmsInOneOhm, MegaohmsTolerance), ElectricResistanceUnit.Microohm => (MicroohmsInOneOhm, MicroohmsTolerance), ElectricResistanceUnit.Milliohm => (MilliohmsInOneOhm, MilliohmsTolerance), + ElectricResistanceUnit.Nanoohm => (NanoohmsInOneOhm, NanoohmsTolerance), ElectricResistanceUnit.Ohm => (OhmsInOneOhm, OhmsTolerance), ElectricResistanceUnit.Teraohm => (TeraohmsInOneOhm, TeraohmsTolerance), _ => throw new NotSupportedException() @@ -78,6 +81,7 @@ public abstract partial class ElectricResistanceTestsBase : QuantityTestsBase new object[] { ElectricResistanceUnit.Megaohm }, new object[] { ElectricResistanceUnit.Microohm }, new object[] { ElectricResistanceUnit.Milliohm }, + new object[] { ElectricResistanceUnit.Nanoohm }, new object[] { ElectricResistanceUnit.Ohm }, new object[] { ElectricResistanceUnit.Teraohm }, }; @@ -152,6 +156,7 @@ public void OhmToElectricResistanceUnits() AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.Megaohms, MegaohmsTolerance); AssertEx.EqualTolerance(MicroohmsInOneOhm, ohm.Microohms, MicroohmsTolerance); AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.Milliohms, MilliohmsTolerance); + AssertEx.EqualTolerance(NanoohmsInOneOhm, ohm.Nanoohms, NanoohmsTolerance); AssertEx.EqualTolerance(OhmsInOneOhm, ohm.Ohms, OhmsTolerance); AssertEx.EqualTolerance(TeraohmsInOneOhm, ohm.Teraohms, TeraohmsTolerance); } @@ -179,13 +184,17 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity04.Milliohms, MilliohmsTolerance); Assert.Equal(ElectricResistanceUnit.Milliohm, quantity04.Unit); - var quantity05 = ElectricResistance.From(1, ElectricResistanceUnit.Ohm); - AssertEx.EqualTolerance(1, quantity05.Ohms, OhmsTolerance); - Assert.Equal(ElectricResistanceUnit.Ohm, quantity05.Unit); + var quantity05 = ElectricResistance.From(1, ElectricResistanceUnit.Nanoohm); + AssertEx.EqualTolerance(1, quantity05.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricResistanceUnit.Nanoohm, quantity05.Unit); - var quantity06 = ElectricResistance.From(1, ElectricResistanceUnit.Teraohm); - AssertEx.EqualTolerance(1, quantity06.Teraohms, TeraohmsTolerance); - Assert.Equal(ElectricResistanceUnit.Teraohm, quantity06.Unit); + var quantity06 = ElectricResistance.From(1, ElectricResistanceUnit.Ohm); + AssertEx.EqualTolerance(1, quantity06.Ohms, OhmsTolerance); + Assert.Equal(ElectricResistanceUnit.Ohm, quantity06.Unit); + + var quantity07 = ElectricResistance.From(1, ElectricResistanceUnit.Teraohm); + AssertEx.EqualTolerance(1, quantity07.Teraohms, TeraohmsTolerance); + Assert.Equal(ElectricResistanceUnit.Teraohm, quantity07.Unit); } @@ -216,6 +225,7 @@ public void As() AssertEx.EqualTolerance(MegaohmsInOneOhm, ohm.As(ElectricResistanceUnit.Megaohm), MegaohmsTolerance); AssertEx.EqualTolerance(MicroohmsInOneOhm, ohm.As(ElectricResistanceUnit.Microohm), MicroohmsTolerance); AssertEx.EqualTolerance(MilliohmsInOneOhm, ohm.As(ElectricResistanceUnit.Milliohm), MilliohmsTolerance); + AssertEx.EqualTolerance(NanoohmsInOneOhm, ohm.As(ElectricResistanceUnit.Nanoohm), NanoohmsTolerance); AssertEx.EqualTolerance(OhmsInOneOhm, ohm.As(ElectricResistanceUnit.Ohm), OhmsTolerance); AssertEx.EqualTolerance(TeraohmsInOneOhm, ohm.As(ElectricResistanceUnit.Teraohm), TeraohmsTolerance); } @@ -275,6 +285,13 @@ public void Parse() Assert.Equal(ElectricResistanceUnit.Milliohm, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = ElectricResistance.Parse("1 nΩ", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricResistanceUnit.Nanoohm, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = ElectricResistance.Parse("1 Ω", CultureInfo.GetCultureInfo("en-US")); @@ -312,6 +329,12 @@ public void TryParse() Assert.Equal(ElectricResistanceUnit.Microohm, parsed.Unit); } + { + Assert.True(ElectricResistance.TryParse("1 nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanoohms, NanoohmsTolerance); + Assert.Equal(ElectricResistanceUnit.Nanoohm, parsed.Unit); + } + { Assert.True(ElectricResistance.TryParse("1 Ω", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.Ohms, OhmsTolerance); @@ -359,6 +382,12 @@ public void ParseUnit() Assert.Equal(ElectricResistanceUnit.Milliohm, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = ElectricResistance.ParseUnit("nΩ", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricResistanceUnit.Nanoohm, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = ElectricResistance.ParseUnit("Ω", CultureInfo.GetCultureInfo("en-US")); @@ -391,6 +420,11 @@ public void TryParseUnit() Assert.Equal(ElectricResistanceUnit.Microohm, parsedUnit); } + { + Assert.True(ElectricResistance.TryParseUnit("nΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricResistanceUnit.Nanoohm, parsedUnit); + } + { Assert.True(ElectricResistance.TryParseUnit("Ω", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(ElectricResistanceUnit.Ohm, parsedUnit); @@ -454,6 +488,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, ElectricResistance.FromMegaohms(ohm.Megaohms).Ohms, MegaohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromMicroohms(ohm.Microohms).Ohms, MicroohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromMilliohms(ohm.Milliohms).Ohms, MilliohmsTolerance); + AssertEx.EqualTolerance(1, ElectricResistance.FromNanoohms(ohm.Nanoohms).Ohms, NanoohmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromOhms(ohm.Ohms).Ohms, OhmsTolerance); AssertEx.EqualTolerance(1, ElectricResistance.FromTeraohms(ohm.Teraohms).Ohms, TeraohmsTolerance); } @@ -610,6 +645,7 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Assert.Equal("1 MΩ", new ElectricResistance(1, ElectricResistanceUnit.Megaohm).ToString()); Assert.Equal("1 µΩ", new ElectricResistance(1, ElectricResistanceUnit.Microohm).ToString()); Assert.Equal("1 mΩ", new ElectricResistance(1, ElectricResistanceUnit.Milliohm).ToString()); + Assert.Equal("1 nΩ", new ElectricResistance(1, ElectricResistanceUnit.Nanoohm).ToString()); Assert.Equal("1 Ω", new ElectricResistance(1, ElectricResistanceUnit.Ohm).ToString()); Assert.Equal("1 TΩ", new ElectricResistance(1, ElectricResistanceUnit.Teraohm).ToString()); } @@ -630,6 +666,7 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 MΩ", new ElectricResistance(1, ElectricResistanceUnit.Megaohm).ToString(swedishCulture)); Assert.Equal("1 µΩ", new ElectricResistance(1, ElectricResistanceUnit.Microohm).ToString(swedishCulture)); Assert.Equal("1 mΩ", new ElectricResistance(1, ElectricResistanceUnit.Milliohm).ToString(swedishCulture)); + Assert.Equal("1 nΩ", new ElectricResistance(1, ElectricResistanceUnit.Nanoohm).ToString(swedishCulture)); Assert.Equal("1 Ω", new ElectricResistance(1, ElectricResistanceUnit.Ohm).ToString(swedishCulture)); Assert.Equal("1 TΩ", new ElectricResistance(1, ElectricResistanceUnit.Teraohm).ToString(swedishCulture)); } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs new file mode 100644 index 0000000000..84a4ee42c7 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSusceptanceTestsBase.g.cs @@ -0,0 +1,1154 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of ElectricSusceptance. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class ElectricSusceptanceTestsBase : QuantityTestsBase + { + protected abstract double GigamhosInOneSiemens { get; } + protected abstract double GigasiemensInOneSiemens { get; } + protected abstract double KilomhosInOneSiemens { get; } + protected abstract double KilosiemensInOneSiemens { get; } + protected abstract double MegamhosInOneSiemens { get; } + protected abstract double MegasiemensInOneSiemens { get; } + protected abstract double MhosInOneSiemens { get; } + protected abstract double MicromhosInOneSiemens { get; } + protected abstract double MicrosiemensInOneSiemens { get; } + protected abstract double MillimhosInOneSiemens { get; } + protected abstract double MillisiemensInOneSiemens { get; } + protected abstract double NanomhosInOneSiemens { get; } + protected abstract double NanosiemensInOneSiemens { get; } + protected abstract double SiemensInOneSiemens { get; } + protected abstract double TeramhosInOneSiemens { get; } + protected abstract double TerasiemensInOneSiemens { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GigamhosTolerance { get { return 1e-5; } } + protected virtual double GigasiemensTolerance { get { return 1e-5; } } + protected virtual double KilomhosTolerance { get { return 1e-5; } } + protected virtual double KilosiemensTolerance { get { return 1e-5; } } + protected virtual double MegamhosTolerance { get { return 1e-5; } } + protected virtual double MegasiemensTolerance { get { return 1e-5; } } + protected virtual double MhosTolerance { get { return 1e-5; } } + protected virtual double MicromhosTolerance { get { return 1e-5; } } + protected virtual double MicrosiemensTolerance { get { return 1e-5; } } + protected virtual double MillimhosTolerance { get { return 1e-5; } } + protected virtual double MillisiemensTolerance { get { return 1e-5; } } + protected virtual double NanomhosTolerance { get { return 1e-5; } } + protected virtual double NanosiemensTolerance { get { return 1e-5; } } + protected virtual double SiemensTolerance { get { return 1e-5; } } + protected virtual double TeramhosTolerance { get { return 1e-5; } } + protected virtual double TerasiemensTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(ElectricSusceptanceUnit unit) + { + return unit switch + { + ElectricSusceptanceUnit.Gigamho => (GigamhosInOneSiemens, GigamhosTolerance), + ElectricSusceptanceUnit.Gigasiemens => (GigasiemensInOneSiemens, GigasiemensTolerance), + ElectricSusceptanceUnit.Kilomho => (KilomhosInOneSiemens, KilomhosTolerance), + ElectricSusceptanceUnit.Kilosiemens => (KilosiemensInOneSiemens, KilosiemensTolerance), + ElectricSusceptanceUnit.Megamho => (MegamhosInOneSiemens, MegamhosTolerance), + ElectricSusceptanceUnit.Megasiemens => (MegasiemensInOneSiemens, MegasiemensTolerance), + ElectricSusceptanceUnit.Mho => (MhosInOneSiemens, MhosTolerance), + ElectricSusceptanceUnit.Micromho => (MicromhosInOneSiemens, MicromhosTolerance), + ElectricSusceptanceUnit.Microsiemens => (MicrosiemensInOneSiemens, MicrosiemensTolerance), + ElectricSusceptanceUnit.Millimho => (MillimhosInOneSiemens, MillimhosTolerance), + ElectricSusceptanceUnit.Millisiemens => (MillisiemensInOneSiemens, MillisiemensTolerance), + ElectricSusceptanceUnit.Nanomho => (NanomhosInOneSiemens, NanomhosTolerance), + ElectricSusceptanceUnit.Nanosiemens => (NanosiemensInOneSiemens, NanosiemensTolerance), + ElectricSusceptanceUnit.Siemens => (SiemensInOneSiemens, SiemensTolerance), + ElectricSusceptanceUnit.Teramho => (TeramhosInOneSiemens, TeramhosTolerance), + ElectricSusceptanceUnit.Terasiemens => (TerasiemensInOneSiemens, TerasiemensTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { ElectricSusceptanceUnit.Gigamho }, + new object[] { ElectricSusceptanceUnit.Gigasiemens }, + new object[] { ElectricSusceptanceUnit.Kilomho }, + new object[] { ElectricSusceptanceUnit.Kilosiemens }, + new object[] { ElectricSusceptanceUnit.Megamho }, + new object[] { ElectricSusceptanceUnit.Megasiemens }, + new object[] { ElectricSusceptanceUnit.Mho }, + new object[] { ElectricSusceptanceUnit.Micromho }, + new object[] { ElectricSusceptanceUnit.Microsiemens }, + new object[] { ElectricSusceptanceUnit.Millimho }, + new object[] { ElectricSusceptanceUnit.Millisiemens }, + new object[] { ElectricSusceptanceUnit.Nanomho }, + new object[] { ElectricSusceptanceUnit.Nanosiemens }, + new object[] { ElectricSusceptanceUnit.Siemens }, + new object[] { ElectricSusceptanceUnit.Teramho }, + new object[] { ElectricSusceptanceUnit.Terasiemens }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new ElectricSusceptance(); + Assert.Equal(0, quantity.Value); + Assert.Equal(ElectricSusceptanceUnit.Siemens, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => new ElectricSusceptance(double.PositiveInfinity, ElectricSusceptanceUnit.Siemens)); + var exception2 = Record.Exception(() => new ElectricSusceptance(double.NegativeInfinity, ElectricSusceptanceUnit.Siemens)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void Ctor_WithNaNValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => new ElectricSusceptance(double.NaN, ElectricSusceptanceUnit.Siemens)); + + Assert.Null(exception); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new ElectricSusceptance(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new ElectricSusceptance(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (ElectricSusceptance) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void ElectricSusceptance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new ElectricSusceptance(1, ElectricSusceptanceUnit.Siemens); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(ElectricSusceptance.Zero, quantityInfo.Zero); + Assert.Equal("ElectricSusceptance", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void SiemensToElectricSusceptanceUnits() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + AssertEx.EqualTolerance(GigamhosInOneSiemens, siemens.Gigamhos, GigamhosTolerance); + AssertEx.EqualTolerance(GigasiemensInOneSiemens, siemens.Gigasiemens, GigasiemensTolerance); + AssertEx.EqualTolerance(KilomhosInOneSiemens, siemens.Kilomhos, KilomhosTolerance); + AssertEx.EqualTolerance(KilosiemensInOneSiemens, siemens.Kilosiemens, KilosiemensTolerance); + AssertEx.EqualTolerance(MegamhosInOneSiemens, siemens.Megamhos, MegamhosTolerance); + AssertEx.EqualTolerance(MegasiemensInOneSiemens, siemens.Megasiemens, MegasiemensTolerance); + AssertEx.EqualTolerance(MhosInOneSiemens, siemens.Mhos, MhosTolerance); + AssertEx.EqualTolerance(MicromhosInOneSiemens, siemens.Micromhos, MicromhosTolerance); + AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.Microsiemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(MillimhosInOneSiemens, siemens.Millimhos, MillimhosTolerance); + AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.Millisiemens, MillisiemensTolerance); + AssertEx.EqualTolerance(NanomhosInOneSiemens, siemens.Nanomhos, NanomhosTolerance); + AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.Nanosiemens, NanosiemensTolerance); + AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.Siemens, SiemensTolerance); + AssertEx.EqualTolerance(TeramhosInOneSiemens, siemens.Teramhos, TeramhosTolerance); + AssertEx.EqualTolerance(TerasiemensInOneSiemens, siemens.Terasiemens, TerasiemensTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Gigamho); + AssertEx.EqualTolerance(1, quantity00.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Gigamho, quantity00.Unit); + + var quantity01 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Gigasiemens); + AssertEx.EqualTolerance(1, quantity01.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, quantity01.Unit); + + var quantity02 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Kilomho); + AssertEx.EqualTolerance(1, quantity02.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Kilomho, quantity02.Unit); + + var quantity03 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Kilosiemens); + AssertEx.EqualTolerance(1, quantity03.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, quantity03.Unit); + + var quantity04 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Megamho); + AssertEx.EqualTolerance(1, quantity04.Megamhos, MegamhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Megamho, quantity04.Unit); + + var quantity05 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Megasiemens); + AssertEx.EqualTolerance(1, quantity05.Megasiemens, MegasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Megasiemens, quantity05.Unit); + + var quantity06 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Mho); + AssertEx.EqualTolerance(1, quantity06.Mhos, MhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Mho, quantity06.Unit); + + var quantity07 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Micromho); + AssertEx.EqualTolerance(1, quantity07.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Micromho, quantity07.Unit); + + var quantity08 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Microsiemens); + AssertEx.EqualTolerance(1, quantity08.Microsiemens, MicrosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Microsiemens, quantity08.Unit); + + var quantity09 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Millimho); + AssertEx.EqualTolerance(1, quantity09.Millimhos, MillimhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Millimho, quantity09.Unit); + + var quantity10 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Millisiemens); + AssertEx.EqualTolerance(1, quantity10.Millisiemens, MillisiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Millisiemens, quantity10.Unit); + + var quantity11 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Nanomho); + AssertEx.EqualTolerance(1, quantity11.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Nanomho, quantity11.Unit); + + var quantity12 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Nanosiemens); + AssertEx.EqualTolerance(1, quantity12.Nanosiemens, NanosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, quantity12.Unit); + + var quantity13 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Siemens); + AssertEx.EqualTolerance(1, quantity13.Siemens, SiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Siemens, quantity13.Unit); + + var quantity14 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Teramho); + AssertEx.EqualTolerance(1, quantity14.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Teramho, quantity14.Unit); + + var quantity15 = ElectricSusceptance.From(1, ElectricSusceptanceUnit.Terasiemens); + AssertEx.EqualTolerance(1, quantity15.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Terasiemens, quantity15.Unit); + + } + + [Fact] + public void FromSiemens_WithInfinityValue_DoNotThrowsArgumentException() + { + var exception1 = Record.Exception(() => ElectricSusceptance.FromSiemens(double.PositiveInfinity)); + var exception2 = Record.Exception(() => ElectricSusceptance.FromSiemens(double.NegativeInfinity)); + + Assert.Null(exception1); + Assert.Null(exception2); + } + + [Fact] + public void FromSiemens_WithNanValue_DoNotThrowsArgumentException() + { + var exception = Record.Exception(() => ElectricSusceptance.FromSiemens(double.NaN)); + + Assert.Null(exception); + } + + [Fact] + public void As() + { + var siemens = ElectricSusceptance.FromSiemens(1); + AssertEx.EqualTolerance(GigamhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Gigamho), GigamhosTolerance); + AssertEx.EqualTolerance(GigasiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Gigasiemens), GigasiemensTolerance); + AssertEx.EqualTolerance(KilomhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Kilomho), KilomhosTolerance); + AssertEx.EqualTolerance(KilosiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Kilosiemens), KilosiemensTolerance); + AssertEx.EqualTolerance(MegamhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Megamho), MegamhosTolerance); + AssertEx.EqualTolerance(MegasiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Megasiemens), MegasiemensTolerance); + AssertEx.EqualTolerance(MhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Mho), MhosTolerance); + AssertEx.EqualTolerance(MicromhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Micromho), MicromhosTolerance); + AssertEx.EqualTolerance(MicrosiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Microsiemens), MicrosiemensTolerance); + AssertEx.EqualTolerance(MillimhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Millimho), MillimhosTolerance); + AssertEx.EqualTolerance(MillisiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Millisiemens), MillisiemensTolerance); + AssertEx.EqualTolerance(NanomhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Nanomho), NanomhosTolerance); + AssertEx.EqualTolerance(NanosiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Nanosiemens), NanosiemensTolerance); + AssertEx.EqualTolerance(SiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Siemens), SiemensTolerance); + AssertEx.EqualTolerance(TeramhosInOneSiemens, siemens.As(ElectricSusceptanceUnit.Teramho), TeramhosTolerance); + AssertEx.EqualTolerance(TerasiemensInOneSiemens, siemens.As(ElectricSusceptanceUnit.Terasiemens), TerasiemensTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new ElectricSusceptance(value: 1, unit: ElectricSusceptance.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 = ElectricSusceptance.Parse("1 G℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Gigamho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 GS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 k℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Kilomho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 kS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 M℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megamhos, MegamhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Megamho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 MS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Megasiemens, MegasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Megasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 ℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Mho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 µ℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Micromho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 µS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Microsiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 m℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Millimhos, MillimhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Millimho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 mS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Millisiemens, MillisiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Millisiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 n℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Nanomho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 nS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 S", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Siemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 T℧", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Teramho, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = ElectricSusceptance.Parse("1 TS", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Terasiemens, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(ElectricSusceptance.TryParse("1 G℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigamhos, GigamhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Gigamho, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 GS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Gigasiemens, GigasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 k℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilomhos, KilomhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Kilomho, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 kS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Kilosiemens, KilosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Mhos, MhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Mho, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 µ℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Micromhos, MicromhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Micromho, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 µS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Microsiemens, MicrosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Microsiemens, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 n℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanomhos, NanomhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Nanomho, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 nS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Nanosiemens, NanosiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 S", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Siemens, SiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Siemens, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 T℧", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Teramhos, TeramhosTolerance); + Assert.Equal(ElectricSusceptanceUnit.Teramho, parsed.Unit); + } + + { + Assert.True(ElectricSusceptance.TryParse("1 TS", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Terasiemens, TerasiemensTolerance); + Assert.Equal(ElectricSusceptanceUnit.Terasiemens, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("G℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Gigamho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("GS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("k℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Kilomho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("kS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("M℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Megamho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("MS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Megasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Mho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("µ℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Micromho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("µS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Microsiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("m℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Millimho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("mS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Millisiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("n℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Nanomho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("nS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("S", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Siemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("T℧", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Teramho, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = ElectricSusceptance.ParseUnit("TS", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(ElectricSusceptanceUnit.Terasiemens, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(ElectricSusceptance.TryParseUnit("G℧", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Gigamho, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("GS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Gigasiemens, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("k℧", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Kilomho, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("kS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Kilosiemens, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("℧", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Mho, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("µ℧", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Micromho, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("µS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Microsiemens, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("n℧", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Nanomho, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("nS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Nanosiemens, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Siemens, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("T℧", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Teramho, parsedUnit); + } + + { + Assert.True(ElectricSusceptance.TryParseUnit("TS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(ElectricSusceptanceUnit.Terasiemens, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(ElectricSusceptanceUnit unit) + { + var inBaseUnits = ElectricSusceptance.From(1.0, ElectricSusceptance.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(ElectricSusceptanceUnit unit) + { + var quantity = ElectricSusceptance.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(ElectricSusceptanceUnit 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 = ElectricSusceptance.Units.First(u => u != ElectricSusceptance.BaseUnit); + + var quantity = ElectricSusceptance.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(ElectricSusceptanceUnit unit) + { + var quantity = default(ElectricSusceptance); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromGigamhos(siemens.Gigamhos).Siemens, GigamhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromGigasiemens(siemens.Gigasiemens).Siemens, GigasiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromKilomhos(siemens.Kilomhos).Siemens, KilomhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromKilosiemens(siemens.Kilosiemens).Siemens, KilosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMegamhos(siemens.Megamhos).Siemens, MegamhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMegasiemens(siemens.Megasiemens).Siemens, MegasiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMhos(siemens.Mhos).Siemens, MhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMicromhos(siemens.Micromhos).Siemens, MicromhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMicrosiemens(siemens.Microsiemens).Siemens, MicrosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMillimhos(siemens.Millimhos).Siemens, MillimhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromMillisiemens(siemens.Millisiemens).Siemens, MillisiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromNanomhos(siemens.Nanomhos).Siemens, NanomhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromNanosiemens(siemens.Nanosiemens).Siemens, NanosiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromSiemens(siemens.Siemens).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromTeramhos(siemens.Teramhos).Siemens, TeramhosTolerance); + AssertEx.EqualTolerance(1, ElectricSusceptance.FromTerasiemens(siemens.Terasiemens).Siemens, TerasiemensTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + ElectricSusceptance v = ElectricSusceptance.FromSiemens(1); + AssertEx.EqualTolerance(-1, -v.Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, (ElectricSusceptance.FromSiemens(3)-v).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, (v + v).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(10, (v*10).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(10, (10*v).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, (ElectricSusceptance.FromSiemens(10)/5).Siemens, SiemensTolerance); + AssertEx.EqualTolerance(2, ElectricSusceptance.FromSiemens(10)/ElectricSusceptance.FromSiemens(5), SiemensTolerance); + } + + [Fact] + public void ComparisonOperators() + { + ElectricSusceptance oneSiemens = ElectricSusceptance.FromSiemens(1); + ElectricSusceptance twoSiemens = ElectricSusceptance.FromSiemens(2); + + Assert.True(oneSiemens < twoSiemens); + Assert.True(oneSiemens <= twoSiemens); + Assert.True(twoSiemens > oneSiemens); + Assert.True(twoSiemens >= oneSiemens); + + Assert.False(oneSiemens > twoSiemens); + Assert.False(oneSiemens >= twoSiemens); + Assert.False(twoSiemens < oneSiemens); + Assert.False(twoSiemens <= oneSiemens); + } + + [Fact] + public void CompareToIsImplemented() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + Assert.Equal(0, siemens.CompareTo(siemens)); + Assert.True(siemens.CompareTo(ElectricSusceptance.Zero) > 0); + Assert.True(ElectricSusceptance.Zero.CompareTo(siemens) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + Assert.Throws(() => siemens.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + Assert.Throws(() => siemens.CompareTo(null)); + } + + [Theory] + [InlineData(1, ElectricSusceptanceUnit.Siemens, 1, ElectricSusceptanceUnit.Siemens, true)] // Same value and unit. + [InlineData(1, ElectricSusceptanceUnit.Siemens, 2, ElectricSusceptanceUnit.Siemens, false)] // Different value. + [InlineData(2, ElectricSusceptanceUnit.Siemens, 1, ElectricSusceptanceUnit.Gigamho, false)] // Different value and unit. + [InlineData(1, ElectricSusceptanceUnit.Siemens, 1, ElectricSusceptanceUnit.Gigamho, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, ElectricSusceptanceUnit unitA, double valueB, ElectricSusceptanceUnit unitB, bool expectEqual) + { + var a = new ElectricSusceptance(valueA, unitA); + var b = new ElectricSusceptance(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 = ElectricSusceptance.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 = ElectricSusceptance.FromSiemens(1); + Assert.True(v.Equals(ElectricSusceptance.FromSiemens(1), SiemensTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(ElectricSusceptance.Zero, SiemensTolerance, ComparisonType.Relative)); + Assert.True(ElectricSusceptance.FromSiemens(100).Equals(ElectricSusceptance.FromSiemens(120), 0.3, ComparisonType.Relative)); + Assert.False(ElectricSusceptance.FromSiemens(100).Equals(ElectricSusceptance.FromSiemens(120), 0.1, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = ElectricSusceptance.FromSiemens(1); + Assert.Throws(() => v.Equals(ElectricSusceptance.FromSiemens(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + Assert.False(siemens.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + ElectricSusceptance siemens = ElectricSusceptance.FromSiemens(1); + Assert.False(siemens.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(ElectricSusceptanceUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(ElectricSusceptance.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 G℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Gigamho).ToString()); + Assert.Equal("1 GS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Gigasiemens).ToString()); + Assert.Equal("1 k℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Kilomho).ToString()); + Assert.Equal("1 kS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Kilosiemens).ToString()); + Assert.Equal("1 M℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Megamho).ToString()); + Assert.Equal("1 MS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Megasiemens).ToString()); + Assert.Equal("1 ℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Mho).ToString()); + Assert.Equal("1 µ℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Micromho).ToString()); + Assert.Equal("1 µS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Microsiemens).ToString()); + Assert.Equal("1 m℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Millimho).ToString()); + Assert.Equal("1 mS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Millisiemens).ToString()); + Assert.Equal("1 n℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Nanomho).ToString()); + Assert.Equal("1 nS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Nanosiemens).ToString()); + Assert.Equal("1 S", new ElectricSusceptance(1, ElectricSusceptanceUnit.Siemens).ToString()); + Assert.Equal("1 T℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Teramho).ToString()); + Assert.Equal("1 TS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Terasiemens).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 G℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Gigamho).ToString(swedishCulture)); + Assert.Equal("1 GS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Gigasiemens).ToString(swedishCulture)); + Assert.Equal("1 k℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Kilomho).ToString(swedishCulture)); + Assert.Equal("1 kS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Kilosiemens).ToString(swedishCulture)); + Assert.Equal("1 M℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Megamho).ToString(swedishCulture)); + Assert.Equal("1 MS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Megasiemens).ToString(swedishCulture)); + Assert.Equal("1 ℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Mho).ToString(swedishCulture)); + Assert.Equal("1 µ℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Micromho).ToString(swedishCulture)); + Assert.Equal("1 µS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Microsiemens).ToString(swedishCulture)); + Assert.Equal("1 m℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Millimho).ToString(swedishCulture)); + Assert.Equal("1 mS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Millisiemens).ToString(swedishCulture)); + Assert.Equal("1 n℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Nanomho).ToString(swedishCulture)); + Assert.Equal("1 nS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Nanosiemens).ToString(swedishCulture)); + Assert.Equal("1 S", new ElectricSusceptance(1, ElectricSusceptanceUnit.Siemens).ToString(swedishCulture)); + Assert.Equal("1 T℧", new ElectricSusceptance(1, ElectricSusceptanceUnit.Teramho).ToString(swedishCulture)); + Assert.Equal("1 TS", new ElectricSusceptance(1, ElectricSusceptanceUnit.Terasiemens).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s1")); + Assert.Equal("0.12 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s2")); + Assert.Equal("0.123 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s3")); + Assert.Equal("0.1235 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s1", culture)); + Assert.Equal("0.12 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s2", culture)); + Assert.Equal("0.123 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s3", culture)); + Assert.Equal("0.1235 S", new ElectricSusceptance(0.123456, ElectricSusceptanceUnit.Siemens).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = ElectricSusceptance.FromSiemens(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 = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(ElectricSusceptance))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(ElectricSusceptanceUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(ElectricSusceptance.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(ElectricSusceptance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = ElectricSusceptance.FromSiemens(1.0); + Assert.Equal(new {ElectricSusceptance.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 = ElectricSusceptance.FromSiemens(value); + Assert.Equal(ElectricSusceptance.FromSiemens(-value), -quantity); + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs index b152d7afee..b05273ec5f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs @@ -38,6 +38,10 @@ 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. /// + /// + /// has been renamed to , 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 : diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs index a3afb1bb30..3ff9f5fc4e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs @@ -38,6 +38,10 @@ 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. /// + /// + /// has been renamed to , 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 : diff --git a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs index e78ba83ff3..045469b97f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs @@ -39,8 +39,9 @@ namespace UnitsNet /// Capacitance is the ability of a body to store an electric charge. /// /// - /// https://en.wikipedia.org/wiki/Capacitance + /// has been renamed to , 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 : diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs index 2f00a7b59b..5c2f91fa6a 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -36,8 +36,12 @@ namespace UnitsNet { /// /// - /// Electric admittance is a measure of how easily a circuit or device will allow a current to flow. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S). + /// Electric admittance is a measure of how easily a circuit or device will allow a current to flow by the combined effect of conductance and susceptance in a circuit. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S). /// + /// + /// https://en.wikipedia.org/wiki/Electrical_admittance + /// + [Obsolete("Admittance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricConductance or ElectricSusceptance instead.")] [DataContract] [DebuggerTypeProxy(typeof(QuantityDisplay))] public readonly partial struct ElectricAdmittance : @@ -73,10 +77,22 @@ static ElectricAdmittance() Info = new QuantityInfo("ElectricAdmittance", new UnitInfo[] { + new UnitInfo(ElectricAdmittanceUnit.Gigamho, "Gigamhos", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Gigasiemens, "Gigasiemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Kilomho, "Kilomhos", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Kilosiemens, "Kilosiemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Megamho, "Megamhos", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Megasiemens, "Megasiemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Mho, "Mhos", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Micromho, "Micromhos", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Microsiemens, "Microsiemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Millimho, "Millimhos", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Nanosiemens, "Nanosiemens", BaseUnits.Undefined, "ElectricAdmittance"), new UnitInfo(ElectricAdmittanceUnit.Siemens, "Siemens", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricAdmittance"), + new UnitInfo(ElectricAdmittanceUnit.Terasiemens, "Terasiemens", BaseUnits.Undefined, "ElectricAdmittance"), }, BaseUnit, Zero, BaseDimensions); @@ -179,16 +195,66 @@ public ElectricAdmittance(double value, UnitSystem unitSystem) #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Gigamhos => As(ElectricAdmittanceUnit.Gigamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Gigasiemens => As(ElectricAdmittanceUnit.Gigasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilomhos => As(ElectricAdmittanceUnit.Kilomho); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilosiemens => As(ElectricAdmittanceUnit.Kilosiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Megamhos => As(ElectricAdmittanceUnit.Megamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Megasiemens => As(ElectricAdmittanceUnit.Megasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Mhos => As(ElectricAdmittanceUnit.Mho); + + /// + /// Gets a value of this quantity converted into + /// + public double Micromhos => As(ElectricAdmittanceUnit.Micromho); + /// /// Gets a value of this quantity converted into /// public double Microsiemens => As(ElectricAdmittanceUnit.Microsiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Millimhos => As(ElectricAdmittanceUnit.Millimho); + /// /// Gets a value of this quantity converted into /// public double Millisiemens => As(ElectricAdmittanceUnit.Millisiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Nanomhos => As(ElectricAdmittanceUnit.Nanomho); + /// /// Gets a value of this quantity converted into /// @@ -199,6 +265,16 @@ public ElectricAdmittance(double value, UnitSystem unitSystem) /// public double Siemens => As(ElectricAdmittanceUnit.Siemens); + /// + /// Gets a value of this quantity converted into + /// + public double Teramhos => As(ElectricAdmittanceUnit.Teramho); + + /// + /// Gets a value of this quantity converted into + /// + public double Terasiemens => As(ElectricAdmittanceUnit.Terasiemens); + #endregion #region Static Methods @@ -210,17 +286,41 @@ public ElectricAdmittance(double value, UnitSystem unitSystem) internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: ElectricAdmittanceUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Gigamho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Gigasiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Kilomho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Kilosiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Megamho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Megasiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Mho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Micromho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Microsiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Millimho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Millisiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Nanomho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Nanosiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Teramho, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Terasiemens, ElectricAdmittanceUnit.Siemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Siemens)); // Register in unit converter: BaseUnit <-> BaseUnit unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Siemens, quantity => quantity); // Register in unit converter: BaseUnit -> ElectricAdmittanceUnit + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Gigamho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Gigamho)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Gigasiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Gigasiemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Kilomho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Kilomho)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Kilosiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Kilosiemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Megamho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Megamho)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Megasiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Megasiemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Mho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Mho)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Micromho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Micromho)); unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Microsiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Microsiemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Millimho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Millimho)); unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Millisiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Millisiemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Nanomho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Nanomho)); unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Nanosiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Nanosiemens)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Teramho, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Teramho)); + unitConverter.SetConversionFunction(ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Terasiemens, quantity => quantity.ToUnit(ElectricAdmittanceUnit.Terasiemens)); } /// @@ -248,6 +348,70 @@ public static string GetAbbreviation(ElectricAdmittanceUnit unit, IFormatProvide #region Static Factory Methods + /// + /// Creates a from . + /// + public static ElectricAdmittance FromGigamhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Gigamho); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromGigasiemens(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Gigasiemens); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromKilomhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Kilomho); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromKilosiemens(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Kilosiemens); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMegamhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Megamho); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMegasiemens(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Megasiemens); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Mho); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMicromhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Micromho); + } + /// /// Creates a from . /// @@ -256,6 +420,14 @@ public static ElectricAdmittance FromMicrosiemens(double value) return new ElectricAdmittance(value, ElectricAdmittanceUnit.Microsiemens); } + /// + /// Creates a from . + /// + public static ElectricAdmittance FromMillimhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Millimho); + } + /// /// Creates a from . /// @@ -264,6 +436,14 @@ public static ElectricAdmittance FromMillisiemens(double value) return new ElectricAdmittance(value, ElectricAdmittanceUnit.Millisiemens); } + /// + /// Creates a from . + /// + public static ElectricAdmittance FromNanomhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Nanomho); + } + /// /// Creates a from . /// @@ -280,6 +460,22 @@ public static ElectricAdmittance FromSiemens(double value) return new ElectricAdmittance(value, ElectricAdmittanceUnit.Siemens); } + /// + /// Creates a from . + /// + public static ElectricAdmittance FromTeramhos(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Teramho); + } + + /// + /// Creates a from . + /// + public static ElectricAdmittance FromTerasiemens(double value) + { + return new ElectricAdmittance(value, ElectricAdmittanceUnit.Terasiemens); + } + /// /// Dynamically convert from value and unit enum to . /// @@ -764,14 +960,38 @@ private bool TryToUnit(ElectricAdmittanceUnit unit, [NotNullWhen(true)] out Elec ElectricAdmittance? convertedOrNull = (Unit, unit) switch { // ElectricAdmittanceUnit -> BaseUnit + (ElectricAdmittanceUnit.Gigamho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e9d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Gigasiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e9d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Kilomho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e3d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Kilosiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e3d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Megamho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e6d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Megasiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e6d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Mho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance(_value, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Micromho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e-6d, ElectricAdmittanceUnit.Siemens), (ElectricAdmittanceUnit.Microsiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e-6d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Millimho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e-3d, ElectricAdmittanceUnit.Siemens), (ElectricAdmittanceUnit.Millisiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e-3d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Nanomho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e-9d, ElectricAdmittanceUnit.Siemens), (ElectricAdmittanceUnit.Nanosiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e-9d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Teramho, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e12d, ElectricAdmittanceUnit.Siemens), + (ElectricAdmittanceUnit.Terasiemens, ElectricAdmittanceUnit.Siemens) => new ElectricAdmittance((_value) * 1e12d, ElectricAdmittanceUnit.Siemens), // BaseUnit -> ElectricAdmittanceUnit + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Gigamho) => new ElectricAdmittance((_value) / 1e9d, ElectricAdmittanceUnit.Gigamho), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Gigasiemens) => new ElectricAdmittance((_value) / 1e9d, ElectricAdmittanceUnit.Gigasiemens), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Kilomho) => new ElectricAdmittance((_value) / 1e3d, ElectricAdmittanceUnit.Kilomho), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Kilosiemens) => new ElectricAdmittance((_value) / 1e3d, ElectricAdmittanceUnit.Kilosiemens), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Megamho) => new ElectricAdmittance((_value) / 1e6d, ElectricAdmittanceUnit.Megamho), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Megasiemens) => new ElectricAdmittance((_value) / 1e6d, ElectricAdmittanceUnit.Megasiemens), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Mho) => new ElectricAdmittance(_value, ElectricAdmittanceUnit.Mho), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Micromho) => new ElectricAdmittance((_value) / 1e-6d, ElectricAdmittanceUnit.Micromho), (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Microsiemens) => new ElectricAdmittance((_value) / 1e-6d, ElectricAdmittanceUnit.Microsiemens), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Millimho) => new ElectricAdmittance((_value) / 1e-3d, ElectricAdmittanceUnit.Millimho), (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Millisiemens) => new ElectricAdmittance((_value) / 1e-3d, ElectricAdmittanceUnit.Millisiemens), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Nanomho) => new ElectricAdmittance((_value) / 1e-9d, ElectricAdmittanceUnit.Nanomho), (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Nanosiemens) => new ElectricAdmittance((_value) / 1e-9d, ElectricAdmittanceUnit.Nanosiemens), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Teramho) => new ElectricAdmittance((_value) / 1e12d, ElectricAdmittanceUnit.Teramho), + (ElectricAdmittanceUnit.Siemens, ElectricAdmittanceUnit.Terasiemens) => new ElectricAdmittance((_value) / 1e12d, ElectricAdmittanceUnit.Terasiemens), _ => null }; diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs new file mode 100644 index 0000000000..e2c293414c --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs @@ -0,0 +1,950 @@ +//------------------------------------------------------------------------------ +// +// 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. + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricApparentEnergy : + 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 ElectricApparentEnergyUnit? _unit; + + static ElectricApparentEnergy() + { + BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); + BaseUnit = ElectricApparentEnergyUnit.VoltampereHour; + Units = Enum.GetValues(typeof(ElectricApparentEnergyUnit)).Cast().ToArray(); + Zero = new ElectricApparentEnergy(0, BaseUnit); + Info = new QuantityInfo("ElectricApparentEnergy", + new UnitInfo[] + { + new UnitInfo(ElectricApparentEnergyUnit.KilovoltampereHour, "KilovoltampereHours", BaseUnits.Undefined, "ElectricApparentEnergy"), + new UnitInfo(ElectricApparentEnergyUnit.MegavoltampereHour, "MegavoltampereHours", BaseUnits.Undefined, "ElectricApparentEnergy"), + new UnitInfo(ElectricApparentEnergyUnit.VoltampereHour, "VoltampereHours", BaseUnits.Undefined, "ElectricApparentEnergy"), + }, + 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 ElectricApparentEnergy(double value, ElectricApparentEnergyUnit 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 ElectricApparentEnergy(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 ElectricApparentEnergy, which is VoltampereHour. All conversions go via this value. + /// + public static ElectricApparentEnergyUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricApparentEnergy quantity. + /// + public static ElectricApparentEnergyUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereHour. + /// + public static ElectricApparentEnergy Zero { get; } + + /// + public static ElectricApparentEnergy 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 ElectricApparentEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricApparentEnergy.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilovoltampereHours => As(ElectricApparentEnergyUnit.KilovoltampereHour); + + /// + /// Gets a value of this quantity converted into + /// + public double MegavoltampereHours => As(ElectricApparentEnergyUnit.MegavoltampereHour); + + /// + /// Gets a value of this quantity converted into + /// + public double VoltampereHours => As(ElectricApparentEnergyUnit.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: ElectricApparentEnergyUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricApparentEnergyUnit.KilovoltampereHour, ElectricApparentEnergyUnit.VoltampereHour, quantity => quantity.ToUnit(ElectricApparentEnergyUnit.VoltampereHour)); + unitConverter.SetConversionFunction(ElectricApparentEnergyUnit.MegavoltampereHour, ElectricApparentEnergyUnit.VoltampereHour, quantity => quantity.ToUnit(ElectricApparentEnergyUnit.VoltampereHour)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricApparentEnergyUnit.VoltampereHour, ElectricApparentEnergyUnit.VoltampereHour, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricApparentEnergyUnit + unitConverter.SetConversionFunction(ElectricApparentEnergyUnit.VoltampereHour, ElectricApparentEnergyUnit.KilovoltampereHour, quantity => quantity.ToUnit(ElectricApparentEnergyUnit.KilovoltampereHour)); + unitConverter.SetConversionFunction(ElectricApparentEnergyUnit.VoltampereHour, ElectricApparentEnergyUnit.MegavoltampereHour, quantity => quantity.ToUnit(ElectricApparentEnergyUnit.MegavoltampereHour)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricApparentEnergyUnit 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(ElectricApparentEnergyUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricApparentEnergy FromKilovoltampereHours(double value) + { + return new ElectricApparentEnergy(value, ElectricApparentEnergyUnit.KilovoltampereHour); + } + + /// + /// Creates a from . + /// + public static ElectricApparentEnergy FromMegavoltampereHours(double value) + { + return new ElectricApparentEnergy(value, ElectricApparentEnergyUnit.MegavoltampereHour); + } + + /// + /// Creates a from . + /// + public static ElectricApparentEnergy FromVoltampereHours(double value) + { + return new ElectricApparentEnergy(value, ElectricApparentEnergyUnit.VoltampereHour); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricApparentEnergy unit value. + public static ElectricApparentEnergy From(double value, ElectricApparentEnergyUnit fromUnit) + { + return new ElectricApparentEnergy(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 ElectricApparentEnergy 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 ElectricApparentEnergy Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricApparentEnergy 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 ElectricApparentEnergy result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricApparentEnergyUnit 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 ElectricApparentEnergyUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricApparentEnergyUnit 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 ElectricApparentEnergyUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricApparentEnergy operator -(ElectricApparentEnergy right) + { + return new ElectricApparentEnergy(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricApparentEnergy operator +(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return new ElectricApparentEnergy(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricApparentEnergy operator -(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return new ElectricApparentEnergy(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricApparentEnergy operator *(double left, ElectricApparentEnergy right) + { + return new ElectricApparentEnergy(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricApparentEnergy operator *(ElectricApparentEnergy left, double right) + { + return new ElectricApparentEnergy(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricApparentEnergy operator /(ElectricApparentEnergy left, double right) + { + return new ElectricApparentEnergy(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return left.VoltampereHours / right.VoltampereHours; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricApparentEnergy left, ElectricApparentEnergy 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(ElectricApparentEnergy other, ElectricApparentEnergy 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 ==(ElectricApparentEnergy left, ElectricApparentEnergy 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(ElectricApparentEnergy other, ElectricApparentEnergy 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 !=(ElectricApparentEnergy left, ElectricApparentEnergy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricApparentEnergy other, ElectricApparentEnergy 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 ElectricApparentEnergy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricApparentEnergy other, ElectricApparentEnergy 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(ElectricApparentEnergy 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 ElectricApparentEnergy otherQuantity)) throw new ArgumentException("Expected type ElectricApparentEnergy.", 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(ElectricApparentEnergy other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricApparentEnergy 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(ElectricApparentEnergy other, ElectricApparentEnergy 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(ElectricApparentEnergy 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 ElectricApparentEnergy otherTyped + && (tolerance is ElectricApparentEnergy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricApparentEnergy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricApparentEnergy other, ElectricApparentEnergy 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 ElectricApparentEnergy. + 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(ElectricApparentEnergyUnit 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 ElectricApparentEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentEnergyUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricApparentEnergy to another ElectricApparentEnergy with the unit representation . + /// + /// The unit to convert to. + /// A ElectricApparentEnergy with the specified unit. + public ElectricApparentEnergy ToUnit(ElectricApparentEnergyUnit 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 ElectricApparentEnergy with the specified unit. + public ElectricApparentEnergy ToUnit(ElectricApparentEnergyUnit 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(ElectricApparentEnergy), Unit, typeof(ElectricApparentEnergy), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricApparentEnergy)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(ElectricApparentEnergyUnit unit, [NotNullWhen(true)] out ElectricApparentEnergy? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricApparentEnergy? convertedOrNull = (Unit, unit) switch + { + // ElectricApparentEnergyUnit -> BaseUnit + (ElectricApparentEnergyUnit.KilovoltampereHour, ElectricApparentEnergyUnit.VoltampereHour) => new ElectricApparentEnergy((_value) * 1e3d, ElectricApparentEnergyUnit.VoltampereHour), + (ElectricApparentEnergyUnit.MegavoltampereHour, ElectricApparentEnergyUnit.VoltampereHour) => new ElectricApparentEnergy((_value) * 1e6d, ElectricApparentEnergyUnit.VoltampereHour), + + // BaseUnit -> ElectricApparentEnergyUnit + (ElectricApparentEnergyUnit.VoltampereHour, ElectricApparentEnergyUnit.KilovoltampereHour) => new ElectricApparentEnergy((_value) / 1e3d, ElectricApparentEnergyUnit.KilovoltampereHour), + (ElectricApparentEnergyUnit.VoltampereHour, ElectricApparentEnergyUnit.MegavoltampereHour) => new ElectricApparentEnergy((_value) / 1e6d, ElectricApparentEnergyUnit.MegavoltampereHour), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricApparentEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentEnergyUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricApparentEnergy 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(ElectricApparentEnergyUnit 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(ElectricApparentEnergy)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricApparentEnergy)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricApparentEnergy)} 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(ElectricApparentEnergy)) + return this; + else if (conversionType == typeof(ElectricApparentEnergyUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricApparentEnergy.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricApparentEnergy.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricApparentEnergy)} 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/ElectricApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs new file mode 100644 index 0000000000..24fd77fa74 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs @@ -0,0 +1,1007 @@ +//------------------------------------------------------------------------------ +// +// 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. It is the product of the root mean square voltage (in volts) and the root mean square current (in amperes). + /// + /// + /// https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricApparentPower : + 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 ElectricApparentPowerUnit? _unit; + + static ElectricApparentPower() + { + BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + BaseUnit = ElectricApparentPowerUnit.Voltampere; + Units = Enum.GetValues(typeof(ElectricApparentPowerUnit)).Cast().ToArray(); + Zero = new ElectricApparentPower(0, BaseUnit); + Info = new QuantityInfo("ElectricApparentPower", + new UnitInfo[] + { + new UnitInfo(ElectricApparentPowerUnit.Gigavoltampere, "Gigavoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + new UnitInfo(ElectricApparentPowerUnit.Kilovoltampere, "Kilovoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + new UnitInfo(ElectricApparentPowerUnit.Megavoltampere, "Megavoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + new UnitInfo(ElectricApparentPowerUnit.Microvoltampere, "Microvoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + new UnitInfo(ElectricApparentPowerUnit.Millivoltampere, "Millivoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + new UnitInfo(ElectricApparentPowerUnit.Voltampere, "Voltamperes", BaseUnits.Undefined, "ElectricApparentPower"), + }, + 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 ElectricApparentPower(double value, ElectricApparentPowerUnit 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 ElectricApparentPower(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 ElectricApparentPower, which is Voltampere. All conversions go via this value. + /// + public static ElectricApparentPowerUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricApparentPower quantity. + /// + public static ElectricApparentPowerUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Voltampere. + /// + public static ElectricApparentPower Zero { get; } + + /// + public static ElectricApparentPower 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 ElectricApparentPowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricApparentPower.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigavoltamperes => As(ElectricApparentPowerUnit.Gigavoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilovoltamperes => As(ElectricApparentPowerUnit.Kilovoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Megavoltamperes => As(ElectricApparentPowerUnit.Megavoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Microvoltamperes => As(ElectricApparentPowerUnit.Microvoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Millivoltamperes => As(ElectricApparentPowerUnit.Millivoltampere); + + /// + /// Gets a value of this quantity converted into + /// + public double Voltamperes => As(ElectricApparentPowerUnit.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: ElectricApparentPowerUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Gigavoltampere, ElectricApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Voltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Kilovoltampere, ElectricApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Voltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Megavoltampere, ElectricApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Voltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Microvoltampere, ElectricApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Voltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Millivoltampere, ElectricApparentPowerUnit.Voltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Voltampere)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Voltampere, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricApparentPowerUnit + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Gigavoltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Gigavoltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Kilovoltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Kilovoltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Megavoltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Megavoltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Microvoltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Microvoltampere)); + unitConverter.SetConversionFunction(ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Millivoltampere, quantity => quantity.ToUnit(ElectricApparentPowerUnit.Millivoltampere)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricApparentPowerUnit 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(ElectricApparentPowerUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromGigavoltamperes(double value) + { + return new ElectricApparentPower(value, ElectricApparentPowerUnit.Gigavoltampere); + } + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromKilovoltamperes(double value) + { + return new ElectricApparentPower(value, ElectricApparentPowerUnit.Kilovoltampere); + } + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromMegavoltamperes(double value) + { + return new ElectricApparentPower(value, ElectricApparentPowerUnit.Megavoltampere); + } + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromMicrovoltamperes(double value) + { + return new ElectricApparentPower(value, ElectricApparentPowerUnit.Microvoltampere); + } + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromMillivoltamperes(double value) + { + return new ElectricApparentPower(value, ElectricApparentPowerUnit.Millivoltampere); + } + + /// + /// Creates a from . + /// + public static ElectricApparentPower FromVoltamperes(double value) + { + return new ElectricApparentPower(value, ElectricApparentPowerUnit.Voltampere); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricApparentPower unit value. + public static ElectricApparentPower From(double value, ElectricApparentPowerUnit fromUnit) + { + return new ElectricApparentPower(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 ElectricApparentPower 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 ElectricApparentPower Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricApparentPower 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 ElectricApparentPower result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricApparentPowerUnit 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 ElectricApparentPowerUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricApparentPowerUnit 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 ElectricApparentPowerUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricApparentPower operator -(ElectricApparentPower right) + { + return new ElectricApparentPower(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricApparentPower operator +(ElectricApparentPower left, ElectricApparentPower right) + { + return new ElectricApparentPower(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricApparentPower operator -(ElectricApparentPower left, ElectricApparentPower right) + { + return new ElectricApparentPower(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricApparentPower operator *(double left, ElectricApparentPower right) + { + return new ElectricApparentPower(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricApparentPower operator *(ElectricApparentPower left, double right) + { + return new ElectricApparentPower(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricApparentPower operator /(ElectricApparentPower left, double right) + { + return new ElectricApparentPower(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricApparentPower left, ElectricApparentPower right) + { + return left.Voltamperes / right.Voltamperes; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricApparentPower left, ElectricApparentPower right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricApparentPower left, ElectricApparentPower right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricApparentPower left, ElectricApparentPower right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricApparentPower left, ElectricApparentPower 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(ElectricApparentPower other, ElectricApparentPower 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 ==(ElectricApparentPower left, ElectricApparentPower 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(ElectricApparentPower other, ElectricApparentPower 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 !=(ElectricApparentPower left, ElectricApparentPower right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricApparentPower other, ElectricApparentPower 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 ElectricApparentPower otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricApparentPower other, ElectricApparentPower 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(ElectricApparentPower 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 ElectricApparentPower otherQuantity)) throw new ArgumentException("Expected type ElectricApparentPower.", 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(ElectricApparentPower other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricApparentPower 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(ElectricApparentPower other, ElectricApparentPower 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(ElectricApparentPower 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 ElectricApparentPower otherTyped + && (tolerance is ElectricApparentPower toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricApparentPower'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricApparentPower other, ElectricApparentPower 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 ElectricApparentPower. + 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(ElectricApparentPowerUnit 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 ElectricApparentPowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentPowerUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricApparentPower to another ElectricApparentPower with the unit representation . + /// + /// The unit to convert to. + /// A ElectricApparentPower with the specified unit. + public ElectricApparentPower ToUnit(ElectricApparentPowerUnit 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 ElectricApparentPower with the specified unit. + public ElectricApparentPower ToUnit(ElectricApparentPowerUnit 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(ElectricApparentPower), Unit, typeof(ElectricApparentPower), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricApparentPower)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(ElectricApparentPowerUnit unit, [NotNullWhen(true)] out ElectricApparentPower? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricApparentPower? convertedOrNull = (Unit, unit) switch + { + // ElectricApparentPowerUnit -> BaseUnit + (ElectricApparentPowerUnit.Gigavoltampere, ElectricApparentPowerUnit.Voltampere) => new ElectricApparentPower((_value) * 1e9d, ElectricApparentPowerUnit.Voltampere), + (ElectricApparentPowerUnit.Kilovoltampere, ElectricApparentPowerUnit.Voltampere) => new ElectricApparentPower((_value) * 1e3d, ElectricApparentPowerUnit.Voltampere), + (ElectricApparentPowerUnit.Megavoltampere, ElectricApparentPowerUnit.Voltampere) => new ElectricApparentPower((_value) * 1e6d, ElectricApparentPowerUnit.Voltampere), + (ElectricApparentPowerUnit.Microvoltampere, ElectricApparentPowerUnit.Voltampere) => new ElectricApparentPower((_value) * 1e-6d, ElectricApparentPowerUnit.Voltampere), + (ElectricApparentPowerUnit.Millivoltampere, ElectricApparentPowerUnit.Voltampere) => new ElectricApparentPower((_value) * 1e-3d, ElectricApparentPowerUnit.Voltampere), + + // BaseUnit -> ElectricApparentPowerUnit + (ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Gigavoltampere) => new ElectricApparentPower((_value) / 1e9d, ElectricApparentPowerUnit.Gigavoltampere), + (ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Kilovoltampere) => new ElectricApparentPower((_value) / 1e3d, ElectricApparentPowerUnit.Kilovoltampere), + (ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Megavoltampere) => new ElectricApparentPower((_value) / 1e6d, ElectricApparentPowerUnit.Megavoltampere), + (ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Microvoltampere) => new ElectricApparentPower((_value) / 1e-6d, ElectricApparentPowerUnit.Microvoltampere), + (ElectricApparentPowerUnit.Voltampere, ElectricApparentPowerUnit.Millivoltampere) => new ElectricApparentPower((_value) / 1e-3d, ElectricApparentPowerUnit.Millivoltampere), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricApparentPowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricApparentPowerUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricApparentPower 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(ElectricApparentPowerUnit 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(ElectricApparentPower)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricApparentPower)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricApparentPower)} 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(ElectricApparentPower)) + return this; + else if (conversionType == typeof(ElectricApparentPowerUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricApparentPower.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricApparentPower.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricApparentPower)} 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/ElectricCapacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs new file mode 100644 index 0000000000..dbd678e9bd --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs @@ -0,0 +1,1025 @@ +//------------------------------------------------------------------------------ +// +// 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 capacity of a material object or device to store electric charge. + /// + /// + /// https://en.wikipedia.org/wiki/Capacitance + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricCapacitance : + 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 ElectricCapacitanceUnit? _unit; + + static ElectricCapacitance() + { + BaseDimensions = new BaseDimensions(-2, -1, 4, 2, 0, 0, 0); + BaseUnit = ElectricCapacitanceUnit.Farad; + Units = Enum.GetValues(typeof(ElectricCapacitanceUnit)).Cast().ToArray(); + Zero = new ElectricCapacitance(0, BaseUnit); + Info = new QuantityInfo("ElectricCapacitance", + new UnitInfo[] + { + new UnitInfo(ElectricCapacitanceUnit.Farad, "Farads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCapacitance"), + new UnitInfo(ElectricCapacitanceUnit.Kilofarad, "Kilofarads", BaseUnits.Undefined, "ElectricCapacitance"), + new UnitInfo(ElectricCapacitanceUnit.Megafarad, "Megafarads", BaseUnits.Undefined, "ElectricCapacitance"), + new UnitInfo(ElectricCapacitanceUnit.Microfarad, "Microfarads", BaseUnits.Undefined, "ElectricCapacitance"), + new UnitInfo(ElectricCapacitanceUnit.Millifarad, "Millifarads", BaseUnits.Undefined, "ElectricCapacitance"), + new UnitInfo(ElectricCapacitanceUnit.Nanofarad, "Nanofarads", BaseUnits.Undefined, "ElectricCapacitance"), + new UnitInfo(ElectricCapacitanceUnit.Picofarad, "Picofarads", BaseUnits.Undefined, "ElectricCapacitance"), + }, + 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 ElectricCapacitance(double value, ElectricCapacitanceUnit 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 ElectricCapacitance(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 ElectricCapacitance, which is Farad. All conversions go via this value. + /// + public static ElectricCapacitanceUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricCapacitance quantity. + /// + public static ElectricCapacitanceUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Farad. + /// + public static ElectricCapacitance Zero { get; } + + /// + public static ElectricCapacitance 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 ElectricCapacitanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricCapacitance.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Farads => As(ElectricCapacitanceUnit.Farad); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilofarads => As(ElectricCapacitanceUnit.Kilofarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Megafarads => As(ElectricCapacitanceUnit.Megafarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Microfarads => As(ElectricCapacitanceUnit.Microfarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Millifarads => As(ElectricCapacitanceUnit.Millifarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanofarads => As(ElectricCapacitanceUnit.Nanofarad); + + /// + /// Gets a value of this quantity converted into + /// + public double Picofarads => As(ElectricCapacitanceUnit.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: ElectricCapacitanceUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Kilofarad, ElectricCapacitanceUnit.Farad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Farad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Megafarad, ElectricCapacitanceUnit.Farad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Farad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Microfarad, ElectricCapacitanceUnit.Farad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Farad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Millifarad, ElectricCapacitanceUnit.Farad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Farad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Nanofarad, ElectricCapacitanceUnit.Farad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Farad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Picofarad, ElectricCapacitanceUnit.Farad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Farad)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Farad, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricCapacitanceUnit + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Kilofarad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Kilofarad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Megafarad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Megafarad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Microfarad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Microfarad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Millifarad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Millifarad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Nanofarad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Nanofarad)); + unitConverter.SetConversionFunction(ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Picofarad, quantity => quantity.ToUnit(ElectricCapacitanceUnit.Picofarad)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricCapacitanceUnit 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(ElectricCapacitanceUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromFarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Farad); + } + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromKilofarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Kilofarad); + } + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromMegafarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Megafarad); + } + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromMicrofarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Microfarad); + } + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromMillifarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Millifarad); + } + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromNanofarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Nanofarad); + } + + /// + /// Creates a from . + /// + public static ElectricCapacitance FromPicofarads(double value) + { + return new ElectricCapacitance(value, ElectricCapacitanceUnit.Picofarad); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricCapacitance unit value. + public static ElectricCapacitance From(double value, ElectricCapacitanceUnit fromUnit) + { + return new ElectricCapacitance(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 ElectricCapacitance 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 ElectricCapacitance Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricCapacitance 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 ElectricCapacitance result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricCapacitanceUnit 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 ElectricCapacitanceUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricCapacitanceUnit 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 ElectricCapacitanceUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricCapacitance operator -(ElectricCapacitance right) + { + return new ElectricCapacitance(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricCapacitance operator +(ElectricCapacitance left, ElectricCapacitance right) + { + return new ElectricCapacitance(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricCapacitance operator -(ElectricCapacitance left, ElectricCapacitance right) + { + return new ElectricCapacitance(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricCapacitance operator *(double left, ElectricCapacitance right) + { + return new ElectricCapacitance(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricCapacitance operator *(ElectricCapacitance left, double right) + { + return new ElectricCapacitance(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricCapacitance operator /(ElectricCapacitance left, double right) + { + return new ElectricCapacitance(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricCapacitance left, ElectricCapacitance right) + { + return left.Farads / right.Farads; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricCapacitance left, ElectricCapacitance right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricCapacitance left, ElectricCapacitance right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricCapacitance left, ElectricCapacitance right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricCapacitance left, ElectricCapacitance 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(ElectricCapacitance other, ElectricCapacitance 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 ==(ElectricCapacitance left, ElectricCapacitance 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(ElectricCapacitance other, ElectricCapacitance 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 !=(ElectricCapacitance left, ElectricCapacitance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricCapacitance other, ElectricCapacitance 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 ElectricCapacitance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricCapacitance other, ElectricCapacitance 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(ElectricCapacitance 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 ElectricCapacitance otherQuantity)) throw new ArgumentException("Expected type ElectricCapacitance.", 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(ElectricCapacitance other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricCapacitance 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(ElectricCapacitance other, ElectricCapacitance 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(ElectricCapacitance 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 ElectricCapacitance otherTyped + && (tolerance is ElectricCapacitance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricCapacitance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricCapacitance other, ElectricCapacitance 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 ElectricCapacitance. + 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(ElectricCapacitanceUnit 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 ElectricCapacitanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCapacitanceUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricCapacitance to another ElectricCapacitance with the unit representation . + /// + /// The unit to convert to. + /// A ElectricCapacitance with the specified unit. + public ElectricCapacitance ToUnit(ElectricCapacitanceUnit 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 ElectricCapacitance with the specified unit. + public ElectricCapacitance ToUnit(ElectricCapacitanceUnit 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(ElectricCapacitance), Unit, typeof(ElectricCapacitance), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricCapacitance)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(ElectricCapacitanceUnit unit, [NotNullWhen(true)] out ElectricCapacitance? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricCapacitance? convertedOrNull = (Unit, unit) switch + { + // ElectricCapacitanceUnit -> BaseUnit + (ElectricCapacitanceUnit.Kilofarad, ElectricCapacitanceUnit.Farad) => new ElectricCapacitance((_value) * 1e3d, ElectricCapacitanceUnit.Farad), + (ElectricCapacitanceUnit.Megafarad, ElectricCapacitanceUnit.Farad) => new ElectricCapacitance((_value) * 1e6d, ElectricCapacitanceUnit.Farad), + (ElectricCapacitanceUnit.Microfarad, ElectricCapacitanceUnit.Farad) => new ElectricCapacitance((_value) * 1e-6d, ElectricCapacitanceUnit.Farad), + (ElectricCapacitanceUnit.Millifarad, ElectricCapacitanceUnit.Farad) => new ElectricCapacitance((_value) * 1e-3d, ElectricCapacitanceUnit.Farad), + (ElectricCapacitanceUnit.Nanofarad, ElectricCapacitanceUnit.Farad) => new ElectricCapacitance((_value) * 1e-9d, ElectricCapacitanceUnit.Farad), + (ElectricCapacitanceUnit.Picofarad, ElectricCapacitanceUnit.Farad) => new ElectricCapacitance((_value) * 1e-12d, ElectricCapacitanceUnit.Farad), + + // BaseUnit -> ElectricCapacitanceUnit + (ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Kilofarad) => new ElectricCapacitance((_value) / 1e3d, ElectricCapacitanceUnit.Kilofarad), + (ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Megafarad) => new ElectricCapacitance((_value) / 1e6d, ElectricCapacitanceUnit.Megafarad), + (ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Microfarad) => new ElectricCapacitance((_value) / 1e-6d, ElectricCapacitanceUnit.Microfarad), + (ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Millifarad) => new ElectricCapacitance((_value) / 1e-3d, ElectricCapacitanceUnit.Millifarad), + (ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Nanofarad) => new ElectricCapacitance((_value) / 1e-9d, ElectricCapacitanceUnit.Nanofarad), + (ElectricCapacitanceUnit.Farad, ElectricCapacitanceUnit.Picofarad) => new ElectricCapacitance((_value) / 1e-12d, ElectricCapacitanceUnit.Picofarad), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricCapacitanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCapacitanceUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricCapacitance 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(ElectricCapacitanceUnit 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(ElectricCapacitance)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricCapacitance)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricCapacitance)} 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(ElectricCapacitance)) + return this; + else if (conversionType == typeof(ElectricCapacitanceUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricCapacitance.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricCapacitance.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricCapacitance)} 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/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs index baed8ee118..cffa3a5b6e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -36,7 +36,7 @@ namespace UnitsNet { /// /// - /// The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor. + /// The electrical conductance of an object is a measure of the ease with which an electric current passes. Along with susceptance, it is one of two elements of admittance. Its reciprocal quantity is electrical resistance. /// /// /// https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance @@ -76,11 +76,22 @@ static ElectricConductance() Info = new QuantityInfo("ElectricConductance", new UnitInfo[] { + new UnitInfo(ElectricConductanceUnit.Gigamho, "Gigamhos", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Gigasiemens, "Gigasiemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Kilomho, "Kilomhos", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Kilosiemens, "Kilosiemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Megamho, "Megamhos", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Megasiemens, "Megasiemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Mho, "Mhos", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Micromho, "Micromhos", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Microsiemens, "Microsiemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Millimho, "Millimhos", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Nanosiemens, "Nanosiemens", BaseUnits.Undefined, "ElectricConductance"), new UnitInfo(ElectricConductanceUnit.Siemens, "Siemens", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricConductance"), + new UnitInfo(ElectricConductanceUnit.Terasiemens, "Terasiemens", BaseUnits.Undefined, "ElectricConductance"), }, BaseUnit, Zero, BaseDimensions); @@ -183,21 +194,66 @@ public ElectricConductance(double value, UnitSystem unitSystem) #region Conversion Properties + /// + /// Gets a value of this quantity converted into + /// + public double Gigamhos => As(ElectricConductanceUnit.Gigamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Gigasiemens => As(ElectricConductanceUnit.Gigasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilomhos => As(ElectricConductanceUnit.Kilomho); + /// /// Gets a value of this quantity converted into /// public double Kilosiemens => As(ElectricConductanceUnit.Kilosiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Megamhos => As(ElectricConductanceUnit.Megamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Megasiemens => As(ElectricConductanceUnit.Megasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Mhos => As(ElectricConductanceUnit.Mho); + + /// + /// Gets a value of this quantity converted into + /// + public double Micromhos => As(ElectricConductanceUnit.Micromho); + /// /// Gets a value of this quantity converted into /// public double Microsiemens => As(ElectricConductanceUnit.Microsiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Millimhos => As(ElectricConductanceUnit.Millimho); + /// /// Gets a value of this quantity converted into /// public double Millisiemens => As(ElectricConductanceUnit.Millisiemens); + /// + /// Gets a value of this quantity converted into + /// + public double Nanomhos => As(ElectricConductanceUnit.Nanomho); + /// /// Gets a value of this quantity converted into /// @@ -208,6 +264,16 @@ public ElectricConductance(double value, UnitSystem unitSystem) /// public double Siemens => As(ElectricConductanceUnit.Siemens); + /// + /// Gets a value of this quantity converted into + /// + public double Teramhos => As(ElectricConductanceUnit.Teramho); + + /// + /// Gets a value of this quantity converted into + /// + public double Terasiemens => As(ElectricConductanceUnit.Terasiemens); + #endregion #region Static Methods @@ -219,19 +285,41 @@ public ElectricConductance(double value, UnitSystem unitSystem) internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: ElectricConductanceUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricConductanceUnit.Gigamho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Gigasiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Kilomho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Kilosiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Megamho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Megasiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Mho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Micromho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Microsiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Millimho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Millisiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Nanomho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Nanosiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Teramho, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Terasiemens, ElectricConductanceUnit.Siemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Siemens)); // Register in unit converter: BaseUnit <-> BaseUnit unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Siemens, quantity => quantity); // Register in unit converter: BaseUnit -> ElectricConductanceUnit + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Gigamho, quantity => quantity.ToUnit(ElectricConductanceUnit.Gigamho)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Gigasiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Gigasiemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Kilomho, quantity => quantity.ToUnit(ElectricConductanceUnit.Kilomho)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Kilosiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Kilosiemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Megamho, quantity => quantity.ToUnit(ElectricConductanceUnit.Megamho)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Megasiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Megasiemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Mho, quantity => quantity.ToUnit(ElectricConductanceUnit.Mho)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Micromho, quantity => quantity.ToUnit(ElectricConductanceUnit.Micromho)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Microsiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Microsiemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Millimho, quantity => quantity.ToUnit(ElectricConductanceUnit.Millimho)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Millisiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Millisiemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Nanomho, quantity => quantity.ToUnit(ElectricConductanceUnit.Nanomho)); unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Nanosiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Nanosiemens)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Teramho, quantity => quantity.ToUnit(ElectricConductanceUnit.Teramho)); + unitConverter.SetConversionFunction(ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Terasiemens, quantity => quantity.ToUnit(ElectricConductanceUnit.Terasiemens)); } /// @@ -259,6 +347,30 @@ public static string GetAbbreviation(ElectricConductanceUnit unit, IFormatProvid #region Static Factory Methods + /// + /// Creates a from . + /// + public static ElectricConductance FromGigamhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Gigamho); + } + + /// + /// Creates a from . + /// + public static ElectricConductance FromGigasiemens(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Gigasiemens); + } + + /// + /// Creates a from . + /// + public static ElectricConductance FromKilomhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Kilomho); + } + /// /// Creates a from . /// @@ -267,6 +379,38 @@ public static ElectricConductance FromKilosiemens(double value) return new ElectricConductance(value, ElectricConductanceUnit.Kilosiemens); } + /// + /// Creates a from . + /// + public static ElectricConductance FromMegamhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Megamho); + } + + /// + /// Creates a from . + /// + public static ElectricConductance FromMegasiemens(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Megasiemens); + } + + /// + /// Creates a from . + /// + public static ElectricConductance FromMhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Mho); + } + + /// + /// Creates a from . + /// + public static ElectricConductance FromMicromhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Micromho); + } + /// /// Creates a from . /// @@ -275,6 +419,14 @@ public static ElectricConductance FromMicrosiemens(double value) return new ElectricConductance(value, ElectricConductanceUnit.Microsiemens); } + /// + /// Creates a from . + /// + public static ElectricConductance FromMillimhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Millimho); + } + /// /// Creates a from . /// @@ -283,6 +435,14 @@ public static ElectricConductance FromMillisiemens(double value) return new ElectricConductance(value, ElectricConductanceUnit.Millisiemens); } + /// + /// Creates a from . + /// + public static ElectricConductance FromNanomhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Nanomho); + } + /// /// Creates a from . /// @@ -299,6 +459,22 @@ public static ElectricConductance FromSiemens(double value) return new ElectricConductance(value, ElectricConductanceUnit.Siemens); } + /// + /// Creates a from . + /// + public static ElectricConductance FromTeramhos(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Teramho); + } + + /// + /// Creates a from . + /// + public static ElectricConductance FromTerasiemens(double value) + { + return new ElectricConductance(value, ElectricConductanceUnit.Terasiemens); + } + /// /// Dynamically convert from value and unit enum to . /// @@ -783,16 +959,38 @@ private bool TryToUnit(ElectricConductanceUnit unit, [NotNullWhen(true)] out Ele ElectricConductance? convertedOrNull = (Unit, unit) switch { // ElectricConductanceUnit -> BaseUnit + (ElectricConductanceUnit.Gigamho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e9d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Gigasiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e9d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Kilomho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e3d, ElectricConductanceUnit.Siemens), (ElectricConductanceUnit.Kilosiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e3d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Megamho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e6d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Megasiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e6d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Mho, ElectricConductanceUnit.Siemens) => new ElectricConductance(_value, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Micromho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e-6d, ElectricConductanceUnit.Siemens), (ElectricConductanceUnit.Microsiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e-6d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Millimho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e-3d, ElectricConductanceUnit.Siemens), (ElectricConductanceUnit.Millisiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e-3d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Nanomho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e-9d, ElectricConductanceUnit.Siemens), (ElectricConductanceUnit.Nanosiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e-9d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Teramho, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e12d, ElectricConductanceUnit.Siemens), + (ElectricConductanceUnit.Terasiemens, ElectricConductanceUnit.Siemens) => new ElectricConductance((_value) * 1e12d, ElectricConductanceUnit.Siemens), // BaseUnit -> ElectricConductanceUnit + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Gigamho) => new ElectricConductance((_value) / 1e9d, ElectricConductanceUnit.Gigamho), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Gigasiemens) => new ElectricConductance((_value) / 1e9d, ElectricConductanceUnit.Gigasiemens), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Kilomho) => new ElectricConductance((_value) / 1e3d, ElectricConductanceUnit.Kilomho), (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Kilosiemens) => new ElectricConductance((_value) / 1e3d, ElectricConductanceUnit.Kilosiemens), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Megamho) => new ElectricConductance((_value) / 1e6d, ElectricConductanceUnit.Megamho), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Megasiemens) => new ElectricConductance((_value) / 1e6d, ElectricConductanceUnit.Megasiemens), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Mho) => new ElectricConductance(_value, ElectricConductanceUnit.Mho), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Micromho) => new ElectricConductance((_value) / 1e-6d, ElectricConductanceUnit.Micromho), (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Microsiemens) => new ElectricConductance((_value) / 1e-6d, ElectricConductanceUnit.Microsiemens), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Millimho) => new ElectricConductance((_value) / 1e-3d, ElectricConductanceUnit.Millimho), (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Millisiemens) => new ElectricConductance((_value) / 1e-3d, ElectricConductanceUnit.Millisiemens), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Nanomho) => new ElectricConductance((_value) / 1e-9d, ElectricConductanceUnit.Nanomho), (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Nanosiemens) => new ElectricConductance((_value) / 1e-9d, ElectricConductanceUnit.Nanosiemens), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Teramho) => new ElectricConductance((_value) / 1e12d, ElectricConductanceUnit.Teramho), + (ElectricConductanceUnit.Siemens, ElectricConductanceUnit.Terasiemens) => new ElectricConductance((_value) / 1e12d, ElectricConductanceUnit.Terasiemens), _ => null }; diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 84775aad64..7eb0360ba4 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -38,6 +38,9 @@ namespace UnitsNet /// /// An electric current is a flow of electric charge. In electric circuits this charge is often carried by moving electrons in a wire. It can also be carried by ions in an electrolyte, or by both ions and electrons such as in a plasma. /// + /// + /// If you want to map more parameters into the class (amps RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple. + /// [DataContract] [DebuggerTypeProxy(typeof(QuantityDisplay))] public readonly partial struct ElectricCurrent : diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs new file mode 100644 index 0000000000..5188b26f63 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs @@ -0,0 +1,1044 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// Electric impedance is the opposition to alternating current presented by the combined effect of resistance and reactance in a circuit. It is defined as the inverse of admittance. The SI unit of impedance is the ohm (symbol Ω). + /// + /// + /// https://en.wikipedia.org/wiki/Electrical_impedance + /// + [Obsolete("Impedance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricResistance or ElectricReactance instead.")] + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricImpedance : + 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 ElectricImpedanceUnit? _unit; + + static ElectricImpedance() + { + BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); + BaseUnit = ElectricImpedanceUnit.Ohm; + Units = Enum.GetValues(typeof(ElectricImpedanceUnit)).Cast().ToArray(); + Zero = new ElectricImpedance(0, BaseUnit); + Info = new QuantityInfo("ElectricImpedance", + new UnitInfo[] + { + new UnitInfo(ElectricImpedanceUnit.Gigaohm, "Gigaohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Kiloohm, "Kiloohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Megaohm, "Megaohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Microohm, "Microohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Milliohm, "Milliohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Nanoohm, "Nanoohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Ohm, "Ohms", BaseUnits.Undefined, "ElectricImpedance"), + new UnitInfo(ElectricImpedanceUnit.Teraohm, "Teraohms", BaseUnits.Undefined, "ElectricImpedance"), + }, + 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 ElectricImpedance(double value, ElectricImpedanceUnit 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 ElectricImpedance(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 ElectricImpedance, which is Ohm. All conversions go via this value. + /// + public static ElectricImpedanceUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricImpedance quantity. + /// + public static ElectricImpedanceUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Ohm. + /// + public static ElectricImpedance Zero { get; } + + /// + public static ElectricImpedance 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 ElectricImpedanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricImpedance.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigaohms => As(ElectricImpedanceUnit.Gigaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Kiloohms => As(ElectricImpedanceUnit.Kiloohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Megaohms => As(ElectricImpedanceUnit.Megaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Microohms => As(ElectricImpedanceUnit.Microohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Milliohms => As(ElectricImpedanceUnit.Milliohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanoohms => As(ElectricImpedanceUnit.Nanoohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Ohms => As(ElectricImpedanceUnit.Ohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Teraohms => As(ElectricImpedanceUnit.Teraohm); + + #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: ElectricImpedanceUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Gigaohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Kiloohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Megaohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Microohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Milliohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Nanoohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Teraohm, ElectricImpedanceUnit.Ohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Ohm)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Ohm, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricImpedanceUnit + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Gigaohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Gigaohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Kiloohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Kiloohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Megaohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Megaohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Microohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Microohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Milliohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Milliohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Nanoohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Nanoohm)); + unitConverter.SetConversionFunction(ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Teraohm, quantity => quantity.ToUnit(ElectricImpedanceUnit.Teraohm)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricImpedanceUnit 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(ElectricImpedanceUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricImpedance FromGigaohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Gigaohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromKiloohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Kiloohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromMegaohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Megaohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromMicroohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Microohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromMilliohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Milliohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromNanoohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Nanoohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromOhms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Ohm); + } + + /// + /// Creates a from . + /// + public static ElectricImpedance FromTeraohms(double value) + { + return new ElectricImpedance(value, ElectricImpedanceUnit.Teraohm); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricImpedance unit value. + public static ElectricImpedance From(double value, ElectricImpedanceUnit fromUnit) + { + return new ElectricImpedance(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 ElectricImpedance 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 ElectricImpedance Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricImpedance 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 ElectricImpedance result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricImpedanceUnit 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 ElectricImpedanceUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricImpedanceUnit 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 ElectricImpedanceUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricImpedance operator -(ElectricImpedance right) + { + return new ElectricImpedance(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricImpedance operator +(ElectricImpedance left, ElectricImpedance right) + { + return new ElectricImpedance(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricImpedance operator -(ElectricImpedance left, ElectricImpedance right) + { + return new ElectricImpedance(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricImpedance operator *(double left, ElectricImpedance right) + { + return new ElectricImpedance(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricImpedance operator *(ElectricImpedance left, double right) + { + return new ElectricImpedance(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricImpedance operator /(ElectricImpedance left, double right) + { + return new ElectricImpedance(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricImpedance left, ElectricImpedance right) + { + return left.Ohms / right.Ohms; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricImpedance left, ElectricImpedance right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricImpedance left, ElectricImpedance right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricImpedance left, ElectricImpedance right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricImpedance left, ElectricImpedance 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(ElectricImpedance other, ElectricImpedance 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 ==(ElectricImpedance left, ElectricImpedance 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(ElectricImpedance other, ElectricImpedance 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 !=(ElectricImpedance left, ElectricImpedance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricImpedance other, ElectricImpedance 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 ElectricImpedance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricImpedance other, ElectricImpedance 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(ElectricImpedance 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 ElectricImpedance otherQuantity)) throw new ArgumentException("Expected type ElectricImpedance.", 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(ElectricImpedance other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricImpedance 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(ElectricImpedance other, ElectricImpedance 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(ElectricImpedance 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 ElectricImpedance otherTyped + && (tolerance is ElectricImpedance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricImpedance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricImpedance other, ElectricImpedance 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 ElectricImpedance. + 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(ElectricImpedanceUnit 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 ElectricImpedanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricImpedanceUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricImpedance to another ElectricImpedance with the unit representation . + /// + /// The unit to convert to. + /// A ElectricImpedance with the specified unit. + public ElectricImpedance ToUnit(ElectricImpedanceUnit 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 ElectricImpedance with the specified unit. + public ElectricImpedance ToUnit(ElectricImpedanceUnit 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(ElectricImpedance), Unit, typeof(ElectricImpedance), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricImpedance)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(ElectricImpedanceUnit unit, [NotNullWhen(true)] out ElectricImpedance? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricImpedance? convertedOrNull = (Unit, unit) switch + { + // ElectricImpedanceUnit -> BaseUnit + (ElectricImpedanceUnit.Gigaohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e9d, ElectricImpedanceUnit.Ohm), + (ElectricImpedanceUnit.Kiloohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e3d, ElectricImpedanceUnit.Ohm), + (ElectricImpedanceUnit.Megaohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e6d, ElectricImpedanceUnit.Ohm), + (ElectricImpedanceUnit.Microohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e-6d, ElectricImpedanceUnit.Ohm), + (ElectricImpedanceUnit.Milliohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e-3d, ElectricImpedanceUnit.Ohm), + (ElectricImpedanceUnit.Nanoohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e-9d, ElectricImpedanceUnit.Ohm), + (ElectricImpedanceUnit.Teraohm, ElectricImpedanceUnit.Ohm) => new ElectricImpedance((_value) * 1e12d, ElectricImpedanceUnit.Ohm), + + // BaseUnit -> ElectricImpedanceUnit + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Gigaohm) => new ElectricImpedance((_value) / 1e9d, ElectricImpedanceUnit.Gigaohm), + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Kiloohm) => new ElectricImpedance((_value) / 1e3d, ElectricImpedanceUnit.Kiloohm), + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Megaohm) => new ElectricImpedance((_value) / 1e6d, ElectricImpedanceUnit.Megaohm), + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Microohm) => new ElectricImpedance((_value) / 1e-6d, ElectricImpedanceUnit.Microohm), + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Milliohm) => new ElectricImpedance((_value) / 1e-3d, ElectricImpedanceUnit.Milliohm), + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Nanoohm) => new ElectricImpedance((_value) / 1e-9d, ElectricImpedanceUnit.Nanoohm), + (ElectricImpedanceUnit.Ohm, ElectricImpedanceUnit.Teraohm) => new ElectricImpedance((_value) / 1e12d, ElectricImpedanceUnit.Teraohm), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricImpedanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricImpedanceUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricImpedance 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(ElectricImpedanceUnit 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(ElectricImpedance)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricImpedance)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricImpedance)} 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(ElectricImpedance)) + return this; + else if (conversionType == typeof(ElectricImpedanceUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricImpedance.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricImpedance.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricImpedance)} 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/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs index 5539cc718c..4482e1540c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -38,6 +38,9 @@ namespace UnitsNet /// /// In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point. /// + /// + /// If you want to map more parameters into the 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 ElectricPotential : diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs index 8f00170e41..42de2dcb8f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.g.cs @@ -38,6 +38,10 @@ namespace UnitsNet /// /// The Electric Potential of a system known to use Alternating Current. /// + /// + /// has been merged into , and will be removed in a later major version. If you want to map more parameters into the 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 : diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs index c10ffda5f3..847e24b670 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.g.cs @@ -38,6 +38,10 @@ namespace UnitsNet /// /// The Electric Potential of a system known to use Direct Current. /// + /// + /// has been merged into , and will be removed in a later major version. If you want to map more parameters into the 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 : diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs new file mode 100644 index 0000000000..0f43258a5b --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs @@ -0,0 +1,1043 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// In electrical circuits, reactance is the opposition presented to alternating current by inductance and capacitance. Along with resistance, it is one of two elements of impedance. + /// + /// + /// https://en.wikipedia.org/wiki/Electrical_reactance + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricReactance : + 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 ElectricReactanceUnit? _unit; + + static ElectricReactance() + { + BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); + BaseUnit = ElectricReactanceUnit.Ohm; + Units = Enum.GetValues(typeof(ElectricReactanceUnit)).Cast().ToArray(); + Zero = new ElectricReactance(0, BaseUnit); + Info = new QuantityInfo("ElectricReactance", + new UnitInfo[] + { + new UnitInfo(ElectricReactanceUnit.Gigaohm, "Gigaohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Kiloohm, "Kiloohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Megaohm, "Megaohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Microohm, "Microohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Milliohm, "Milliohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Nanoohm, "Nanoohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Ohm, "Ohms", BaseUnits.Undefined, "ElectricReactance"), + new UnitInfo(ElectricReactanceUnit.Teraohm, "Teraohms", BaseUnits.Undefined, "ElectricReactance"), + }, + 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 ElectricReactance(double value, ElectricReactanceUnit 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 ElectricReactance(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 ElectricReactance, which is Ohm. All conversions go via this value. + /// + public static ElectricReactanceUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricReactance quantity. + /// + public static ElectricReactanceUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Ohm. + /// + public static ElectricReactance Zero { get; } + + /// + public static ElectricReactance 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 ElectricReactanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricReactance.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigaohms => As(ElectricReactanceUnit.Gigaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Kiloohms => As(ElectricReactanceUnit.Kiloohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Megaohms => As(ElectricReactanceUnit.Megaohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Microohms => As(ElectricReactanceUnit.Microohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Milliohms => As(ElectricReactanceUnit.Milliohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanoohms => As(ElectricReactanceUnit.Nanoohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Ohms => As(ElectricReactanceUnit.Ohm); + + /// + /// Gets a value of this quantity converted into + /// + public double Teraohms => As(ElectricReactanceUnit.Teraohm); + + #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: ElectricReactanceUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricReactanceUnit.Gigaohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Kiloohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Megaohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Microohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Milliohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Nanoohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Teraohm, ElectricReactanceUnit.Ohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Ohm)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Ohm, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricReactanceUnit + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Gigaohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Gigaohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Kiloohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Kiloohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Megaohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Megaohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Microohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Microohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Milliohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Milliohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Nanoohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Nanoohm)); + unitConverter.SetConversionFunction(ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Teraohm, quantity => quantity.ToUnit(ElectricReactanceUnit.Teraohm)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricReactanceUnit 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(ElectricReactanceUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricReactance FromGigaohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Gigaohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromKiloohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Kiloohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromMegaohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Megaohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromMicroohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Microohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromMilliohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Milliohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromNanoohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Nanoohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromOhms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Ohm); + } + + /// + /// Creates a from . + /// + public static ElectricReactance FromTeraohms(double value) + { + return new ElectricReactance(value, ElectricReactanceUnit.Teraohm); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricReactance unit value. + public static ElectricReactance From(double value, ElectricReactanceUnit fromUnit) + { + return new ElectricReactance(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 ElectricReactance 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 ElectricReactance Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricReactance 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 ElectricReactance result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricReactanceUnit 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 ElectricReactanceUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricReactanceUnit 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 ElectricReactanceUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricReactance operator -(ElectricReactance right) + { + return new ElectricReactance(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricReactance operator +(ElectricReactance left, ElectricReactance right) + { + return new ElectricReactance(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricReactance operator -(ElectricReactance left, ElectricReactance right) + { + return new ElectricReactance(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricReactance operator *(double left, ElectricReactance right) + { + return new ElectricReactance(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricReactance operator *(ElectricReactance left, double right) + { + return new ElectricReactance(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricReactance operator /(ElectricReactance left, double right) + { + return new ElectricReactance(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricReactance left, ElectricReactance right) + { + return left.Ohms / right.Ohms; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricReactance left, ElectricReactance right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricReactance left, ElectricReactance right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricReactance left, ElectricReactance right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricReactance left, ElectricReactance 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(ElectricReactance other, ElectricReactance 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 ==(ElectricReactance left, ElectricReactance 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(ElectricReactance other, ElectricReactance 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 !=(ElectricReactance left, ElectricReactance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricReactance other, ElectricReactance 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 ElectricReactance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricReactance other, ElectricReactance 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(ElectricReactance 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 ElectricReactance otherQuantity)) throw new ArgumentException("Expected type ElectricReactance.", 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(ElectricReactance other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricReactance 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(ElectricReactance other, ElectricReactance 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(ElectricReactance 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 ElectricReactance otherTyped + && (tolerance is ElectricReactance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricReactance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricReactance other, ElectricReactance 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 ElectricReactance. + 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(ElectricReactanceUnit 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 ElectricReactanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactanceUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricReactance to another ElectricReactance with the unit representation . + /// + /// The unit to convert to. + /// A ElectricReactance with the specified unit. + public ElectricReactance ToUnit(ElectricReactanceUnit 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 ElectricReactance with the specified unit. + public ElectricReactance ToUnit(ElectricReactanceUnit 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(ElectricReactance), Unit, typeof(ElectricReactance), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricReactance)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(ElectricReactanceUnit unit, [NotNullWhen(true)] out ElectricReactance? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricReactance? convertedOrNull = (Unit, unit) switch + { + // ElectricReactanceUnit -> BaseUnit + (ElectricReactanceUnit.Gigaohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e9d, ElectricReactanceUnit.Ohm), + (ElectricReactanceUnit.Kiloohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e3d, ElectricReactanceUnit.Ohm), + (ElectricReactanceUnit.Megaohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e6d, ElectricReactanceUnit.Ohm), + (ElectricReactanceUnit.Microohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e-6d, ElectricReactanceUnit.Ohm), + (ElectricReactanceUnit.Milliohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e-3d, ElectricReactanceUnit.Ohm), + (ElectricReactanceUnit.Nanoohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e-9d, ElectricReactanceUnit.Ohm), + (ElectricReactanceUnit.Teraohm, ElectricReactanceUnit.Ohm) => new ElectricReactance((_value) * 1e12d, ElectricReactanceUnit.Ohm), + + // BaseUnit -> ElectricReactanceUnit + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Gigaohm) => new ElectricReactance((_value) / 1e9d, ElectricReactanceUnit.Gigaohm), + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Kiloohm) => new ElectricReactance((_value) / 1e3d, ElectricReactanceUnit.Kiloohm), + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Megaohm) => new ElectricReactance((_value) / 1e6d, ElectricReactanceUnit.Megaohm), + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Microohm) => new ElectricReactance((_value) / 1e-6d, ElectricReactanceUnit.Microohm), + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Milliohm) => new ElectricReactance((_value) / 1e-3d, ElectricReactanceUnit.Milliohm), + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Nanoohm) => new ElectricReactance((_value) / 1e-9d, ElectricReactanceUnit.Nanoohm), + (ElectricReactanceUnit.Ohm, ElectricReactanceUnit.Teraohm) => new ElectricReactance((_value) / 1e12d, ElectricReactanceUnit.Teraohm), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricReactanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactanceUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricReactance 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(ElectricReactanceUnit 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(ElectricReactance)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricReactance)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricReactance)} 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(ElectricReactance)) + return this; + else if (conversionType == typeof(ElectricReactanceUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricReactance.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricReactance.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricReactance)} 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/ElectricReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs new file mode 100644 index 0000000000..c26eceb2c8 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs @@ -0,0 +1,950 @@ +//------------------------------------------------------------------------------ +// +// 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. + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricReactiveEnergy : + 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 ElectricReactiveEnergyUnit? _unit; + + static ElectricReactiveEnergy() + { + BaseDimensions = new BaseDimensions(2, 1, -1, 0, 0, 0, 0); + BaseUnit = ElectricReactiveEnergyUnit.VoltampereReactiveHour; + Units = Enum.GetValues(typeof(ElectricReactiveEnergyUnit)).Cast().ToArray(); + Zero = new ElectricReactiveEnergy(0, BaseUnit); + Info = new QuantityInfo("ElectricReactiveEnergy", + new UnitInfo[] + { + new UnitInfo(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, "KilovoltampereReactiveHours", BaseUnits.Undefined, "ElectricReactiveEnergy"), + new UnitInfo(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, "MegavoltampereReactiveHours", BaseUnits.Undefined, "ElectricReactiveEnergy"), + new UnitInfo(ElectricReactiveEnergyUnit.VoltampereReactiveHour, "VoltampereReactiveHours", BaseUnits.Undefined, "ElectricReactiveEnergy"), + }, + 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 ElectricReactiveEnergy(double value, ElectricReactiveEnergyUnit 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 ElectricReactiveEnergy(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 ElectricReactiveEnergy, which is VoltampereReactiveHour. All conversions go via this value. + /// + public static ElectricReactiveEnergyUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricReactiveEnergy quantity. + /// + public static ElectricReactiveEnergyUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereReactiveHour. + /// + public static ElectricReactiveEnergy Zero { get; } + + /// + public static ElectricReactiveEnergy 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 ElectricReactiveEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricReactiveEnergy.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilovoltampereReactiveHours => As(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour); + + /// + /// Gets a value of this quantity converted into + /// + public double MegavoltampereReactiveHours => As(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour); + + /// + /// Gets a value of this quantity converted into + /// + public double VoltampereReactiveHours => As(ElectricReactiveEnergyUnit.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: ElectricReactiveEnergyUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, ElectricReactiveEnergyUnit.VoltampereReactiveHour, quantity => quantity.ToUnit(ElectricReactiveEnergyUnit.VoltampereReactiveHour)); + unitConverter.SetConversionFunction(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, ElectricReactiveEnergyUnit.VoltampereReactiveHour, quantity => quantity.ToUnit(ElectricReactiveEnergyUnit.VoltampereReactiveHour)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricReactiveEnergyUnit.VoltampereReactiveHour, ElectricReactiveEnergyUnit.VoltampereReactiveHour, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricReactiveEnergyUnit + unitConverter.SetConversionFunction(ElectricReactiveEnergyUnit.VoltampereReactiveHour, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, quantity => quantity.ToUnit(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour)); + unitConverter.SetConversionFunction(ElectricReactiveEnergyUnit.VoltampereReactiveHour, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, quantity => quantity.ToUnit(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricReactiveEnergyUnit 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(ElectricReactiveEnergyUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricReactiveEnergy FromKilovoltampereReactiveHours(double value) + { + return new ElectricReactiveEnergy(value, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour); + } + + /// + /// Creates a from . + /// + public static ElectricReactiveEnergy FromMegavoltampereReactiveHours(double value) + { + return new ElectricReactiveEnergy(value, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour); + } + + /// + /// Creates a from . + /// + public static ElectricReactiveEnergy FromVoltampereReactiveHours(double value) + { + return new ElectricReactiveEnergy(value, ElectricReactiveEnergyUnit.VoltampereReactiveHour); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricReactiveEnergy unit value. + public static ElectricReactiveEnergy From(double value, ElectricReactiveEnergyUnit fromUnit) + { + return new ElectricReactiveEnergy(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 ElectricReactiveEnergy 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 ElectricReactiveEnergy Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricReactiveEnergy 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 ElectricReactiveEnergy result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricReactiveEnergyUnit 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 ElectricReactiveEnergyUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricReactiveEnergyUnit 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 ElectricReactiveEnergyUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricReactiveEnergy operator -(ElectricReactiveEnergy right) + { + return new ElectricReactiveEnergy(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricReactiveEnergy operator +(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return new ElectricReactiveEnergy(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricReactiveEnergy operator -(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return new ElectricReactiveEnergy(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricReactiveEnergy operator *(double left, ElectricReactiveEnergy right) + { + return new ElectricReactiveEnergy(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricReactiveEnergy operator *(ElectricReactiveEnergy left, double right) + { + return new ElectricReactiveEnergy(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricReactiveEnergy operator /(ElectricReactiveEnergy left, double right) + { + return new ElectricReactiveEnergy(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return left.VoltampereReactiveHours / right.VoltampereReactiveHours; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricReactiveEnergy left, ElectricReactiveEnergy 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(ElectricReactiveEnergy other, ElectricReactiveEnergy 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 ==(ElectricReactiveEnergy left, ElectricReactiveEnergy 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(ElectricReactiveEnergy other, ElectricReactiveEnergy 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 !=(ElectricReactiveEnergy left, ElectricReactiveEnergy right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricReactiveEnergy other, ElectricReactiveEnergy 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 ElectricReactiveEnergy otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricReactiveEnergy other, ElectricReactiveEnergy 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(ElectricReactiveEnergy 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 ElectricReactiveEnergy otherQuantity)) throw new ArgumentException("Expected type ElectricReactiveEnergy.", 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(ElectricReactiveEnergy other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricReactiveEnergy 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(ElectricReactiveEnergy other, ElectricReactiveEnergy 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(ElectricReactiveEnergy 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 ElectricReactiveEnergy otherTyped + && (tolerance is ElectricReactiveEnergy toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricReactiveEnergy'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricReactiveEnergy other, ElectricReactiveEnergy 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 ElectricReactiveEnergy. + 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(ElectricReactiveEnergyUnit 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 ElectricReactiveEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactiveEnergyUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricReactiveEnergy to another ElectricReactiveEnergy with the unit representation . + /// + /// The unit to convert to. + /// A ElectricReactiveEnergy with the specified unit. + public ElectricReactiveEnergy ToUnit(ElectricReactiveEnergyUnit 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 ElectricReactiveEnergy with the specified unit. + public ElectricReactiveEnergy ToUnit(ElectricReactiveEnergyUnit 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(ElectricReactiveEnergy), Unit, typeof(ElectricReactiveEnergy), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricReactiveEnergy)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(ElectricReactiveEnergyUnit unit, [NotNullWhen(true)] out ElectricReactiveEnergy? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricReactiveEnergy? convertedOrNull = (Unit, unit) switch + { + // ElectricReactiveEnergyUnit -> BaseUnit + (ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, ElectricReactiveEnergyUnit.VoltampereReactiveHour) => new ElectricReactiveEnergy((_value) * 1e3d, ElectricReactiveEnergyUnit.VoltampereReactiveHour), + (ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, ElectricReactiveEnergyUnit.VoltampereReactiveHour) => new ElectricReactiveEnergy((_value) * 1e6d, ElectricReactiveEnergyUnit.VoltampereReactiveHour), + + // BaseUnit -> ElectricReactiveEnergyUnit + (ElectricReactiveEnergyUnit.VoltampereReactiveHour, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour) => new ElectricReactiveEnergy((_value) / 1e3d, ElectricReactiveEnergyUnit.KilovoltampereReactiveHour), + (ElectricReactiveEnergyUnit.VoltampereReactiveHour, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour) => new ElectricReactiveEnergy((_value) / 1e6d, ElectricReactiveEnergyUnit.MegavoltampereReactiveHour), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricReactiveEnergyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactiveEnergyUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricReactiveEnergy 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(ElectricReactiveEnergyUnit 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(ElectricReactiveEnergy)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricReactiveEnergy)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricReactiveEnergy)} 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(ElectricReactiveEnergy)) + return this; + else if (conversionType == typeof(ElectricReactiveEnergyUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricReactiveEnergy.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricReactiveEnergy.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricReactiveEnergy)} 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/ElectricReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs new file mode 100644 index 0000000000..d644661292 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs @@ -0,0 +1,971 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// In electric power transmission and distribution, volt-ampere reactive (var) is a unit of measurement of reactive power. Reactive power exists in an AC circuit when the current and voltage are not in phase. + /// + /// + /// https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricReactivePower : + 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 ElectricReactivePowerUnit? _unit; + + static ElectricReactivePower() + { + BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + BaseUnit = ElectricReactivePowerUnit.VoltampereReactive; + Units = Enum.GetValues(typeof(ElectricReactivePowerUnit)).Cast().ToArray(); + Zero = new ElectricReactivePower(0, BaseUnit); + Info = new QuantityInfo("ElectricReactivePower", + new UnitInfo[] + { + new UnitInfo(ElectricReactivePowerUnit.GigavoltampereReactive, "GigavoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), + new UnitInfo(ElectricReactivePowerUnit.KilovoltampereReactive, "KilovoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), + new UnitInfo(ElectricReactivePowerUnit.MegavoltampereReactive, "MegavoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), + new UnitInfo(ElectricReactivePowerUnit.VoltampereReactive, "VoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), + }, + 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 ElectricReactivePower(double value, ElectricReactivePowerUnit 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 ElectricReactivePower(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 ElectricReactivePower, which is VoltampereReactive. All conversions go via this value. + /// + public static ElectricReactivePowerUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricReactivePower quantity. + /// + public static ElectricReactivePowerUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereReactive. + /// + public static ElectricReactivePower Zero { get; } + + /// + public static ElectricReactivePower 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 ElectricReactivePowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricReactivePower.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double GigavoltamperesReactive => As(ElectricReactivePowerUnit.GigavoltampereReactive); + + /// + /// Gets a value of this quantity converted into + /// + public double KilovoltamperesReactive => As(ElectricReactivePowerUnit.KilovoltampereReactive); + + /// + /// Gets a value of this quantity converted into + /// + public double MegavoltamperesReactive => As(ElectricReactivePowerUnit.MegavoltampereReactive); + + /// + /// Gets a value of this quantity converted into + /// + public double VoltamperesReactive => As(ElectricReactivePowerUnit.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: ElectricReactivePowerUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.GigavoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive, quantity => quantity.ToUnit(ElectricReactivePowerUnit.VoltampereReactive)); + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.KilovoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive, quantity => quantity.ToUnit(ElectricReactivePowerUnit.VoltampereReactive)); + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.MegavoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive, quantity => quantity.ToUnit(ElectricReactivePowerUnit.VoltampereReactive)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricReactivePowerUnit + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.GigavoltampereReactive, quantity => quantity.ToUnit(ElectricReactivePowerUnit.GigavoltampereReactive)); + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.KilovoltampereReactive, quantity => quantity.ToUnit(ElectricReactivePowerUnit.KilovoltampereReactive)); + unitConverter.SetConversionFunction(ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.MegavoltampereReactive, quantity => quantity.ToUnit(ElectricReactivePowerUnit.MegavoltampereReactive)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricReactivePowerUnit 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(ElectricReactivePowerUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromGigavoltamperesReactive(double value) + { + return new ElectricReactivePower(value, ElectricReactivePowerUnit.GigavoltampereReactive); + } + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromKilovoltamperesReactive(double value) + { + return new ElectricReactivePower(value, ElectricReactivePowerUnit.KilovoltampereReactive); + } + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromMegavoltamperesReactive(double value) + { + return new ElectricReactivePower(value, ElectricReactivePowerUnit.MegavoltampereReactive); + } + + /// + /// Creates a from . + /// + public static ElectricReactivePower FromVoltamperesReactive(double value) + { + return new ElectricReactivePower(value, ElectricReactivePowerUnit.VoltampereReactive); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricReactivePower unit value. + public static ElectricReactivePower From(double value, ElectricReactivePowerUnit fromUnit) + { + return new ElectricReactivePower(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 ElectricReactivePower 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 ElectricReactivePower Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricReactivePower 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 ElectricReactivePower result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricReactivePowerUnit 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 ElectricReactivePowerUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricReactivePowerUnit 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 ElectricReactivePowerUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricReactivePower operator -(ElectricReactivePower right) + { + return new ElectricReactivePower(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricReactivePower operator +(ElectricReactivePower left, ElectricReactivePower right) + { + return new ElectricReactivePower(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricReactivePower operator -(ElectricReactivePower left, ElectricReactivePower right) + { + return new ElectricReactivePower(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricReactivePower operator *(double left, ElectricReactivePower right) + { + return new ElectricReactivePower(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricReactivePower operator *(ElectricReactivePower left, double right) + { + return new ElectricReactivePower(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricReactivePower operator /(ElectricReactivePower left, double right) + { + return new ElectricReactivePower(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricReactivePower left, ElectricReactivePower right) + { + return left.VoltamperesReactive / right.VoltamperesReactive; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricReactivePower left, ElectricReactivePower right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricReactivePower left, ElectricReactivePower right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricReactivePower left, ElectricReactivePower right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricReactivePower left, ElectricReactivePower 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(ElectricReactivePower other, ElectricReactivePower 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 ==(ElectricReactivePower left, ElectricReactivePower 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(ElectricReactivePower other, ElectricReactivePower 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 !=(ElectricReactivePower left, ElectricReactivePower right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricReactivePower other, ElectricReactivePower 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 ElectricReactivePower otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricReactivePower other, ElectricReactivePower 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(ElectricReactivePower 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 ElectricReactivePower otherQuantity)) throw new ArgumentException("Expected type ElectricReactivePower.", 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(ElectricReactivePower other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricReactivePower 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(ElectricReactivePower other, ElectricReactivePower 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(ElectricReactivePower 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 ElectricReactivePower otherTyped + && (tolerance is ElectricReactivePower toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricReactivePower'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricReactivePower other, ElectricReactivePower 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 ElectricReactivePower. + 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(ElectricReactivePowerUnit 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 ElectricReactivePowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactivePowerUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricReactivePower to another ElectricReactivePower with the unit representation . + /// + /// The unit to convert to. + /// A ElectricReactivePower with the specified unit. + public ElectricReactivePower ToUnit(ElectricReactivePowerUnit 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 ElectricReactivePower with the specified unit. + public ElectricReactivePower ToUnit(ElectricReactivePowerUnit 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(ElectricReactivePower), Unit, typeof(ElectricReactivePower), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricReactivePower)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(ElectricReactivePowerUnit unit, [NotNullWhen(true)] out ElectricReactivePower? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricReactivePower? convertedOrNull = (Unit, unit) switch + { + // ElectricReactivePowerUnit -> BaseUnit + (ElectricReactivePowerUnit.GigavoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive) => new ElectricReactivePower((_value) * 1e9d, ElectricReactivePowerUnit.VoltampereReactive), + (ElectricReactivePowerUnit.KilovoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive) => new ElectricReactivePower((_value) * 1e3d, ElectricReactivePowerUnit.VoltampereReactive), + (ElectricReactivePowerUnit.MegavoltampereReactive, ElectricReactivePowerUnit.VoltampereReactive) => new ElectricReactivePower((_value) * 1e6d, ElectricReactivePowerUnit.VoltampereReactive), + + // BaseUnit -> ElectricReactivePowerUnit + (ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.GigavoltampereReactive) => new ElectricReactivePower((_value) / 1e9d, ElectricReactivePowerUnit.GigavoltampereReactive), + (ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.KilovoltampereReactive) => new ElectricReactivePower((_value) / 1e3d, ElectricReactivePowerUnit.KilovoltampereReactive), + (ElectricReactivePowerUnit.VoltampereReactive, ElectricReactivePowerUnit.MegavoltampereReactive) => new ElectricReactivePower((_value) / 1e6d, ElectricReactivePowerUnit.MegavoltampereReactive), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricReactivePowerUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricReactivePowerUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricReactivePower 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(ElectricReactivePowerUnit 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(ElectricReactivePower)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricReactivePower)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricReactivePower)} 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(ElectricReactivePower)) + return this; + else if (conversionType == typeof(ElectricReactivePowerUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricReactivePower.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricReactivePower.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricReactivePower)} 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/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs index 3a706f1498..9ab84f14b3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -36,8 +36,11 @@ namespace UnitsNet { /// /// - /// The electrical resistance of an electrical conductor is the opposition to the passage of an electric current through that conductor. + /// The electrical resistance of an object is a measure of its opposition to the flow of electric current. Along with reactance, it is one of two elements of impedance. Its reciprocal quantity is electrical conductance. /// + /// + /// https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance + /// [DataContract] [DebuggerTypeProxy(typeof(QuantityDisplay))] public readonly partial struct ElectricResistance : @@ -81,6 +84,7 @@ static ElectricResistance() new UnitInfo(ElectricResistanceUnit.Megaohm, "Megaohms", BaseUnits.Undefined, "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Microohm, "Microohms", BaseUnits.Undefined, "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Milliohm, "Milliohms", BaseUnits.Undefined, "ElectricResistance"), + new UnitInfo(ElectricResistanceUnit.Nanoohm, "Nanoohms", BaseUnits.Undefined, "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Ohm, "Ohms", BaseUnits.Undefined, "ElectricResistance"), new UnitInfo(ElectricResistanceUnit.Teraohm, "Teraohms", BaseUnits.Undefined, "ElectricResistance"), }, @@ -210,6 +214,11 @@ public ElectricResistance(double value, UnitSystem unitSystem) /// public double Milliohms => As(ElectricResistanceUnit.Milliohm); + /// + /// Gets a value of this quantity converted into + /// + public double Nanoohms => As(ElectricResistanceUnit.Nanoohm); + /// /// Gets a value of this quantity converted into /// @@ -236,6 +245,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(ElectricResistanceUnit.Megaohm, ElectricResistanceUnit.Ohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Ohm)); unitConverter.SetConversionFunction(ElectricResistanceUnit.Microohm, ElectricResistanceUnit.Ohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Ohm)); unitConverter.SetConversionFunction(ElectricResistanceUnit.Milliohm, ElectricResistanceUnit.Ohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Ohm)); + unitConverter.SetConversionFunction(ElectricResistanceUnit.Nanoohm, ElectricResistanceUnit.Ohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Ohm)); unitConverter.SetConversionFunction(ElectricResistanceUnit.Teraohm, ElectricResistanceUnit.Ohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Ohm)); // Register in unit converter: BaseUnit <-> BaseUnit @@ -247,6 +257,7 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Megaohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Megaohm)); unitConverter.SetConversionFunction(ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Microohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Microohm)); unitConverter.SetConversionFunction(ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Milliohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Milliohm)); + unitConverter.SetConversionFunction(ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Nanoohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Nanoohm)); unitConverter.SetConversionFunction(ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Teraohm, quantity => quantity.ToUnit(ElectricResistanceUnit.Teraohm)); } @@ -315,6 +326,14 @@ public static ElectricResistance FromMilliohms(double value) return new ElectricResistance(value, ElectricResistanceUnit.Milliohm); } + /// + /// Creates a from . + /// + public static ElectricResistance FromNanoohms(double value) + { + return new ElectricResistance(value, ElectricResistanceUnit.Nanoohm); + } + /// /// Creates a from . /// @@ -830,6 +849,7 @@ private bool TryToUnit(ElectricResistanceUnit unit, [NotNullWhen(true)] out Elec (ElectricResistanceUnit.Megaohm, ElectricResistanceUnit.Ohm) => new ElectricResistance((_value) * 1e6d, ElectricResistanceUnit.Ohm), (ElectricResistanceUnit.Microohm, ElectricResistanceUnit.Ohm) => new ElectricResistance((_value) * 1e-6d, ElectricResistanceUnit.Ohm), (ElectricResistanceUnit.Milliohm, ElectricResistanceUnit.Ohm) => new ElectricResistance((_value) * 1e-3d, ElectricResistanceUnit.Ohm), + (ElectricResistanceUnit.Nanoohm, ElectricResistanceUnit.Ohm) => new ElectricResistance((_value) * 1e-9d, ElectricResistanceUnit.Ohm), (ElectricResistanceUnit.Teraohm, ElectricResistanceUnit.Ohm) => new ElectricResistance((_value) * 1e12d, ElectricResistanceUnit.Ohm), // BaseUnit -> ElectricResistanceUnit @@ -838,6 +858,7 @@ private bool TryToUnit(ElectricResistanceUnit unit, [NotNullWhen(true)] out Elec (ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Megaohm) => new ElectricResistance((_value) / 1e6d, ElectricResistanceUnit.Megaohm), (ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Microohm) => new ElectricResistance((_value) / 1e-6d, ElectricResistanceUnit.Microohm), (ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Milliohm) => new ElectricResistance((_value) / 1e-3d, ElectricResistanceUnit.Milliohm), + (ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Nanoohm) => new ElectricResistance((_value) / 1e-9d, ElectricResistanceUnit.Nanoohm), (ElectricResistanceUnit.Ohm, ElectricResistanceUnit.Teraohm) => new ElectricResistance((_value) / 1e12d, ElectricResistanceUnit.Teraohm), _ => null diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs new file mode 100644 index 0000000000..f6d6cac96f --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs @@ -0,0 +1,1187 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// Electrical susceptance is the imaginary part of admittance, where the real part is conductance. + /// + /// + /// https://en.wikipedia.org/wiki/Electrical_susceptance + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct ElectricSusceptance : + 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 ElectricSusceptanceUnit? _unit; + + static ElectricSusceptance() + { + BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); + BaseUnit = ElectricSusceptanceUnit.Siemens; + Units = Enum.GetValues(typeof(ElectricSusceptanceUnit)).Cast().ToArray(); + Zero = new ElectricSusceptance(0, BaseUnit); + Info = new QuantityInfo("ElectricSusceptance", + new UnitInfo[] + { + new UnitInfo(ElectricSusceptanceUnit.Gigamho, "Gigamhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Gigasiemens, "Gigasiemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Kilomho, "Kilomhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Kilosiemens, "Kilosiemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Megamho, "Megamhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Megasiemens, "Megasiemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Mho, "Mhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Micromho, "Micromhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Microsiemens, "Microsiemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Millimho, "Millimhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Nanosiemens, "Nanosiemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Siemens, "Siemens", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricSusceptance"), + new UnitInfo(ElectricSusceptanceUnit.Terasiemens, "Terasiemens", BaseUnits.Undefined, "ElectricSusceptance"), + }, + 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 ElectricSusceptance(double value, ElectricSusceptanceUnit 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 ElectricSusceptance(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 ElectricSusceptance, which is Siemens. All conversions go via this value. + /// + public static ElectricSusceptanceUnit BaseUnit { get; } + + /// + /// All units of measurement for the ElectricSusceptance quantity. + /// + public static ElectricSusceptanceUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Siemens. + /// + public static ElectricSusceptance Zero { get; } + + /// + public static ElectricSusceptance 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 ElectricSusceptanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => ElectricSusceptance.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double Gigamhos => As(ElectricSusceptanceUnit.Gigamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Gigasiemens => As(ElectricSusceptanceUnit.Gigasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilomhos => As(ElectricSusceptanceUnit.Kilomho); + + /// + /// Gets a value of this quantity converted into + /// + public double Kilosiemens => As(ElectricSusceptanceUnit.Kilosiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Megamhos => As(ElectricSusceptanceUnit.Megamho); + + /// + /// Gets a value of this quantity converted into + /// + public double Megasiemens => As(ElectricSusceptanceUnit.Megasiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Mhos => As(ElectricSusceptanceUnit.Mho); + + /// + /// Gets a value of this quantity converted into + /// + public double Micromhos => As(ElectricSusceptanceUnit.Micromho); + + /// + /// Gets a value of this quantity converted into + /// + public double Microsiemens => As(ElectricSusceptanceUnit.Microsiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Millimhos => As(ElectricSusceptanceUnit.Millimho); + + /// + /// Gets a value of this quantity converted into + /// + public double Millisiemens => As(ElectricSusceptanceUnit.Millisiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanomhos => As(ElectricSusceptanceUnit.Nanomho); + + /// + /// Gets a value of this quantity converted into + /// + public double Nanosiemens => As(ElectricSusceptanceUnit.Nanosiemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Siemens => As(ElectricSusceptanceUnit.Siemens); + + /// + /// Gets a value of this quantity converted into + /// + public double Teramhos => As(ElectricSusceptanceUnit.Teramho); + + /// + /// Gets a value of this quantity converted into + /// + public double Terasiemens => As(ElectricSusceptanceUnit.Terasiemens); + + #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: ElectricSusceptanceUnit -> BaseUnit + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Gigamho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Gigasiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Kilomho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Kilosiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Megamho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Megasiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Mho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Micromho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Microsiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Millimho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Millisiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Nanomho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Nanosiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Teramho, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Terasiemens, ElectricSusceptanceUnit.Siemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Siemens)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Siemens, quantity => quantity); + + // Register in unit converter: BaseUnit -> ElectricSusceptanceUnit + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Gigamho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Gigamho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Gigasiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Gigasiemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Kilomho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Kilomho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Kilosiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Kilosiemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Megamho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Megamho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Megasiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Megasiemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Mho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Mho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Micromho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Micromho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Microsiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Microsiemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Millimho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Millimho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Millisiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Millisiemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Nanomho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Nanomho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Nanosiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Nanosiemens)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Teramho, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Teramho)); + unitConverter.SetConversionFunction(ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Terasiemens, quantity => quantity.ToUnit(ElectricSusceptanceUnit.Terasiemens)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(ElectricSusceptanceUnit 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(ElectricSusceptanceUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromGigamhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Gigamho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromGigasiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Gigasiemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromKilomhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Kilomho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromKilosiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Kilosiemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMegamhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Megamho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMegasiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Megasiemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Mho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMicromhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Micromho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMicrosiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Microsiemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMillimhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Millimho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromMillisiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Millisiemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromNanomhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Nanomho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromNanosiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Nanosiemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromSiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Siemens); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromTeramhos(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Teramho); + } + + /// + /// Creates a from . + /// + public static ElectricSusceptance FromTerasiemens(double value) + { + return new ElectricSusceptance(value, ElectricSusceptanceUnit.Terasiemens); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricSusceptance unit value. + public static ElectricSusceptance From(double value, ElectricSusceptanceUnit fromUnit) + { + return new ElectricSusceptance(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 ElectricSusceptance 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 ElectricSusceptance Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse([NotNullWhen(true)]string? str, out ElectricSusceptance 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 ElectricSusceptance result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static ElectricSusceptanceUnit 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 ElectricSusceptanceUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit([NotNullWhen(true)]string? str, out ElectricSusceptanceUnit 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 ElectricSusceptanceUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static ElectricSusceptance operator -(ElectricSusceptance right) + { + return new ElectricSusceptance(-right.Value, right.Unit); + } + + /// Get from adding two . + public static ElectricSusceptance operator +(ElectricSusceptance left, ElectricSusceptance right) + { + return new ElectricSusceptance(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static ElectricSusceptance operator -(ElectricSusceptance left, ElectricSusceptance right) + { + return new ElectricSusceptance(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static ElectricSusceptance operator *(double left, ElectricSusceptance right) + { + return new ElectricSusceptance(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static ElectricSusceptance operator *(ElectricSusceptance left, double right) + { + return new ElectricSusceptance(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static ElectricSusceptance operator /(ElectricSusceptance left, double right) + { + return new ElectricSusceptance(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(ElectricSusceptance left, ElectricSusceptance right) + { + return left.Siemens / right.Siemens; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(ElectricSusceptance left, ElectricSusceptance right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(ElectricSusceptance left, ElectricSusceptance right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(ElectricSusceptance left, ElectricSusceptance right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(ElectricSusceptance left, ElectricSusceptance 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(ElectricSusceptance other, ElectricSusceptance 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 ==(ElectricSusceptance left, ElectricSusceptance 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(ElectricSusceptance other, ElectricSusceptance 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 !=(ElectricSusceptance left, ElectricSusceptance right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricSusceptance other, ElectricSusceptance 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 ElectricSusceptance otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(ElectricSusceptance other, ElectricSusceptance 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(ElectricSusceptance 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 ElectricSusceptance otherQuantity)) throw new ArgumentException("Expected type ElectricSusceptance.", 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(ElectricSusceptance other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another ElectricSusceptance 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(ElectricSusceptance other, ElectricSusceptance 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(ElectricSusceptance 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 ElectricSusceptance otherTyped + && (tolerance is ElectricSusceptance toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'ElectricSusceptance'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(ElectricSusceptance other, ElectricSusceptance 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 ElectricSusceptance. + 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(ElectricSusceptanceUnit 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 ElectricSusceptanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSusceptanceUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this ElectricSusceptance to another ElectricSusceptance with the unit representation . + /// + /// The unit to convert to. + /// A ElectricSusceptance with the specified unit. + public ElectricSusceptance ToUnit(ElectricSusceptanceUnit 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 ElectricSusceptance with the specified unit. + public ElectricSusceptance ToUnit(ElectricSusceptanceUnit 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(ElectricSusceptance), Unit, typeof(ElectricSusceptance), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (ElectricSusceptance)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(ElectricSusceptanceUnit unit, [NotNullWhen(true)] out ElectricSusceptance? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + ElectricSusceptance? convertedOrNull = (Unit, unit) switch + { + // ElectricSusceptanceUnit -> BaseUnit + (ElectricSusceptanceUnit.Gigamho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e9d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Gigasiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e9d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Kilomho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e3d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Kilosiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e3d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Megamho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e6d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Megasiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e6d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Mho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance(_value, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Micromho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e-6d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Microsiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e-6d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Millimho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e-3d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Millisiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e-3d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Nanomho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e-9d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Nanosiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e-9d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Teramho, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e12d, ElectricSusceptanceUnit.Siemens), + (ElectricSusceptanceUnit.Terasiemens, ElectricSusceptanceUnit.Siemens) => new ElectricSusceptance((_value) * 1e12d, ElectricSusceptanceUnit.Siemens), + + // BaseUnit -> ElectricSusceptanceUnit + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Gigamho) => new ElectricSusceptance((_value) / 1e9d, ElectricSusceptanceUnit.Gigamho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Gigasiemens) => new ElectricSusceptance((_value) / 1e9d, ElectricSusceptanceUnit.Gigasiemens), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Kilomho) => new ElectricSusceptance((_value) / 1e3d, ElectricSusceptanceUnit.Kilomho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Kilosiemens) => new ElectricSusceptance((_value) / 1e3d, ElectricSusceptanceUnit.Kilosiemens), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Megamho) => new ElectricSusceptance((_value) / 1e6d, ElectricSusceptanceUnit.Megamho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Megasiemens) => new ElectricSusceptance((_value) / 1e6d, ElectricSusceptanceUnit.Megasiemens), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Mho) => new ElectricSusceptance(_value, ElectricSusceptanceUnit.Mho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Micromho) => new ElectricSusceptance((_value) / 1e-6d, ElectricSusceptanceUnit.Micromho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Microsiemens) => new ElectricSusceptance((_value) / 1e-6d, ElectricSusceptanceUnit.Microsiemens), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Millimho) => new ElectricSusceptance((_value) / 1e-3d, ElectricSusceptanceUnit.Millimho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Millisiemens) => new ElectricSusceptance((_value) / 1e-3d, ElectricSusceptanceUnit.Millisiemens), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Nanomho) => new ElectricSusceptance((_value) / 1e-9d, ElectricSusceptanceUnit.Nanomho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Nanosiemens) => new ElectricSusceptance((_value) / 1e-9d, ElectricSusceptanceUnit.Nanosiemens), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Teramho) => new ElectricSusceptance((_value) / 1e12d, ElectricSusceptanceUnit.Teramho), + (ElectricSusceptanceUnit.Siemens, ElectricSusceptanceUnit.Terasiemens) => new ElectricSusceptance((_value) / 1e12d, ElectricSusceptanceUnit.Terasiemens), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is ElectricSusceptanceUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricSusceptanceUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public ElectricSusceptance 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(ElectricSusceptanceUnit 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(ElectricSusceptance)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricSusceptance)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(ElectricSusceptance)} 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(ElectricSusceptance)) + return this; + else if (conversionType == typeof(ElectricSusceptanceUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return ElectricSusceptance.Info; + else if (conversionType == typeof(BaseDimensions)) + return ElectricSusceptance.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(ElectricSusceptance)} 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 index dc49d377e7..d382701342 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.g.cs @@ -38,6 +38,10 @@ namespace UnitsNet /// /// The Volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour. /// + /// + /// has been renamed to , 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 : diff --git a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs index f699569610..aef893d5ba 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactivePower.g.cs @@ -38,6 +38,10 @@ 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. /// + /// + /// has been renamed to , 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 : diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index d8e8d86866..dc8baed7c7 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -57,6 +57,9 @@ public partial class Quantity { "Duration", Duration.Info }, { "DynamicViscosity", DynamicViscosity.Info }, { "ElectricAdmittance", ElectricAdmittance.Info }, + { "ElectricApparentEnergy", ElectricApparentEnergy.Info }, + { "ElectricApparentPower", ElectricApparentPower.Info }, + { "ElectricCapacitance", ElectricCapacitance.Info }, { "ElectricCharge", ElectricCharge.Info }, { "ElectricChargeDensity", ElectricChargeDensity.Info }, { "ElectricConductance", ElectricConductance.Info }, @@ -65,14 +68,19 @@ public partial class Quantity { "ElectricCurrentDensity", ElectricCurrentDensity.Info }, { "ElectricCurrentGradient", ElectricCurrentGradient.Info }, { "ElectricField", ElectricField.Info }, + { "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 }, { "ElectricResistance", ElectricResistance.Info }, { "ElectricResistivity", ElectricResistivity.Info }, { "ElectricSurfaceChargeDensity", ElectricSurfaceChargeDensity.Info }, + { "ElectricSusceptance", ElectricSusceptance.Info }, { "Energy", Energy.Info }, { "EnergyDensity", EnergyDensity.Info }, { "Entropy", Entropy.Info }, @@ -192,6 +200,9 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value "Duration" => Duration.From(value, Duration.BaseUnit), "DynamicViscosity" => DynamicViscosity.From(value, DynamicViscosity.BaseUnit), "ElectricAdmittance" => ElectricAdmittance.From(value, ElectricAdmittance.BaseUnit), + "ElectricApparentEnergy" => ElectricApparentEnergy.From(value, ElectricApparentEnergy.BaseUnit), + "ElectricApparentPower" => ElectricApparentPower.From(value, ElectricApparentPower.BaseUnit), + "ElectricCapacitance" => ElectricCapacitance.From(value, ElectricCapacitance.BaseUnit), "ElectricCharge" => ElectricCharge.From(value, ElectricCharge.BaseUnit), "ElectricChargeDensity" => ElectricChargeDensity.From(value, ElectricChargeDensity.BaseUnit), "ElectricConductance" => ElectricConductance.From(value, ElectricConductance.BaseUnit), @@ -200,14 +211,19 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value "ElectricCurrentDensity" => ElectricCurrentDensity.From(value, ElectricCurrentDensity.BaseUnit), "ElectricCurrentGradient" => ElectricCurrentGradient.From(value, ElectricCurrentGradient.BaseUnit), "ElectricField" => ElectricField.From(value, ElectricField.BaseUnit), + "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), "ElectricResistance" => ElectricResistance.From(value, ElectricResistance.BaseUnit), "ElectricResistivity" => ElectricResistivity.From(value, ElectricResistivity.BaseUnit), "ElectricSurfaceChargeDensity" => ElectricSurfaceChargeDensity.From(value, ElectricSurfaceChargeDensity.BaseUnit), + "ElectricSusceptance" => ElectricSusceptance.From(value, ElectricSusceptance.BaseUnit), "Energy" => Energy.From(value, Energy.BaseUnit), "EnergyDensity" => EnergyDensity.From(value, EnergyDensity.BaseUnit), "Entropy" => Entropy.From(value, Entropy.BaseUnit), @@ -330,6 +346,9 @@ public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQu DurationUnit durationUnit => Duration.From(value, durationUnit), DynamicViscosityUnit dynamicViscosityUnit => DynamicViscosity.From(value, dynamicViscosityUnit), ElectricAdmittanceUnit electricAdmittanceUnit => ElectricAdmittance.From(value, electricAdmittanceUnit), + ElectricApparentEnergyUnit electricApparentEnergyUnit => ElectricApparentEnergy.From(value, electricApparentEnergyUnit), + ElectricApparentPowerUnit electricApparentPowerUnit => ElectricApparentPower.From(value, electricApparentPowerUnit), + ElectricCapacitanceUnit electricCapacitanceUnit => ElectricCapacitance.From(value, electricCapacitanceUnit), ElectricChargeUnit electricChargeUnit => ElectricCharge.From(value, electricChargeUnit), ElectricChargeDensityUnit electricChargeDensityUnit => ElectricChargeDensity.From(value, electricChargeDensityUnit), ElectricConductanceUnit electricConductanceUnit => ElectricConductance.From(value, electricConductanceUnit), @@ -338,14 +357,19 @@ public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQu ElectricCurrentDensityUnit electricCurrentDensityUnit => ElectricCurrentDensity.From(value, electricCurrentDensityUnit), ElectricCurrentGradientUnit electricCurrentGradientUnit => ElectricCurrentGradient.From(value, electricCurrentGradientUnit), ElectricFieldUnit electricFieldUnit => ElectricField.From(value, electricFieldUnit), + 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), ElectricResistanceUnit electricResistanceUnit => ElectricResistance.From(value, electricResistanceUnit), ElectricResistivityUnit electricResistivityUnit => ElectricResistivity.From(value, electricResistivityUnit), ElectricSurfaceChargeDensityUnit electricSurfaceChargeDensityUnit => ElectricSurfaceChargeDensity.From(value, electricSurfaceChargeDensityUnit), + ElectricSusceptanceUnit electricSusceptanceUnit => ElectricSusceptance.From(value, electricSusceptanceUnit), EnergyUnit energyUnit => Energy.From(value, energyUnit), EnergyDensityUnit energyDensityUnit => EnergyDensity.From(value, energyDensityUnit), EntropyUnit entropyUnit => Entropy.From(value, entropyUnit), @@ -478,6 +502,9 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(Duration) => parser.TryParse(quantityString, formatProvider, Duration.From, out quantity), Type _ when quantityType == typeof(DynamicViscosity) => parser.TryParse(quantityString, formatProvider, DynamicViscosity.From, out quantity), Type _ when quantityType == typeof(ElectricAdmittance) => parser.TryParse(quantityString, formatProvider, ElectricAdmittance.From, out quantity), + Type _ when quantityType == typeof(ElectricApparentEnergy) => parser.TryParse(quantityString, formatProvider, ElectricApparentEnergy.From, out quantity), + Type _ when quantityType == typeof(ElectricApparentPower) => parser.TryParse(quantityString, formatProvider, ElectricApparentPower.From, out quantity), + Type _ when quantityType == typeof(ElectricCapacitance) => parser.TryParse(quantityString, formatProvider, ElectricCapacitance.From, out quantity), Type _ when quantityType == typeof(ElectricCharge) => parser.TryParse(quantityString, formatProvider, ElectricCharge.From, out quantity), Type _ when quantityType == typeof(ElectricChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricChargeDensity.From, out quantity), Type _ when quantityType == typeof(ElectricConductance) => parser.TryParse(quantityString, formatProvider, ElectricConductance.From, out quantity), @@ -486,14 +513,19 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(ElectricCurrentDensity) => parser.TryParse(quantityString, formatProvider, ElectricCurrentDensity.From, out quantity), Type _ when quantityType == typeof(ElectricCurrentGradient) => parser.TryParse(quantityString, formatProvider, ElectricCurrentGradient.From, out quantity), Type _ when quantityType == typeof(ElectricField) => parser.TryParse(quantityString, formatProvider, ElectricField.From, out quantity), + 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), Type _ when quantityType == typeof(ElectricResistance) => parser.TryParse(quantityString, formatProvider, ElectricResistance.From, out quantity), Type _ when quantityType == typeof(ElectricResistivity) => parser.TryParse(quantityString, formatProvider, ElectricResistivity.From, out quantity), Type _ when quantityType == typeof(ElectricSurfaceChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricSurfaceChargeDensity.From, out quantity), + Type _ when quantityType == typeof(ElectricSusceptance) => parser.TryParse(quantityString, formatProvider, ElectricSusceptance.From, out quantity), Type _ when quantityType == typeof(Energy) => parser.TryParse(quantityString, formatProvider, Energy.From, out quantity), Type _ when quantityType == typeof(EnergyDensity) => parser.TryParse(quantityString, formatProvider, EnergyDensity.From, out quantity), Type _ when quantityType == typeof(Entropy) => parser.TryParse(quantityString, formatProvider, Entropy.From, out quantity), @@ -607,6 +639,9 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(Duration); yield return typeof(DynamicViscosity); yield return typeof(ElectricAdmittance); + yield return typeof(ElectricApparentEnergy); + yield return typeof(ElectricApparentPower); + yield return typeof(ElectricCapacitance); yield return typeof(ElectricCharge); yield return typeof(ElectricChargeDensity); yield return typeof(ElectricConductance); @@ -615,14 +650,19 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(ElectricCurrentDensity); yield return typeof(ElectricCurrentGradient); yield return typeof(ElectricField); + 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); yield return typeof(ElectricResistance); yield return typeof(ElectricResistivity); yield return typeof(ElectricSurfaceChargeDensity); + yield return typeof(ElectricSusceptance); yield return typeof(Energy); yield return typeof(EnergyDensity); yield return typeof(Entropy); diff --git a/UnitsNet/GeneratedCode/Resources/ElectricAdmittance.restext b/UnitsNet/GeneratedCode/Resources/ElectricAdmittance.restext index 052a7782bf..c0aaccc4d0 100644 --- a/UnitsNet/GeneratedCode/Resources/ElectricAdmittance.restext +++ b/UnitsNet/GeneratedCode/Resources/ElectricAdmittance.restext @@ -1,4 +1,16 @@ +Gigamhos=G? +Gigasiemens=GS +Kilomhos=k? +Kilosiemens=kS +Megamhos=M? +Megasiemens=MS +Mhos=? +Micromhos=µ? Microsiemens=µS +Millimhos=m? Millisiemens=mS +Nanomhos=n? Nanosiemens=nS Siemens=S +Teramhos=T? +Terasiemens=TS diff --git a/UnitsNet/GeneratedCode/Resources/ElectricApparentEnergy.restext b/UnitsNet/GeneratedCode/Resources/ElectricApparentEnergy.restext new file mode 100644 index 0000000000..8042321934 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricApparentEnergy.restext @@ -0,0 +1,3 @@ +KilovoltampereHours=kVAh +MegavoltampereHours=MVAh +VoltampereHours=VAh diff --git a/UnitsNet/GeneratedCode/Resources/ElectricApparentPower.restext b/UnitsNet/GeneratedCode/Resources/ElectricApparentPower.restext new file mode 100644 index 0000000000..fa9f53f44c --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricApparentPower.restext @@ -0,0 +1,6 @@ +Gigavoltamperes=GVA +Kilovoltamperes=kVA +Megavoltamperes=MVA +Microvoltamperes=µVA +Millivoltamperes=mVA +Voltamperes=VA diff --git a/UnitsNet/GeneratedCode/Resources/ElectricCapacitance.restext b/UnitsNet/GeneratedCode/Resources/ElectricCapacitance.restext new file mode 100644 index 0000000000..dff2eb0e40 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricCapacitance.restext @@ -0,0 +1,7 @@ +Farads=F +Kilofarads=kF +Megafarads=MF +Microfarads=µF +Millifarads=mF +Nanofarads=nF +Picofarads=pF diff --git a/UnitsNet/GeneratedCode/Resources/ElectricConductance.restext b/UnitsNet/GeneratedCode/Resources/ElectricConductance.restext index 72b72d444e..c0aaccc4d0 100644 --- a/UnitsNet/GeneratedCode/Resources/ElectricConductance.restext +++ b/UnitsNet/GeneratedCode/Resources/ElectricConductance.restext @@ -1,5 +1,16 @@ +Gigamhos=G? +Gigasiemens=GS +Kilomhos=k? Kilosiemens=kS +Megamhos=M? +Megasiemens=MS +Mhos=? +Micromhos=µ? Microsiemens=µS +Millimhos=m? Millisiemens=mS +Nanomhos=n? Nanosiemens=nS Siemens=S +Teramhos=T? +Terasiemens=TS diff --git a/UnitsNet/GeneratedCode/Resources/ElectricImpedance.restext b/UnitsNet/GeneratedCode/Resources/ElectricImpedance.restext new file mode 100644 index 0000000000..c63f569b80 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricImpedance.restext @@ -0,0 +1,8 @@ +Gigaohms=GΩ +Kiloohms=kΩ +Megaohms=MΩ +Microohms=µΩ +Milliohms=mΩ +Nanoohms=nΩ +Ohms=Ω +Teraohms=TΩ diff --git a/UnitsNet/GeneratedCode/Resources/ElectricReactance.restext b/UnitsNet/GeneratedCode/Resources/ElectricReactance.restext new file mode 100644 index 0000000000..c63f569b80 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricReactance.restext @@ -0,0 +1,8 @@ +Gigaohms=GΩ +Kiloohms=kΩ +Megaohms=MΩ +Microohms=µΩ +Milliohms=mΩ +Nanoohms=nΩ +Ohms=Ω +Teraohms=TΩ diff --git a/UnitsNet/GeneratedCode/Resources/ElectricReactiveEnergy.restext b/UnitsNet/GeneratedCode/Resources/ElectricReactiveEnergy.restext new file mode 100644 index 0000000000..1b5a2f86ac --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricReactiveEnergy.restext @@ -0,0 +1,3 @@ +KilovoltampereReactiveHours=kvarh +MegavoltampereReactiveHours=Mvarh +VoltampereReactiveHours=varh diff --git a/UnitsNet/GeneratedCode/Resources/ElectricReactivePower.restext b/UnitsNet/GeneratedCode/Resources/ElectricReactivePower.restext new file mode 100644 index 0000000000..713ea6becd --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricReactivePower.restext @@ -0,0 +1,4 @@ +GigavoltamperesReactive=Gvar +KilovoltamperesReactive=kvar +MegavoltamperesReactive=Mvar +VoltamperesReactive=var diff --git a/UnitsNet/GeneratedCode/Resources/ElectricResistance.restext b/UnitsNet/GeneratedCode/Resources/ElectricResistance.restext index b49c0108bf..c63f569b80 100644 --- a/UnitsNet/GeneratedCode/Resources/ElectricResistance.restext +++ b/UnitsNet/GeneratedCode/Resources/ElectricResistance.restext @@ -3,5 +3,6 @@ Kiloohms=kΩ Megaohms=MΩ Microohms=µΩ Milliohms=mΩ +Nanoohms=nΩ Ohms=Ω Teraohms=TΩ diff --git a/UnitsNet/GeneratedCode/Resources/ElectricSusceptance.restext b/UnitsNet/GeneratedCode/Resources/ElectricSusceptance.restext new file mode 100644 index 0000000000..21df189425 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/ElectricSusceptance.restext @@ -0,0 +1,16 @@ +Gigamhos=G℧ +Gigasiemens=GS +Kilomhos=k℧ +Kilosiemens=kS +Megamhos=M℧ +Megasiemens=MS +Mhos=℧ +Micromhos=µ℧ +Microsiemens=µS +Millimhos=m℧ +Millisiemens=mS +Nanomhos=n℧ +Nanosiemens=nS +Siemens=S +Teramhos=T℧ +Terasiemens=TS diff --git a/UnitsNet/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs index 622b45de43..1e5e7c9a0b 100644 --- a/UnitsNet/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/ElectricAdmittanceUnit.g.cs @@ -25,10 +25,22 @@ namespace UnitsNet.Units public enum ElectricAdmittanceUnit { + Gigamho = 7, + Gigasiemens = 14, + Kilomho = 11, + Kilosiemens = 9, + Megamho = 8, + Megasiemens = 6, + Mho = 13, + Micromho = 5, Microsiemens = 1, + Millimho = 10, Millisiemens = 2, + Nanomho = 12, Nanosiemens = 3, Siemens = 4, + Teramho = 19, + Terasiemens = 16, } #pragma warning restore 1591 diff --git a/UnitsNet/GeneratedCode/Units/ElectricApparentEnergyUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricApparentEnergyUnit.g.cs new file mode 100644 index 0000000000..f46ab5ea10 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricApparentEnergyUnit.g.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricApparentEnergyUnit + { + KilovoltampereHour = 1, + MegavoltampereHour = 2, + VoltampereHour = 3, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricApparentPowerUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricApparentPowerUnit.g.cs new file mode 100644 index 0000000000..71b500b242 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricApparentPowerUnit.g.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricApparentPowerUnit + { + Gigavoltampere = 9, + Kilovoltampere = 3, + Megavoltampere = 8, + Microvoltampere = 5, + Millivoltampere = 7, + Voltampere = 1, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricCapacitanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricCapacitanceUnit.g.cs new file mode 100644 index 0000000000..b3b88398f2 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricCapacitanceUnit.g.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricCapacitanceUnit + { + Farad = 5, + Kilofarad = 7, + Megafarad = 4, + Microfarad = 6, + Millifarad = 10, + Nanofarad = 9, + Picofarad = 8, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs index f2003b8384..da5b831bde 100644 --- a/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/ElectricConductanceUnit.g.cs @@ -25,11 +25,22 @@ namespace UnitsNet.Units public enum ElectricConductanceUnit { + Gigamho = 15, + Gigasiemens = 5, + Kilomho = 7, Kilosiemens = 6, + Megamho = 13, + Megasiemens = 12, + Mho = 9, + Micromho = 11, Microsiemens = 1, + Millimho = 8, Millisiemens = 2, + Nanomho = 4, Nanosiemens = 10, Siemens = 3, + Teramho = 14, + Terasiemens = 17, } #pragma warning restore 1591 diff --git a/UnitsNet/GeneratedCode/Units/ElectricImpedanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricImpedanceUnit.g.cs new file mode 100644 index 0000000000..61c6ece8b8 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricImpedanceUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricImpedanceUnit + { + Gigaohm = 10, + Kiloohm = 6, + Megaohm = 7, + Microohm = 2, + Milliohm = 1, + Nanoohm = 4, + Ohm = 9, + Teraohm = 8, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricReactanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricReactanceUnit.g.cs new file mode 100644 index 0000000000..fc88bedac4 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricReactanceUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricReactanceUnit + { + Gigaohm = 3, + Kiloohm = 8, + Megaohm = 10, + Microohm = 7, + Milliohm = 4, + Nanoohm = 2, + Ohm = 1, + Teraohm = 5, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricReactiveEnergyUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricReactiveEnergyUnit.g.cs new file mode 100644 index 0000000000..92cc518be5 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricReactiveEnergyUnit.g.cs @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricReactiveEnergyUnit + { + KilovoltampereReactiveHour = 9, + MegavoltampereReactiveHour = 7, + VoltampereReactiveHour = 6, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricReactivePowerUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricReactivePowerUnit.g.cs new file mode 100644 index 0000000000..5f9c0a59e3 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricReactivePowerUnit.g.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// 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 ElectricReactivePowerUnit + { + GigavoltampereReactive = 3, + KilovoltampereReactive = 8, + MegavoltampereReactive = 5, + VoltampereReactive = 2, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/ElectricResistanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricResistanceUnit.g.cs index 452a17522a..8a17f875f7 100644 --- a/UnitsNet/GeneratedCode/Units/ElectricResistanceUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/ElectricResistanceUnit.g.cs @@ -30,6 +30,7 @@ public enum ElectricResistanceUnit Megaohm = 3, Microohm = 4, Milliohm = 5, + Nanoohm = 14, Ohm = 6, Teraohm = 12, } diff --git a/UnitsNet/GeneratedCode/Units/ElectricSusceptanceUnit.g.cs b/UnitsNet/GeneratedCode/Units/ElectricSusceptanceUnit.g.cs new file mode 100644 index 0000000000..b657aec9ce --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/ElectricSusceptanceUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\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 ElectricSusceptanceUnit + { + Gigamho = 4, + Gigasiemens = 5, + Kilomho = 8, + Kilosiemens = 9, + Megamho = 10, + Megasiemens = 6, + Mho = 2, + Micromho = 3, + Microsiemens = 1, + Millimho = 7, + Millisiemens = 16, + Nanomho = 13, + Nanosiemens = 20, + Siemens = 15, + Teramho = 18, + Terasiemens = 17, + } + + #pragma warning restore 1591 +}