@@ -100,10 +100,16 @@ namespace UnitsNet
100
100
public partial struct $quantityName : IComparable, IComparable<$quantityName >
101
101
#endif
102
102
{
103
+ private readonly $baseType _value;
104
+
103
105
/// <summary>
104
106
/// The numeric value this quantity was constructed with.
105
107
/// </summary>
106
- public $baseType Value { get; }
108
+ #if WINDOWS_UWP
109
+ public double Value => Convert.ToDouble(_value);
110
+ #else
111
+ public $baseType Value => _value;
112
+ #endif
107
113
108
114
/// <summary>
109
115
/// The unit this quantity was constructed with.
@@ -120,7 +126,7 @@ namespace UnitsNet
120
126
[Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")]
121
127
public $quantityName (double $baseUnitPluralNameLower )
122
128
{
123
- Value = $convertToBaseType ($baseUnitPluralNameLower );
129
+ _value = $convertToBaseType ($baseUnitPluralNameLower );
124
130
Unit = BaseUnit;
125
131
}
126
132
@@ -130,9 +136,14 @@ namespace UnitsNet
130
136
/// <param name="numericValue">Numeric value.</param>
131
137
/// <param name="unit">Unit representation.</param>
132
138
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
133
- public $quantityName ($baseType numericValue, $unitEnumName unit)
139
+ #if WINDOWS_UWP
140
+ private
141
+ #else
142
+ public
143
+ #endif
144
+ $quantityName ($baseType numericValue, $unitEnumName unit)
134
145
{
135
- Value = numericValue;
146
+ _value = numericValue;
136
147
Unit = unit;
137
148
}
138
149
@@ -357,7 +368,7 @@ namespace UnitsNet
357
368
#endif
358
369
int CompareTo($quantityName other)
359
370
{
360
- return Value .CompareTo(other.AsBaseNumericType(Unit ));
371
+ return AsBaseUnit $baseUnitPluralName () .CompareTo(other.AsBaseUnit $baseUnitPluralName ( ));
361
372
}
362
373
363
374
// Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx
@@ -402,7 +413,7 @@ namespace UnitsNet
402
413
return false;
403
414
}
404
415
405
- return Value .Equals((($quantityName ) obj).AsBaseNumericType(Unit ));
416
+ return AsBaseUnit $baseUnitPluralName () .Equals((($quantityName ) obj).AsBaseUnit $baseUnitPluralName ( ));
406
417
}
407
418
408
419
/// <summary>
@@ -415,7 +426,7 @@ namespace UnitsNet
415
426
/// <returns>True if the difference between the two values is not greater than the specified max.</returns>
416
427
public bool Equals($quantityName other, $quantityName maxError)
417
428
{
418
- return Math.Abs(Value - other.AsBaseNumericType(Unit )) <= maxError.AsBaseNumericType(Unit );
429
+ return Math.Abs(AsBaseUnit $baseUnitPluralName () - other.AsBaseUnit $baseUnitPluralName ( )) <= maxError.AsBaseUnit $baseUnitPluralName ( );
419
430
}
420
431
421
432
public override int GetHashCode()
@@ -715,12 +726,12 @@ namespace UnitsNet
715
726
/// <returns>The value in the base unit representation.</returns>
716
727
private $baseType AsBaseUnit$baseUnitPluralName ()
717
728
{
718
- if (Unit == $unitEnumName .$baseUnitSingularName ) { return Value ; }
729
+ if (Unit == $unitEnumName .$baseUnitSingularName ) { return _value ; }
719
730
720
731
switch (Unit)
721
732
{
722
733
"@ ; foreach ($unit in $units ) {
723
- $func = $unit.FromUnitToBaseFunc.Replace (" x" , " Value " );@"
734
+ $func = $unit.FromUnitToBaseFunc.Replace (" x" , " _value " );@"
724
735
case $unitEnumName .$ ( $unit.SingularName ) : return $func ;
725
736
"@ ; }@"
726
737
default:
0 commit comments