Skip to content

Test pr 423 #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" />

<!--When in Release configuration, use the UnitsNet.Serialization.JsonNet and UnitsNet latest released libraries in Nuget-->
<PackageReference Condition="'$(Configuration)'=='Release'" Include="UnitsNet.Serialization.JsonNet" Version="*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj" />
<!--When in Debug configuration, use the UnitsNet.Serialization.JsonNet project-->
<ProjectReference Condition="'$(Configuration)'=='Debug'" Include="..\UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj" />

<!--When in Release configuration, use the UnitsNet project-->
<ProjectReference Condition="'$(Configuration)'=='Release'" Include="..\UnitsNet\UnitsNet.NetStandard10.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/CustomCode/Quantities/AmplitudeRatio.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/CustomCode/Quantities/Level.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/CustomCode/Quantities/Molarity.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion UnitsNet/CustomCode/Quantities/PowerRatio.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
52 changes: 26 additions & 26 deletions UnitsNet/GeneratedCode/Quantities/Mass.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public partial struct Mass : IComparable, IComparable<Mass>
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
private readonly double _value;
private readonly double _valueRenamed; //Renaming this should break latest (v1.3) serialization library in nuget.

/// <summary>
/// The unit this quantity was constructed with.
Expand All @@ -78,7 +78,7 @@ public partial struct Mass : IComparable, IComparable<Mass>
#if WINDOWS_UWP
public double Value => Convert.ToDouble(_value);
#else
public double Value => _value;
public double Value => _valueRenamed;
#endif

/// <summary>
Expand All @@ -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;
}

Expand All @@ -115,7 +115,7 @@ public Mass(double kilograms)
#endif
Mass(double numericValue, MassUnit unit)
{
_value = numericValue;
_valueRenamed = numericValue;
_unit = unit;
}

Expand Down Expand Up @@ -1471,31 +1471,31 @@ public string ToString(
/// <returns>The value in the base unit representation.</returns>
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);
}
Expand Down
16 changes: 8 additions & 8 deletions UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace UnitsNet
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
private readonly $baseType _value;
private readonly $baseType _valueRenamed;

/// <summary>
/// The unit this quantity was constructed with.
Expand All @@ -107,9 +107,9 @@ namespace UnitsNet
/// The numeric value this quantity was constructed with.
/// </summary>
#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

/// <summary>
Expand All @@ -121,15 +121,15 @@ namespace UnitsNet
#if WINDOWS_UWP
public $quantityName()
{
_value = 0;
_valueRenamed = 0;
_unit = BaseUnit;
}
#endif

[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;
}

Expand All @@ -146,7 +146,7 @@ namespace UnitsNet
#endif
$quantityName($baseType numericValue, $unitEnumName unit)
{
_value = numericValue;
_valueRenamed = numericValue;
_unit = unit;
}

Expand Down Expand Up @@ -844,12 +844,12 @@ namespace UnitsNet
/// <returns>The value in the base unit representation.</returns>
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:
Expand Down