diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj index 7225fad3ed..d662c7345d 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj @@ -17,10 +17,17 @@ + + + - + + + + + \ No newline at end of file diff --git a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs index 024acf53b1..b65d804dfc 100644 --- a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs +++ b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs @@ -252,7 +252,7 @@ private static FieldInfo GetPrivateInstanceField(Type quantityType, string field #else .GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) #endif - .SingleOrDefault(f => f.Name == fieldName); + .SingleOrDefault(f => f.Name == fieldName || f.Name == "_valueRenamed"); //Added support for valueRenamed for testing purposes } catch (InvalidOperationException) { diff --git a/UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs b/UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs index 471a09498a..148e1cfea2 100644 --- a/UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs +++ b/UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs @@ -56,7 +56,7 @@ public partial struct AmplitudeRatio "The base-10 logarithm of a number ≤ 0 is undefined. Voltage must be greater than 0 V."); // E(dBV) = 20*log10(value(V)/reference(V)) - _value = 20 * Math.Log10(voltage.Volts / 1); + _valueRenamed = 20 * Math.Log10(voltage.Volts / 1); _unit = AmplitudeRatioUnit.DecibelVolt; } diff --git a/UnitsNet/CustomCode/Quantities/Level.extra.cs b/UnitsNet/CustomCode/Quantities/Level.extra.cs index 34bac448cc..3177a31002 100644 --- a/UnitsNet/CustomCode/Quantities/Level.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Level.extra.cs @@ -48,7 +48,7 @@ public Level(double quantity, double reference) if ((reference == 0) || ((quantity > 0) && (reference < 0))) throw new ArgumentOutOfRangeException(nameof(reference), errorMessage); - _value = 10*Math.Log10(quantity/reference); + _valueRenamed = 10*Math.Log10(quantity/reference); _unit = LevelUnit.Decibel; } } diff --git a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs index 62a53f86c9..1ed9887c00 100644 --- a/UnitsNet/CustomCode/Quantities/Molarity.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Molarity.extra.cs @@ -21,7 +21,7 @@ public partial struct Molarity Molarity(Density density, Mass molecularWeight) : this() { - _value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms; + _valueRenamed = density.KilogramsPerCubicMeter / molecularWeight.Kilograms; _unit = MolarityUnit.MolesPerCubicMeter; } diff --git a/UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs b/UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs index 3c4c490a2c..28ac093559 100644 --- a/UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs +++ b/UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs @@ -52,7 +52,7 @@ public partial struct PowerRatio nameof(power), "The base-10 logarithm of a number ≤ 0 is undefined. Power must be greater than 0 W."); // P(dBW) = 10*log10(value(W)/reference(W)) - _value = 10 * Math.Log10(power.Watts / 1); + _valueRenamed = 10 * Math.Log10(power.Watts / 1); _unit = PowerRatioUnit.DecibelWatt; } diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index c33dd4cd2b..e8ec2db011 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -65,7 +65,7 @@ public partial struct Mass : IComparable, IComparable /// /// The numeric value this quantity was constructed with. /// - private readonly double _value; + private readonly double _valueRenamed; //Renaming this should break latest (v1.3) serialization library in nuget. /// /// The unit this quantity was constructed with. @@ -78,7 +78,7 @@ public partial struct Mass : IComparable, IComparable #if WINDOWS_UWP public double Value => Convert.ToDouble(_value); #else - public double Value => _value; + public double Value => _valueRenamed; #endif /// @@ -98,7 +98,7 @@ public Mass() [Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")] public Mass(double kilograms) { - _value = Convert.ToDouble(kilograms); + _valueRenamed = Convert.ToDouble(kilograms); _unit = BaseUnit; } @@ -115,7 +115,7 @@ public Mass(double kilograms) #endif Mass(double numericValue, MassUnit unit) { - _value = numericValue; + _valueRenamed = numericValue; _unit = unit; } @@ -1471,31 +1471,31 @@ public string ToString( /// The value in the base unit representation. private double AsBaseUnitKilograms() { - if (Unit == MassUnit.Kilogram) { return _value; } + if (Unit == MassUnit.Kilogram) { return _valueRenamed; } switch (Unit) { - case MassUnit.Centigram: return (_value/1e3) * 1e-2d; - case MassUnit.Decagram: return (_value/1e3) * 1e1d; - case MassUnit.Decigram: return (_value/1e3) * 1e-1d; - case MassUnit.Gram: return _value/1e3; - case MassUnit.Hectogram: return (_value/1e3) * 1e2d; - case MassUnit.Kilogram: return (_value/1e3) * 1e3d; - case MassUnit.Kilopound: return (_value*0.45359237) * 1e3d; - case MassUnit.Kilotonne: return (_value*1e3) * 1e3d; - case MassUnit.LongHundredweight: return _value/0.01968413055222121; - case MassUnit.LongTon: return _value*1016.0469088; - case MassUnit.Megapound: return (_value*0.45359237) * 1e6d; - case MassUnit.Megatonne: return (_value*1e3) * 1e6d; - case MassUnit.Microgram: return (_value/1e3) * 1e-6d; - case MassUnit.Milligram: return (_value/1e3) * 1e-3d; - case MassUnit.Nanogram: return (_value/1e3) * 1e-9d; - case MassUnit.Ounce: return _value/35.2739619; - case MassUnit.Pound: return _value*0.45359237; - case MassUnit.ShortHundredweight: return _value/0.022046226218487758; - case MassUnit.ShortTon: return _value*907.18474; - case MassUnit.Stone: return _value/0.1574731728702698; - case MassUnit.Tonne: return _value*1e3; + case MassUnit.Centigram: return (_valueRenamed/1e3) * 1e-2d; + case MassUnit.Decagram: return (_valueRenamed/1e3) * 1e1d; + case MassUnit.Decigram: return (_valueRenamed/1e3) * 1e-1d; + case MassUnit.Gram: return _valueRenamed/1e3; + case MassUnit.Hectogram: return (_valueRenamed/1e3) * 1e2d; + case MassUnit.Kilogram: return (_valueRenamed/1e3) * 1e3d; + case MassUnit.Kilopound: return (_valueRenamed*0.45359237) * 1e3d; + case MassUnit.Kilotonne: return (_valueRenamed*1e3) * 1e3d; + case MassUnit.LongHundredweight: return _valueRenamed/0.01968413055222121; + case MassUnit.LongTon: return _valueRenamed*1016.0469088; + case MassUnit.Megapound: return (_valueRenamed*0.45359237) * 1e6d; + case MassUnit.Megatonne: return (_valueRenamed*1e3) * 1e6d; + case MassUnit.Microgram: return (_valueRenamed/1e3) * 1e-6d; + case MassUnit.Milligram: return (_valueRenamed/1e3) * 1e-3d; + case MassUnit.Nanogram: return (_valueRenamed/1e3) * 1e-9d; + case MassUnit.Ounce: return _valueRenamed/35.2739619; + case MassUnit.Pound: return _valueRenamed*0.45359237; + case MassUnit.ShortHundredweight: return _valueRenamed/0.022046226218487758; + case MassUnit.ShortTon: return _valueRenamed*907.18474; + case MassUnit.Stone: return _valueRenamed/0.1574731728702698; + case MassUnit.Tonne: return _valueRenamed*1e3; default: throw new NotImplementedException("Unit not implemented: " + Unit); } diff --git a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 index 91ceb71eed..c5a56fa795 100644 --- a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 +++ b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 @@ -96,7 +96,7 @@ namespace UnitsNet /// /// The numeric value this quantity was constructed with. /// - private readonly $baseType _value; + private readonly $baseType _valueRenamed; /// /// The unit this quantity was constructed with. @@ -107,9 +107,9 @@ namespace UnitsNet /// The numeric value this quantity was constructed with. /// #if WINDOWS_UWP - public double Value => Convert.ToDouble(_value); + public double Value => Convert.ToDouble(_valueRenamed); #else - public $baseType Value => _value; + public $baseType Value => _valueRenamed; #endif /// @@ -121,7 +121,7 @@ namespace UnitsNet #if WINDOWS_UWP public $quantityName() { - _value = 0; + _valueRenamed = 0; _unit = BaseUnit; } #endif @@ -129,7 +129,7 @@ namespace UnitsNet [Obsolete("Use the constructor that takes a unit parameter. This constructor will be removed in a future version.")] public $quantityName(double $baseUnitPluralNameLower) { - _value = $convertToBaseType($baseUnitPluralNameLower); + _valueRenamed = $convertToBaseType($baseUnitPluralNameLower); _unit = BaseUnit; } @@ -146,7 +146,7 @@ namespace UnitsNet #endif $quantityName($baseType numericValue, $unitEnumName unit) { - _value = numericValue; + _valueRenamed = numericValue; _unit = unit; } @@ -844,12 +844,12 @@ namespace UnitsNet /// The value in the base unit representation. private $baseType AsBaseUnit$baseUnitPluralName() { - if (Unit == $unitEnumName.$baseUnitSingularName) { return _value; } + if (Unit == $unitEnumName.$baseUnitSingularName) { return _valueRenamed; } switch (Unit) { "@; foreach ($unit in $units) { - $func = $unit.FromUnitToBaseFunc.Replace("x", "_value");@" + $func = $unit.FromUnitToBaseFunc.Replace("x", "_valueRenamed");@" case $unitEnumName.$($unit.SingularName): return $func; "@; }@" default: