Skip to content

Commit 2ac3232

Browse files
committed
Except for the tests, it compiles again
1 parent 0f1233b commit 2ac3232

File tree

121 files changed

+1184
-20
lines changed

Some content is hidden

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

121 files changed

+1184
-20
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,16 @@ double IQuantity.As(Enum unit)
912912
return ToUnit(unit, DefaultConversionFunctions);
913913
}}
914914
915+
/// <summary>
916+
/// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation <paramref name=""unit"" /> and returns its see <cref name=""QuantityValue"" />.
917+
/// </summary>
918+
/// <param name=""unit"">The unit to convert to.</param>
919+
/// <returns>A {_quantity.Name} with the specified unit.</returns>
920+
public QuantityValue ToQuantity({_unitEnumName} unit)
921+
{{
922+
return ((IQuantity)ToUnit(unit, DefaultConversionFunctions)).Value;
923+
}}
924+
915925
/// <summary>
916926
/// Converts this {_quantity.Name} to another {_quantity.Name} using the given <paramref name=""unitConverter""/> with the unit representation <paramref name=""unit"" />.
917927
/// </summary>

UnitsNet.Serialization.JsonNet.Tests/UnitsNetBaseJsonConverterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void UnitsNetBaseJsonConverter_ConvertValueUnit_works_as_expected()
5454

5555
Assert.NotNull(result);
5656
Assert.IsType<Power>(result);
57-
Assert.True(Power.FromWatts(10.2365m).Equals((Power)result, 1E-5, ComparisonType.Absolute));
57+
Assert.True(Power.FromWatts(10.2365m).Equals((Power)result, 1E-5M, ComparisonType.Absolute));
5858

5959
}
6060

UnitsNet.Serialization.JsonNet.Tests/UnitsNetIComparableJsonConverterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void UnitsNetIComparableJsonConverter_ReadJson_works_as_expected()
117117

118118
Assert.NotNull(result);
119119
Assert.IsType<Power>(result);
120-
Assert.Equal(120D, ((Power)result).Watts);
120+
Assert.Equal(120M, ((Power)result).Watts);
121121
}
122122
}
123123
}

UnitsNet.Serialization.JsonNet.Tests/UnitsNetIQuantityJsonConverterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void UnitsNetIQuantityJsonConverter_ReadJson_works_as_expected()
135135

136136
Assert.NotNull(result);
137137
Assert.IsType<Power>(result);
138-
Assert.Equal(10.3654D, ((Power)result).Watts);
138+
Assert.Equal(10.3654M, ((Power)result).Watts);
139139
}
140140
}
141141
}

