Skip to content

Commit 6b05cc8

Browse files
McNeightangularsen
andauthored
Add/rename electric quantities (#1444)
Renamed quantities to have prefix "Electric", marking old name as obsolete and adding new duplicate quantities: * `ApparentEnergy` -> `ElectricApparentEnergy` * `ApparentPower` -> `ElectricApparentPower` * `Capacitance` -> `ElectricCapacitance` * `ReactiveEnergy` -> `ElectricReactiveEnergy` * `ReactivePower` -> `ElectricReactivePower ` * `ElectricPotentialAc` * `ElectricPotentialDc` * `ElectricAdmittance` (obsolete due to being a complex number, not supported by UnitsNet, recommending `ElectricReactance` and `ElectricSusceptance` instead) Decided against adding `ElectricImpedance`, also being a complex number. New: - Add `ElectricReactance` - Add `ElectricSusceptance` - Add `EletricCurrent = ElectricApparentPower / ElectricPotential` - Add `ElectricPotential = ElectricApparentPower / ElectricCurrent` - `ElectricAdmittance`: - Add prefixes: Kilo, Mega, Giga, Tera - Add Mho unit, equivalent to Siemen - `ElectricConductance`: - Add prefixes: Mega, Giga, Tera - Add Mho unit, equivalent to Siemen - `EletricResistance`: - Add prefixes: Nano --------- Co-authored-by: Andreas Gullberg Larsen <[email protected]>
1 parent 52aba98 commit 6b05cc8

File tree

177 files changed

+22344
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+22344
-101
lines changed

CodeGen/Generators/UnitsNetGen/NumberExtensionsGenerator.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,11 @@
33

44
namespace CodeGen.Generators.UnitsNetGen
55
{
6-
internal class NumberExtensionsGenerator : GeneratorBase
6+
internal class NumberExtensionsGenerator(Quantity quantity) : GeneratorBase
77
{
8-
private readonly Unit[] _units;
9-
private readonly string _quantityName;
10-
11-
public NumberExtensionsGenerator(Quantity quantity)
12-
{
13-
if (quantity is null)
14-
throw new ArgumentNullException(nameof(quantity));
15-
16-
_units = quantity.Units;
17-
_quantityName = quantity.Name;
18-
}
8+
private readonly Quantity _quantity = quantity ?? throw new ArgumentNullException(nameof(quantity));
9+
private readonly Unit[] _units = quantity.Units;
10+
private readonly string _quantityName = quantity.Name;
1911

2012
public string Generate()
2113
{
@@ -35,7 +27,10 @@ namespace UnitsNet.NumberExtensions.NumberTo{_quantityName}
3527
{{
3628
/// <summary>
3729
/// A number to {_quantityName} Extensions
38-
/// </summary>
30+
/// </summary>");
31+
32+
Writer.WLIfText(1, GetObsoleteAttributeOrNull(_quantity));
33+
Writer.WL(@$"
3934
public static class NumberTo{_quantityName}Extensions
4035
{{");
4136

@@ -47,7 +42,8 @@ public static class NumberTo{_quantityName}Extensions
4742
Writer.WL(2, $@"
4843
/// <inheritdoc cref=""{_quantityName}.From{unit.PluralName}(UnitsNet.QuantityValue)"" />");
4944

50-
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit.ObsoleteText));
45+
// Include obsolete text from the quantity per extension method, to make it visible when the class is not explicitly referenced in code.
46+
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit.ObsoleteText ?? _quantity.ObsoleteText));
5147

5248
Writer.WL(2, $@"public static {_quantityName} {unit.PluralName}<T>(this T value)
5349
where T : notnull
@@ -63,6 +59,9 @@ public static class NumberTo{_quantityName}Extensions
6359
return Writer.ToString();
6460
}
6561

62+
/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
63+
private static string? GetObsoleteAttributeOrNull(Quantity quantity) => GetObsoleteAttributeOrNull(quantity.ObsoleteText);
64+
6665
private static string? GetObsoleteAttributeOrNull(string? obsoleteText) =>
6766
string.IsNullOrWhiteSpace(obsoleteText) ?
6867
null :

Common/UnitDefinitions/ApparentEnergy.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"Name": "ApparentEnergy",
33
"BaseUnit": "VoltampereHour",
44
"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.",
5+
"XmlDocRemarks": "<see cref=\"ApparentEnergy\" /> has been renamed to <see cref=\"ElectricApparentEnergy\" />, and will be removed in a later major version.",
6+
"ObsoleteText": "ApparentEnergy has been renamed to ElectricApparentEnergy, and will be removed in a later major version.",
57
"BaseDimensions": {
68
"L": 2,
79
"M": 1,

Common/UnitDefinitions/ApparentPower.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"Name": "ApparentPower",
33
"BaseUnit": "Voltampere",
44
"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.",
5+
"XmlDocRemarks": "<see cref=\"ApparentPower\" /> has been renamed to <see cref=\"ElectricApparentPower\" />, and will be removed in a later major version.",
6+
"ObsoleteText": "ApparentPower has been renamed to ElectricApparentPower, and will be removed in a later major version.",
57
"BaseDimensions": {
68
"L": 2,
79
"M": 1,

Common/UnitDefinitions/Capacitance.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"Name": "Capacitance",
33
"BaseUnit": "Farad",
44
"XmlDocSummary": "Capacitance is the ability of a body to store an electric charge.",
5-
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Capacitance",
5+
"XmlDocRemarks": "<see cref=\"Capacitance\" /> has been renamed to <see cref=\"ElectricCapacitance\" />, and will be removed in a later major version.",
6+
"ObsoleteText": "Capacitance has been renamed to ElectricCapacitance, and will be removed in a later major version.",
67
"BaseDimensions": {
78
"L": -2,
89
"M": -1,

Common/UnitDefinitions/ElectricAdmittance.json

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"Name": "ElectricAdmittance",
33
"BaseUnit": "Siemens",
4-
"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).",
4+
"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).",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_admittance",
6+
"ObsoleteText": "Admittance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricConductance or ElectricSusceptance instead.",
57
"BaseDimensions": {
68
"L": -2,
79
"M": -1,
@@ -14,13 +16,26 @@
1416
"PluralName": "Siemens",
1517
"FromUnitToBaseFunc": "{x}",
1618
"FromBaseToUnitFunc": "{x}",
17-
"Prefixes": [ "Nano", "Micro", "Milli" ],
19+
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ],
1820
"Localization": [
1921
{
2022
"Culture": "en-US",
2123
"Abbreviations": [ "S" ]
2224
}
2325
]
26+
},
27+
{
28+
"SingularName": "Mho",
29+
"PluralName": "Mhos",
30+
"FromUnitToBaseFunc": "{x}",
31+
"FromBaseToUnitFunc": "{x}",
32+
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ],
33+
"Localization": [
34+
{
35+
"Culture": "en-US",
36+
"Abbreviations": [ "" ]
37+
}
38+
]
2439
}
2540
]
2641
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Name": "ElectricApparentEnergy",
3+
"BaseUnit": "VoltampereHour",
4+
"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.",
5+
"BaseDimensions": {
6+
"L": 2,
7+
"M": 1,
8+
"T": -2
9+
},
10+
"Units": [
11+
{
12+
"SingularName": "VoltampereHour",
13+
"PluralName": "VoltampereHours",
14+
"FromUnitToBaseFunc": "{x}",
15+
"FromBaseToUnitFunc": "{x}",
16+
"Prefixes": [ "Kilo", "Mega" ],
17+
"Localization": [
18+
{
19+
"Culture": "en-US",
20+
"Abbreviations": [ "VAh" ]
21+
}
22+
]
23+
}
24+
]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"Name": "ElectricApparentPower",
3+
"BaseUnit": "Voltampere",
4+
"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).",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state",
6+
"BaseDimensions": {
7+
"L": 2,
8+
"M": 1,
9+
"T": -3
10+
},
11+
"Units": [
12+
{
13+
"SingularName": "Voltampere",
14+
"PluralName": "Voltamperes",
15+
"FromUnitToBaseFunc": "{x}",
16+
"FromBaseToUnitFunc": "{x}",
17+
"Prefixes": [ "Micro", "Milli", "Kilo", "Mega", "Giga" ],
18+
"Localization": [
19+
{
20+
"Culture": "en-US",
21+
"Abbreviations": [ "VA" ]
22+
}
23+
]
24+
}
25+
]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"Name": "ElectricCapacitance",
3+
"BaseUnit": "Farad",
4+
"XmlDocSummary": "Capacitance is the capacity of a material object or device to store electric charge.",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Capacitance",
6+
"BaseDimensions": {
7+
"L": -2,
8+
"M": -1,
9+
"T": 4,
10+
"I": 2
11+
},
12+
"Units": [
13+
{
14+
"SingularName": "Farad",
15+
"PluralName": "Farads",
16+
"BaseUnits": {
17+
"L": "Meter",
18+
"M": "Kilogram",
19+
"T": "Second",
20+
"I": "Ampere"
21+
},
22+
"FromUnitToBaseFunc": "{x}",
23+
"FromBaseToUnitFunc": "{x}",
24+
"Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ],
25+
"Localization": [
26+
{
27+
"Culture": "en-US",
28+
"Abbreviations": [ "F" ]
29+
}
30+
]
31+
}
32+
]
33+
}

Common/UnitDefinitions/ElectricConductance.json

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Name": "ElectricConductance",
33
"BaseUnit": "Siemens",
4-
"XmlDocSummary": "The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor.",
4+
"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.",
55
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance",
66
"BaseDimensions": {
77
"L": -2,
@@ -15,13 +15,26 @@
1515
"PluralName": "Siemens",
1616
"FromUnitToBaseFunc": "{x}",
1717
"FromBaseToUnitFunc": "{x}",
18-
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo" ],
18+
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ],
1919
"Localization": [
2020
{
2121
"Culture": "en-US",
2222
"Abbreviations": [ "S" ]
2323
}
2424
]
25+
},
26+
{
27+
"SingularName": "Mho",
28+
"PluralName": "Mhos",
29+
"FromUnitToBaseFunc": "{x}",
30+
"FromBaseToUnitFunc": "{x}",
31+
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ],
32+
"Localization": [
33+
{
34+
"Culture": "en-US",
35+
"Abbreviations": [ "" ]
36+
}
37+
]
2538
}
2639
]
2740
}

Common/UnitDefinitions/ElectricCurrent.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Name": "ElectricCurrent",
33
"BaseUnit": "Ampere",
44
"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.",
5+
"XmlDocRemarks": "If you want to map more parameters into the <see cref=\"ElectricCurrent\" /> class (amps RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.",
56
"BaseDimensions": {
67
"I": 1
78
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"Name": "ElectricImpedance",
3+
"BaseUnit": "Ohm",
4+
"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 Ω).",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_impedance",
6+
"ObsoleteText": "Impedance is a complex number, which is not currently supported by UnitsNet. Please use either ElectricResistance or ElectricReactance instead.",
7+
"BaseDimensions": {
8+
"L": 2,
9+
"M": 1,
10+
"T": -3,
11+
"I": -2
12+
},
13+
"Units": [
14+
{
15+
"SingularName": "Ohm",
16+
"PluralName": "Ohms",
17+
"FromUnitToBaseFunc": "{x}",
18+
"FromBaseToUnitFunc": "{x}",
19+
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ],
20+
"Localization": [
21+
{
22+
"Culture": "en-US",
23+
"Abbreviations": [ "Ω" ]
24+
}
25+
]
26+
}
27+
]
28+
}

Common/UnitDefinitions/ElectricPotential.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Name": "ElectricPotential",
33
"BaseUnit": "Volt",
44
"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.",
5+
"XmlDocRemarks": "If you want to map more parameters into the <see cref=\"ElectricPotential\" /> class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.",
56
"BaseDimensions": {
67
"L": 2,
78
"M": 1,

Common/UnitDefinitions/ElectricPotentialAc.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"Name": "ElectricPotentialAc",
33
"BaseUnit": "VoltAc",
44
"XmlDocSummary": "The Electric Potential of a system known to use Alternating Current.",
5+
"XmlDocRemarks": "<see cref=\"ElectricPotentialAc\" /> has been merged into <see cref=\"ElectricPotential\" />, and will be removed in a later major version. If you want to map more parameters into the <see cref=\"ElectricPotential\" /> class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.",
6+
"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.",
57
"Units": [
68
{
79
"SingularName": "VoltAc",

Common/UnitDefinitions/ElectricPotentialDc.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"Name": "ElectricPotentialDc",
33
"BaseUnit": "VoltDc",
44
"XmlDocSummary": "The Electric Potential of a system known to use Direct Current.",
5+
"XmlDocRemarks": "<see cref=\"ElectricPotentialDc\" /> has been merged into <see cref=\"ElectricPotential\" />, and will be removed in a later major version. If you want to map more parameters into the <see cref=\"ElectricPotential\" /> class (volts RMS, phase angle, etc.), create your own wrapper type such as a record or named tuple.",
6+
"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.",
57
"Units": [
68
{
79
"SingularName": "VoltDc",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Name": "ElectricReactance",
3+
"BaseUnit": "Ohm",
4+
"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.",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Electrical_reactance",
6+
"BaseDimensions": {
7+
"L": 2,
8+
"M": 1,
9+
"T": -3,
10+
"I": -2
11+
},
12+
"Units": [
13+
{
14+
"SingularName": "Ohm",
15+
"PluralName": "Ohms",
16+
"FromUnitToBaseFunc": "{x}",
17+
"FromBaseToUnitFunc": "{x}",
18+
"Prefixes": [ "Nano", "Micro", "Milli", "Kilo", "Mega", "Giga", "Tera" ],
19+
"Localization": [
20+
{
21+
"Culture": "en-US",
22+
"Abbreviations": [ "Ω" ]
23+
}
24+
]
25+
}
26+
]
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Name": "ElectricReactiveEnergy",
3+
"BaseUnit": "VoltampereReactiveHour",
4+
"XmlDocSummary": "The volt-ampere reactive hour (expressed as varh) is the reactive power of one Volt-ampere reactive produced in one hour.",
5+
"BaseDimensions": {
6+
"L": 2,
7+
"M": 1,
8+
"T": -2
9+
},
10+
"Units": [
11+
{
12+
"SingularName": "VoltampereReactiveHour",
13+
"PluralName": "VoltampereReactiveHours",
14+
"FromUnitToBaseFunc": "{x}",
15+
"FromBaseToUnitFunc": "{x}",
16+
"Prefixes": [ "Kilo", "Mega" ],
17+
"Localization": [
18+
{
19+
"Culture": "en-US",
20+
"Abbreviations": [ "varh" ]
21+
}
22+
]
23+
}
24+
]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"Name": "ElectricReactivePower",
3+
"BaseUnit": "VoltampereReactive",
4+
"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.",
5+
"XmlDocRemarks": "https://en.wikipedia.org/wiki/AC_power#Active,_reactive,_apparent,_and_complex_power_in_sinusoidal_steady-state",
6+
"BaseDimensions": {
7+
"L": 2,
8+
"M": 1,
9+
"T": -3
10+
},
11+
"Units": [
12+
{
13+
"SingularName": "VoltampereReactive",
14+
"PluralName": "VoltamperesReactive",
15+
"FromUnitToBaseFunc": "{x}",
16+
"FromBaseToUnitFunc": "{x}",
17+
"Prefixes": [ "Kilo", "Mega", "Giga" ],
18+
"Localization": [
19+
{
20+
"Culture": "en-US",
21+
"Abbreviations": [ "var" ]
22+
}
23+
]
24+
}
25+
]
26+
}

0 commit comments

Comments
 (0)