Skip to content

Commit 5179332

Browse files
rohahnangularsen
authored andcommitted
Rename constructor argument 'numericalValue' to 'value' (#705)
* 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
1 parent db95ddf commit 5179332

File tree

201 files changed

+1317
-1295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+1317
-1295
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,20 @@ private void GenerateInstanceConstructors()
158158
/// <summary>
159159
/// Creates the quantity with the given numeric value and unit.
160160
/// </summary>
161-
/// <param name=""numericValue"">The numeric value to construct this quantity with.</param>
161+
/// <param name=""value"">The numeric value to construct this quantity with.</param>
162162
/// <param name=""unit"">The unit representation to construct this quantity with.</param>
163163
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
164-
public {_quantity.Name}({_quantity.BaseType} numericValue, {_unitEnumName} unit)
164+
public {_quantity.Name}({_quantity.BaseType} value, {_unitEnumName} unit)
165165
{{
166166
if(unit == {_unitEnumName}.Undefined)
167167
throw new ArgumentException(""The quantity can not be created with an undefined unit."", nameof(unit));
168168
");
169169

170170
Writer.WL(_quantity.BaseType == "double"
171171
? @"
172-
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));"
172+
_value = Guard.EnsureValidNumber(value, nameof(value));"
173173
: @"
174-
_value = numericValue;");
174+
_value = value;");
175175
Writer.WL($@"
176176
_unit = unit;
177177
}}
@@ -180,11 +180,11 @@ private void GenerateInstanceConstructors()
180180
/// Creates an instance of the quantity with the given numeric value in units compatible with the given <see cref=""UnitSystem""/>.
181181
/// If multiple compatible units were found, the first match is used.
182182
/// </summary>
183-
/// <param name=""numericValue"">The numeric value to construct this quantity with.</param>
183+
/// <param name=""value"">The numeric value to construct this quantity with.</param>
184184
/// <param name=""unitSystem"">The unit system to create the quantity with.</param>
185185
/// <exception cref=""ArgumentNullException"">The given <see cref=""UnitSystem""/> is null.</exception>
186186
/// <exception cref=""ArgumentException"">No unit was found for the given <see cref=""UnitSystem""/>.</exception>
187-
public {_quantity.Name}({_valueType} numericValue, UnitSystem unitSystem)
187+
public {_quantity.Name}({_valueType} value, UnitSystem unitSystem)
188188
{{
189189
if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem));
190190
@@ -194,9 +194,9 @@ private void GenerateInstanceConstructors()
194194

195195
Writer.WL(_quantity.BaseType == "double"
196196
? @"
197-
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));"
197+
_value = Guard.EnsureValidNumber(value, nameof(value));"
198198
: @"
199-
_value = numericValue;");
199+
_value = value;");
200200
Writer.WL(@"
201201
_unit = firstUnitInfo?.Value ?? throw new ArgumentException(""No units were found for the given UnitSystem."", nameof(unitSystem));
202202
}

CodeGen/Generators/UnitsNetWrcGen/QuantityGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,21 @@ private void GenerateInstanceConstructors()
140140
/// <summary>
141141
/// Creates the quantity with the given numeric value and unit.
142142
/// </summary>
143-
/// <param name=""numericValue"">The numeric value to construct this quantity with.</param>
143+
/// <param name=""value"">The numeric value to construct this quantity with.</param>
144144
/// <param name=""unit"">The unit representation to construct this quantity with.</param>
145145
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
146146
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>
147-
private {_quantity.Name}({_quantity.BaseType} numericValue, {_unitEnumName} unit)
147+
private {_quantity.Name}({_quantity.BaseType} value, {_unitEnumName} unit)
148148
{{
149149
if(unit == {_unitEnumName}.Undefined)
150150
throw new ArgumentException(""The quantity can not be created with an undefined unit."", nameof(unit));
151151
");
152152

153153
Writer.WL(_quantity.BaseType == "double"
154154
? @"
155-
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));"
155+
_value = Guard.EnsureValidNumber(value, nameof(value));"
156156
: @"
157-
_value = numericValue;");
157+
_value = value;");
158158
Writer.WL($@"
159159
_unit = unit;
160160
}}

UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentEnergy.g.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)