UnitsNet/CustomCode/Quantities/BrakeSpecificFuelConsumption.extra.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using UnitsNet.Units;
5+
46
namespace UnitsNet
57
{
68
public partial struct BrakeSpecificFuelConsumption
79
{
810
/// <summary>Get <see cref="MassFlow"/> from <see cref="BrakeSpecificFuelConsumption"/> times <see cref="Power"/>.</summary>
911
public static MassFlow operator *(BrakeSpecificFuelConsumption bsfc, Power power)
1012
{
11-
return MassFlow.FromKilogramsPerSecond(bsfc.KilogramsPerJoule*power.Watts);
13+
return MassFlow.FromKilogramsPerSecond(bsfc.KilogramsPerJoule * power.ToQuantity(PowerUnit.Watt));
1214
}
1315

1416
/// <summary>Get <see cref="SpecificEnergy"/> from <paramref name="value"/> divided by <see cref="BrakeSpecificFuelConsumption"/>.</summary>

UnitsNet/CustomCode/Quantities/MassFlow.extra.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
5+
using UnitsNet.Units;
56

67
namespace UnitsNet
78
{
@@ -40,7 +41,7 @@ public partial struct MassFlow
4041
/// <summary>Get <see cref="BrakeSpecificFuelConsumption"/> from <see cref="MassFlow"/> divided by <see cref="Power"/>.</summary>
4142
public static BrakeSpecificFuelConsumption operator /(MassFlow massFlow, Power power)
4243
{
43-
return BrakeSpecificFuelConsumption.FromKilogramsPerJoule(massFlow.KilogramsPerSecond / power.Watts);
44+
return BrakeSpecificFuelConsumption.FromKilogramsPerJoule(massFlow.KilogramsPerSecond / power.ToQuantity(PowerUnit.Watt));
4445
}
4546

4647
/// <summary>Get <see cref="Power"/> from <see cref="MassFlow"/> times <see cref="SpecificEnergy"/>.</summary>

UnitsNet/CustomCode/Quantities/Power.extra.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

44
using System;
5+
using UnitsNet.Units;
56

67
namespace UnitsNet
78
{
@@ -24,87 +25,87 @@ public PowerRatio ToPowerRatio()
2425
/// <summary>Get <see cref="Energy"/> from <see cref="Power"/> times <see cref="TimeSpan"/>.</summary>
2526
public static Energy operator *(Power power, TimeSpan time)
2627
{
27-
return Energy.FromJoules(power.Watts * time.TotalSeconds);
28+
return Energy.FromJoules(power.ToQuantity(PowerUnit.Watt) * time.TotalSeconds);
2829
}
2930

3031
/// <summary>Get <see cref="Energy"/> from <see cref="TimeSpan"/> times <see cref="Power"/>.</summary>
3132
public static Energy operator *(TimeSpan time, Power power)
3233
{
33-
return Energy.FromJoules(power.Watts * time.TotalSeconds);
34+
return Energy.FromJoules(power.ToQuantity(PowerUnit.Watt) * time.TotalSeconds);
3435
}
3536

3637
/// <summary>Get <see cref="Energy"/> from <see cref="Power"/> times <see cref="Duration"/>.</summary>
3738
public static Energy operator *(Power power, Duration duration)
3839
{
39-
return Energy.FromJoules(power.Watts * duration.Seconds);
40+
return Energy.FromJoules(power.ToQuantity(PowerUnit.Watt) * duration.Seconds);
4041
}
4142

4243
/// <summary>Get <see cref="Energy"/> from <see cref="Duration"/> times <see cref="Power"/>.</summary>
4344
public static Energy operator *(Duration duration, Power power)
4445
{
45-
return Energy.FromJoules(power.Watts * duration.Seconds);
46+
return Energy.FromJoules(power.ToQuantity(PowerUnit.Watt) * duration.Seconds);
4647
}
4748

4849
/// <summary>Get <see cref="Force"/> from <see cref="Power"/> divided by <see cref="Speed"/>.</summary>
4950
public static Force operator /(Power power, Speed speed)
5051
{
51-
return Force.FromNewtons(power.Watts / speed.MetersPerSecond);
52+
return Force.FromNewtons(power.ToQuantity(PowerUnit.Watt) / speed.MetersPerSecond);
5253
}
5354

5455
/// <summary>Get <see cref="Torque"/> from <see cref="Power"/> divided by <see cref="RotationalSpeed"/>.</summary>
5556
public static Torque operator /(Power power, RotationalSpeed rotationalSpeed)
5657
{
57-
return Torque.FromNewtonMeters(power.Watts / rotationalSpeed.RadiansPerSecond);
58+
return Torque.FromNewtonMeters(power.ToQuantity(PowerUnit.Watt) / rotationalSpeed.RadiansPerSecond);
5859
}
5960

6061
/// <summary>Get <see cref="RotationalSpeed"/> from <see cref="Power"/> divided by <see cref="Torque"/>.</summary>
6162
public static RotationalSpeed operator /(Power power, Torque torque)
6263
{
63-
return RotationalSpeed.FromRadiansPerSecond(power.Watts / torque.NewtonMeters);
64+
return RotationalSpeed.FromRadiansPerSecond(power.ToQuantity(PowerUnit.Watt) / torque.NewtonMeters);
6465
}
6566

6667
/// <summary>Get <see cref="MassFlow"/> from <see cref="Power"/> times <see cref="BrakeSpecificFuelConsumption"/>.</summary>
6768
public static MassFlow operator *(Power power, BrakeSpecificFuelConsumption bsfc)
6869
{
69-
return MassFlow.FromKilogramsPerSecond(bsfc.KilogramsPerJoule * power.Watts);
70+
return MassFlow.FromKilogramsPerSecond(bsfc.KilogramsPerJoule * power.ToQuantity(PowerUnit.Watt));
7071
}
7172

7273
/// <summary>Get <see cref="SpecificEnergy"/> from <see cref="Power"/> divided by <see cref="MassFlow"/>.</summary>
7374
public static SpecificEnergy operator /(Power power, MassFlow massFlow)
7475
{
75-
return SpecificEnergy.FromJoulesPerKilogram(power.Watts / massFlow.KilogramsPerSecond);
76+
return SpecificEnergy.FromJoulesPerKilogram(power.ToQuantity(PowerUnit.Watt) / massFlow.KilogramsPerSecond);
7677
}
7778

7879
/// <summary>Get <see cref="MassFlow"/> from <see cref="Power"/> divided by <see cref="SpecificEnergy"/>.</summary>
7980
public static MassFlow operator /(Power power, SpecificEnergy specificEnergy)
8081
{
81-
return MassFlow.FromKilogramsPerSecond(power.Watts / specificEnergy.JoulesPerKilogram);
82+
return MassFlow.FromKilogramsPerSecond(power.ToQuantity(PowerUnit.Watt) / specificEnergy.JoulesPerKilogram);
8283
}
8384

8485
/// <summary>Get <see cref="HeatFlux"/> from <see cref="Power"/> divided by <see cref="Area"/>.</summary>
8586
public static HeatFlux operator /(Power power, Area area)
8687
{
87-
return HeatFlux.FromWattsPerSquareMeter(power.Watts / area.SquareMeters);
88+
return HeatFlux.FromWattsPerSquareMeter(power.ToQuantity(PowerUnit.Watt) / area.SquareMeters);
8889
}
8990

9091
/// <summary>Get <see cref="Area"/> from <see cref="Power"/> divided by <see cref="HeatFlux"/>.</summary>
9192
public static Area operator /(Power power, HeatFlux heatFlux)
9293
{
93-
return Area.FromSquareMeters( power.Watts / heatFlux.WattsPerSquareMeter );
94+
return Area.FromSquareMeters(power.ToQuantity(PowerUnit.Watt) / heatFlux.WattsPerSquareMeter );
9495
}
9596

9697
/// <summary>Calculate <see cref="ElectricCurrent"/> from <see cref="Power"/> divided by <see cref="ElectricPotential"/>.</summary>
9798
/// <remarks>Electric power is defined as P = U * I, so I = P / U.</remarks>
9899
public static ElectricCurrent operator /(Power power, ElectricPotential potential)
99100
{
100-
return ElectricCurrent.FromAmperes(power.Watts / potential.Volts);
101+
return ElectricCurrent.FromAmperes(power.ToQuantity(PowerUnit.Watt) / potential.Volts);
101102
}
102103

103104
/// <summary>Calculate <see cref="ElectricPotential"/> from <see cref="Power"/> divided by <see cref="ElectricCurrent"/>.</summary>
104105
/// <remarks>Electric power is defined as P = U * I, so I = P / U.</remarks>
105106
public static ElectricPotential operator /(Power power, ElectricCurrent current)
106107
{
107-
return ElectricPotential.FromVolts(power.Watts / current.Amperes);
108+
return ElectricPotential.FromVolts(power.ToQuantity(PowerUnit.Watt) / current.Amperes);
108109
}
109110
}
110111
}

UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public PowerRatio(Power power)
2121
nameof(power), "The base-10 logarithm of a number ≤ 0 is undefined. Power must be greater than 0 W.");
2222

2323
// P(dBW) = 10*log10(value(W)/reference(W))
24-
_value = 10 * Math.Log10(power.Watts / 1);
24+
_value = 10 * Math.Log10((double)power.Watts);
2525
_unit = PowerRatioUnit.DecibelWatt;
2626
}
2727

UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Area.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/BitRate.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)