Skip to content

Commit 687c714

Browse files
committed
Fix compile errors for Windows Runtime Component
1 parent 7dc80c9 commit 687c714

Some content is hidden

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

74 files changed

+914
-219
lines changed

UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public partial struct AmplitudeRatio
5656
"The base-10 logarithm of a number ≤ 0 is undefined. Voltage must be greater than 0 V.");
5757

5858
// E(dBV) = 20*log10(value(V)/reference(V))
59-
Value = 20 * Math.Log10(voltage.Volts / 1);
59+
_value = 20 * Math.Log10(voltage.Volts / 1);
6060
Unit = AmplitudeRatioUnit.DecibelVolt;
6161
}
6262

@@ -92,4 +92,4 @@ public static PowerRatio ToPowerRatio(AmplitudeRatio amplitudeRatio, ElectricRes
9292
return PowerRatio.FromDecibelWatts(amplitudeRatio.DecibelVolts - 10 * Math.Log10(impedance.Ohms / 1));
9393
}
9494
}
95-
}
95+
}

UnitsNet/CustomCode/Quantities/Level.extra.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ namespace UnitsNet
2727
// Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
2828
// Public structures can't have any members other than public fields, and those fields must be value types or strings.
2929
// 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.
30-
#if WINDOWS_UWP
31-
public sealed partial class Level
32-
#else
30+
// Cannot have methods with same name and same number of parameters.
31+
#if !WINDOWS_UWP
3332
public partial struct Level
34-
#endif
3533
{
3634
/// <summary>
3735
/// Initializes a new instance of the logarithmic <see cref="Level" /> struct which is the ratio of a quantity Q to a
@@ -50,8 +48,9 @@ public Level(double quantity, double reference)
5048
if ((reference == 0) || ((quantity > 0) && (reference < 0)))
5149
throw new ArgumentOutOfRangeException(nameof(reference), errorMessage);
5250

53-
Value = 10*Math.Log10(quantity/reference);
51+
_value = 10*Math.Log10(quantity/reference);
5452
Unit = LevelUnit.Decibel;
5553
}
5654
}
57-
}
55+
#endif
56+
}

UnitsNet/CustomCode/Quantities/Molarity.extra.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial struct Molarity
2121
Molarity(Density density, Mass molecularWeight)
2222
: this()
2323
{
24-
Value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms;
24+
_value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms;
2525
Unit = MolarityUnit.MolesPerCubicMeter;
2626
}
2727

UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public partial struct PowerRatio
5252
nameof(power), "The base-10 logarithm of a number ≤ 0 is undefined. Power must be greater than 0 W.");
5353

5454
// P(dBW) = 10*log10(value(W)/reference(W))
55-
Value = 10 * Math.Log10(power.Watts / 1);
55+
_value = 10 * Math.Log10(power.Watts / 1);
5656
Unit = PowerRatioUnit.DecibelWatt;
5757
}
5858

@@ -87,4 +87,4 @@ public static AmplitudeRatio ToAmplitudeRatio(PowerRatio powerRatio, ElectricRes
8787
return AmplitudeRatio.FromDecibelVolts(10 * Math.Log10(impedance.Ohms / 1) + powerRatio.DecibelWatts);
8888
}
8989
}
90-
}
90+
}

UnitsNet/CustomCode/UnitSystem.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ public UnitSystem() : this(DefaultCulture)
139139
/// Defaults to <see cref="CultureInfo.CurrentUICulture" /> when creating an instance with no culture provided.
140140
/// Can be overridden, but note that this is static and will affect all subsequent usages.
141141
/// </summary>
142-
public static IFormatProvider DefaultCulture { get; set; } = CultureInfo.CurrentUICulture;
142+
#if WINDOWS_UWP
143+
// Windows Runtime Component does not support exposing the IFormatProvider type in public API
144+
private
145+
#else
146+
public
147+
#endif
148+
static IFormatProvider DefaultCulture { get; set; } = CultureInfo.CurrentUICulture;
143149

144150
public bool IsFallbackCulture => Culture.Equals(FallbackCulture);
145151

UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class Acceleration
6969
public partial struct Acceleration : IComparable, IComparable<Acceleration>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public Acceleration() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public Acceleration(double meterpersecondsquared)
9197
{
92-
Value = Convert.ToDouble(meterpersecondsquared);
98+
_value = Convert.ToDouble(meterpersecondsquared);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public Acceleration(double meterpersecondsquared)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public Acceleration(double numericValue, AccelerationUnit unit)
110+
#else
102111
public Acceleration(double numericValue, AccelerationUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class AmountOfSubstance
6969
public partial struct AmountOfSubstance : IComparable, IComparable<AmountOfSubstance>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public AmountOfSubstance() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public AmountOfSubstance(double moles)
9197
{
92-
Value = Convert.ToDouble(moles);
98+
_value = Convert.ToDouble(moles);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public AmountOfSubstance(double moles)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public AmountOfSubstance(double numericValue, AmountOfSubstanceUnit unit)
110+
#else
102111
public AmountOfSubstance(double numericValue, AmountOfSubstanceUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class AmplitudeRatio
6969
public partial struct AmplitudeRatio : IComparable, IComparable<AmplitudeRatio>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public AmplitudeRatio() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public AmplitudeRatio(double decibelvolts)
9197
{
92-
Value = Convert.ToDouble(decibelvolts);
98+
_value = Convert.ToDouble(decibelvolts);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public AmplitudeRatio(double decibelvolts)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public AmplitudeRatio(double numericValue, AmplitudeRatioUnit unit)
110+
#else
102111
public AmplitudeRatio(double numericValue, AmplitudeRatioUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

UnitsNet/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class Angle
6969
public partial struct Angle : IComparable, IComparable<Angle>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public Angle() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public Angle(double degrees)
9197
{
92-
Value = Convert.ToDouble(degrees);
98+
_value = Convert.ToDouble(degrees);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public Angle(double degrees)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public Angle(double numericValue, AngleUnit unit)
110+
#else
102111
public Angle(double numericValue, AngleUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class ApparentEnergy
6969
public partial struct ApparentEnergy : IComparable, IComparable<ApparentEnergy>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public ApparentEnergy() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public ApparentEnergy(double voltamperehours)
9197
{
92-
Value = Convert.ToDouble(voltamperehours);
98+
_value = Convert.ToDouble(voltamperehours);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public ApparentEnergy(double voltamperehours)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public ApparentEnergy(double numericValue, ApparentEnergyUnit unit)
110+
#else
102111
public ApparentEnergy(double numericValue, ApparentEnergyUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class ApparentPower
6969
public partial struct ApparentPower : IComparable, IComparable<ApparentPower>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public ApparentPower() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public ApparentPower(double voltamperes)
9197
{
92-
Value = Convert.ToDouble(voltamperes);
98+
_value = Convert.ToDouble(voltamperes);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public ApparentPower(double voltamperes)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public ApparentPower(double numericValue, ApparentPowerUnit unit)
110+
#else
102111
public ApparentPower(double numericValue, ApparentPowerUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

UnitsNet/GeneratedCode/Quantities/Area.g.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public sealed partial class Area
6969
public partial struct Area : IComparable, IComparable<Area>
7070
#endif
7171
{
72+
private readonly double _value;
73+
7274
/// <summary>
7375
/// The numeric value this quantity was constructed with.
7476
/// </summary>
75-
public double Value { get; }
77+
#if WINDOWS_UWP
78+
public double Value => Convert.ToDouble(_value);
79+
#else
80+
public double Value => _value;
81+
#endif
7682

7783
/// <summary>
7884
/// The unit this quantity was constructed with.
@@ -89,7 +95,7 @@ public Area() : this(0, BaseUnit)
8995
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
9096
public Area(double squaremeters)
9197
{
92-
Value = Convert.ToDouble(squaremeters);
98+
_value = Convert.ToDouble(squaremeters);
9399
Unit = BaseUnit;
94100
}
95101

@@ -99,9 +105,13 @@ public Area(double squaremeters)
99105
/// <param name="numericValue">Numeric value.</param>
100106
/// <param name="unit">Unit representation.</param>
101107
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
108+
#if WINDOWS_UWP
109+
public Area(double numericValue, AreaUnit unit)
110+
#else
102111
public Area(double numericValue, AreaUnit unit)
112+
#endif
103113
{
104-
Value = numericValue;
114+
_value = numericValue;
105115
Unit = unit;
106116
}
107117

0 commit comments

Comments
 (0)