Skip to content

Commit 446c720

Browse files
committed
Fix compile errors in custom code
Access unit property instead of base unit value field.
1 parent b4b0143 commit 446c720

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// THE SOFTWARE.
2121

2222
using System;
23+
using UnitsNet.Units;
2324

2425
namespace UnitsNet
2526
{
@@ -55,7 +56,8 @@ public partial struct AmplitudeRatio
5556
"The base-10 logarithm of a number ≤ 0 is undefined. Voltage must be greater than 0 V.");
5657

5758
// E(dBV) = 20*log10(value(V)/reference(V))
58-
_decibelVolts = 20 * Math.Log10(voltage.Volts / 1);
59+
_value = 20 * Math.Log10(voltage.Volts / 1);
60+
_unit = AmplitudeRatioUnit.DecibelVolt;
5961
}
6062

6163
/// <summary>
@@ -75,7 +77,7 @@ public static AmplitudeRatio FromElectricPotential(ElectricPotential voltage)
7577
public static ElectricPotential ToElectricPotential(AmplitudeRatio voltageRatio)
7678
{
7779
// E(V) = 1V * 10^(E(dBV)/20)
78-
return ElectricPotential.FromVolts(Math.Pow(10, voltageRatio._decibelVolts / 20));
80+
return ElectricPotential.FromVolts(Math.Pow(10, voltageRatio.DecibelVolts / 20));
7981
}
8082

8183
/// <summary>
@@ -90,4 +92,4 @@ public static PowerRatio ToPowerRatio(AmplitudeRatio amplitudeRatio, ElectricRes
9092
return PowerRatio.FromDecibelWatts(amplitudeRatio.DecibelVolts - 10 * Math.Log10(impedance.Ohms / 1));
9193
}
9294
}
93-
}
95+
}

UnitsNet/CustomCode/Quantities/Level.extra.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
// THE SOFTWARE.
2121

2222
using System;
23+
using UnitsNet.Units;
2324

2425
namespace UnitsNet
2526
{
2627
// Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
2728
// Public structures can't have any members other than public fields, and those fields must be value types or strings.
2829
// Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
29-
#if WINDOWS_UWP
30-
public sealed partial class Level
31-
#else
30+
// Cannot have methods with same name and same number of parameters.
31+
#if !WINDOWS_UWP
3232
public partial struct Level
33-
#endif
3433
{
3534
/// <summary>
3635
/// Initializes a new instance of the logarithmic <see cref="Level" /> struct which is the ratio of a quantity Q to a
@@ -49,7 +48,9 @@ public Level(double quantity, double reference)
4948
if ((reference == 0) || ((quantity > 0) && (reference < 0)))
5049
throw new ArgumentOutOfRangeException(nameof(reference), errorMessage);
5150

52-
_decibels = 10*Math.Log10(quantity/reference);
51+
_value = 10*Math.Log10(quantity/reference);
52+
_unit = LevelUnit.Decibel;
5353
}
5454
}
55-
}
55+
#endif
56+
}

UnitsNet/CustomCode/Quantities/Molarity.extra.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using UnitsNet.Units;
23

34
namespace UnitsNet
45
{
@@ -20,7 +21,8 @@ public partial struct Molarity
2021
Molarity(Density density, Mass molecularWeight)
2122
: this()
2223
{
23-
_molesPerCubicMeter = density.KilogramsPerCubicMeter / molecularWeight.Kilograms;
24+
_value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms;
25+
_unit = MolarityUnit.MolesPerCubicMeter;
2426
}
2527

2628
/// <summary>

UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// THE SOFTWARE.
2121

2222
using System;
23+
using UnitsNet.Units;
2324

2425
namespace UnitsNet
2526
{
@@ -51,7 +52,8 @@ public partial struct PowerRatio
5152
nameof(power), "The base-10 logarithm of a number ≤ 0 is undefined. Power must be greater than 0 W.");
5253

5354
// P(dBW) = 10*log10(value(W)/reference(W))
54-
_decibelWatts = 10 * Math.Log10(power.Watts / 1);
55+
_value = 10 * Math.Log10(power.Watts / 1);
56+
_unit = PowerRatioUnit.DecibelWatt;
5557
}
5658

5759
/// <summary>
@@ -70,7 +72,7 @@ public static PowerRatio FromPower(Power power)
7072
public static Power ToPower(PowerRatio powerRatio)
7173
{
7274
// P(W) = 1W * 10^(P(dBW)/10)
73-
return Power.FromWatts(Math.Pow(10, powerRatio._decibelWatts / 10));
75+
return Power.FromWatts(Math.Pow(10, powerRatio.DecibelWatts / 10));
7476
}
7577

7678
/// <summary>
@@ -85,4 +87,4 @@ public static AmplitudeRatio ToAmplitudeRatio(PowerRatio powerRatio, ElectricRes
8587
return AmplitudeRatio.FromDecibelVolts(10 * Math.Log10(impedance.Ohms / 1) + powerRatio.DecibelWatts);
8688
}
8789
}
88-
}
90+
}

0 commit comments

Comments
 (0)