From 8d2c60a43f6a50d1d17a8fd6bff480db98b228e4 Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Fri, 23 Mar 2018 22:12:43 -0500 Subject: [PATCH 1/6] Use build configuration to switch reference For the serialization test project: If in debug configuration, use the UnitsNet.Serialization project reference. If in release configuration, use the latest version of UnitsNet.Serialization as well as UnitsNet in nuget. --- .../UnitsNet.Serialization.JsonNet.Tests.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj index 7225fad3ed..c69514cc2b 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj @@ -17,10 +17,11 @@ + - + \ No newline at end of file From 603848d43a1f9ad1593bd0da8a4bfd4fad1e9d45 Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Fri, 23 Mar 2018 22:28:52 -0500 Subject: [PATCH 2/6] Added comments --- .../UnitsNet.Serialization.JsonNet.Tests.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj index c69514cc2b..081d1ed131 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj @@ -17,10 +17,13 @@ + + + From 3bafcab4d8c4e65bb8aec234b5fd88d1932ed713 Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Sat, 24 Mar 2018 06:52:44 -0500 Subject: [PATCH 3/6] Reference UnitsNet Project in Release config --- .../UnitsNet.Serialization.JsonNet.Tests.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj index 081d1ed131..d662c7345d 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj @@ -25,6 +25,9 @@ + + + \ No newline at end of file From 5125dd8da732f6aa075df98441e7ee6b9397d07a Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Sat, 24 Mar 2018 06:56:04 -0500 Subject: [PATCH 4/6] Change UnitsNet code Change UnitsNet code (see Mass.g.cs) which will break serialization library in nuget. Update JsonConverter to support the said change. --- .../UnitsNetJsonConverter.cs | 2 +- UnitsNet/GeneratedCode/Quantities/Mass.g.cs | 52 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) 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/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); } From ac4780bbc4521d0c59bbd1dd26f9ba5d2f9ef3be Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Sat, 24 Mar 2018 07:06:17 -0500 Subject: [PATCH 5/6] Change the scripts :) --- .../Include-GenerateQuantitySourceCode.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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: From e7ce5797db755b22f64c8446e002973ba775504e Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Sat, 24 Mar 2018 07:10:40 -0500 Subject: [PATCH 6/6] Change custom codes too Manually change _value to _valueRenamed in the custom codes --- UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs | 2 +- UnitsNet/CustomCode/Quantities/Level.extra.cs | 2 +- UnitsNet/CustomCode/Quantities/Molarity.extra.cs | 2 +- UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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; }