Skip to content

Commit

Permalink
Rename constructor argument 'numericalValue' to 'value' (#705)
Browse files Browse the repository at this point in the history
* Rename constructor argument 'numericalValue' to 'value'

Aligning the name of the constructor argument with the property 'Value' allows MessagePack deserialization of types generated by QuantityGenerator. MessagePack can deserialize immutable types by passing the deserialized values of properties without a setter to an appropriate constructor.

* Update generated code
  • Loading branch information
rohahn authored and angularsen committed Sep 20, 2019
1 parent db95ddf commit 5179332
Show file tree
Hide file tree
Showing 201 changed files with 1,317 additions and 1,295 deletions.
16 changes: 8 additions & 8 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ private void GenerateInstanceConstructors()
/// <summary>
/// Creates the quantity with the given numeric value and unit.
/// </summary>
/// <param name=""numericValue"">The numeric value to construct this quantity with.</param>
/// <param name=""value"">The numeric value to construct this quantity with.</param>
/// <param name=""unit"">The unit representation to construct this quantity with.</param>
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
public {_quantity.Name}({_quantity.BaseType} numericValue, {_unitEnumName} unit)
public {_quantity.Name}({_quantity.BaseType} value, {_unitEnumName} unit)
{{
if(unit == {_unitEnumName}.Undefined)
throw new ArgumentException(""The quantity can not be created with an undefined unit."", nameof(unit));
");

Writer.WL(_quantity.BaseType == "double"
? @"
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));"
_value = Guard.EnsureValidNumber(value, nameof(value));"
: @"
_value = numericValue;");
_value = value;");
Writer.WL($@"
_unit = unit;
}}
Expand All @@ -180,11 +180,11 @@ private void GenerateInstanceConstructors()
/// Creates an instance of the quantity with the given numeric value in units compatible with the given <see cref=""UnitSystem""/>.
/// If multiple compatible units were found, the first match is used.
/// </summary>
/// <param name=""numericValue"">The numeric value to construct this quantity with.</param>
/// <param name=""value"">The numeric value to construct this quantity with.</param>
/// <param name=""unitSystem"">The unit system to create the quantity with.</param>
/// <exception cref=""ArgumentNullException"">The given <see cref=""UnitSystem""/> is null.</exception>
/// <exception cref=""ArgumentException"">No unit was found for the given <see cref=""UnitSystem""/>.</exception>
public {_quantity.Name}({_valueType} numericValue, UnitSystem unitSystem)
public {_quantity.Name}({_valueType} value, UnitSystem unitSystem)
{{
if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem));
Expand All @@ -194,9 +194,9 @@ private void GenerateInstanceConstructors()

Writer.WL(_quantity.BaseType == "double"
? @"
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));"
_value = Guard.EnsureValidNumber(value, nameof(value));"
: @"
_value = numericValue;");
_value = value;");
Writer.WL(@"
_unit = firstUnitInfo?.Value ?? throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
}
Expand Down
8 changes: 4 additions & 4 deletions CodeGen/Generators/UnitsNetWrcGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ private void GenerateInstanceConstructors()
/// <summary>
/// Creates the quantity with the given numeric value and unit.
/// </summary>
/// <param name=""numericValue"">The numeric value to construct this quantity with.</param>
/// <param name=""value"">The numeric value to construct this quantity with.</param>
/// <param name=""unit"">The unit representation to construct this quantity with.</param>
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
private {_quantity.Name}({_quantity.BaseType} numericValue, {_unitEnumName} unit)
private {_quantity.Name}({_quantity.BaseType} value, {_unitEnumName} unit)
{{
if(unit == {_unitEnumName}.Undefined)
throw new ArgumentException(""The quantity can not be created with an undefined unit."", nameof(unit));
");

Writer.WL(_quantity.BaseType == "double"
? @"
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));"
_value = Guard.EnsureValidNumber(value, nameof(value));"
: @"
_value = numericValue;");
_value = value;");
Writer.WL($@"
_unit = unit;
}}
Expand Down
4 changes: 4 additions & 0 deletions UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5179332

Please sign in to comment.