Skip to content

Commit

Permalink
💥🐛Change DataMember ordering to 1-indexed (#1360)
Browse files Browse the repository at this point in the history
Related #1200 
Fixes #1356

Apparently, protobuf-net does not support 0-indexed order values.

### Changes
- Change `DataMember` explicit order from 0-indexed to 1-indexed

### Background
Some investigation indicates that the actual order value is not important, only the relative ordering: 
#1356 (comment)

- WCF should tolerate this, according to its docs. #1356 (comment)
- Binary formatters hopefully only care about relative ordering and thus still compatible?
	- Protobuf-net, it never worked and should be OK
	- [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter?view=net-8.0) is obsolete and generally not recommended for years, so hopefully no users are affected
	- A bunch of others exist too, haven't looked into how they handle this
- XML/JSON serializers should tolerate any order, can't imagine it breaking these?
  • Loading branch information
angularsen authored Feb 14, 2024
1 parent 2424307 commit 1c5a0f3
Show file tree
Hide file tree
Showing 124 changed files with 258 additions and 258 deletions.
24 changes: 12 additions & 12 deletions CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace UnitsNet
Writer.WL(@$"
#endif");
}

if (_quantity.ValueType == "decimal") Writer.WL(@$"
IDecimalQuantity,");

Expand All @@ -115,13 +115,13 @@ namespace UnitsNet
/// <summary>
/// The numeric value this quantity was constructed with.
/// </summary>
[DataMember(Name = ""Value"", Order = 0)]
[DataMember(Name = ""Value"", Order = 1)]
private readonly {_quantity.ValueType} _value;
/// <summary>
/// The unit this quantity was constructed with.
/// </summary>
[DataMember(Name = ""Unit"", Order = 1)]
[DataMember(Name = ""Unit"", Order = 2)]
private readonly {_unitEnumName}? _unit;
");
GenerateStaticConstructor();
Expand Down Expand Up @@ -759,41 +759,41 @@ private void GenerateRelationalOperators()
{
leftConversionProperty = "Total" + leftConversionProperty;
}

if (relation.RightQuantity.Name is nameof(TimeSpan))
{
rightConversionProperty = "Total" + rightConversionProperty;
}

if (leftParameter == rightParameter)
{
leftParameter = "left";
rightParameter = "right";
}

var leftPart = $"{leftParameter}.{leftConversionProperty}";
var rightPart = $"{rightParameter}.{rightConversionProperty}";

if (leftParameter is "double")
{
leftParameter = leftPart = "value";
}
}

if (rightParameter is "double")
{
rightParameter = rightPart = "value";
}

var leftCast = relation.LeftQuantity.ValueType is "decimal" ? "(double)" : string.Empty;
var rightCast = relation.RightQuantity.ValueType is "decimal" ? "(double)" : string.Empty;

var expression = $"{leftCast}{leftPart} {relation.Operator} {rightCast}{rightPart}";

if (relation.ResultQuantity.Name is not ("double" or "decimal"))
{
expression = $"{relation.ResultQuantity.Name}.From{relation.ResultUnit.PluralName}({expression})";
}

Writer.WL($@"
/// <summary>Get <see cref=""{relation.ResultQuantity.Name}""/> from <see cref=""{relation.LeftQuantity.Name}""/> {relation.Operator} <see cref=""{relation.RightQuantity.Name}""/>.</summary>
public static {relation.ResultQuantity.Name} operator {relation.Operator}({relation.LeftQuantity.Name} {leftParameter}, {relation.RightQuantity.Name} {rightParameter})
Expand Down

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Angle.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Area.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/BitRate.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.

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Capacitance.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.

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Density.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/Duration.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs

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

4 changes: 2 additions & 2 deletions UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs

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

Loading

0 comments on commit 1c5a0f3

Please sign in to comment.