Skip to content

Commit 77770e4

Browse files
objectArkatufus
andauthored
Order type fields by oridnal to keep the same order on multiple platforms. (#236)
Co-authored-by: Gregorius Soedharmo <[email protected]>
1 parent 97baf14 commit 77770e4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Hyperion.Tests/Bugs.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,5 +489,23 @@ public void WritesManifestEvenIfKnown()
489489
Assert.DoesNotContain("System.Collections.Generic.Dictionary", text);
490490
Assert.Equal(msg, res);
491491
}
492+
493+
#region Issue 348
494+
495+
class FieldsToOrder
496+
{
497+
public string A2;
498+
public string a1;
499+
}
500+
501+
[Fact]
502+
public void ShouldOrderFieldsByOrdinal()
503+
{
504+
string[] expected = { "A2", "a1" };
505+
var actual = typeof(FieldsToOrder).GetFieldInfosForType().Select(x => x.Name).ToArray();
506+
Assert.Equal(expected, actual);
507+
}
508+
509+
#endregion
492510
}
493511
}

src/Hyperion/Extensions/ReflectionEx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static FieldInfo[] GetFieldInfosForType(this Type type)
4848
fieldInfos.AddRange(tfields);
4949
current = current.GetTypeInfo().BaseType;
5050
}
51-
var fields = fieldInfos.OrderBy(f => f.Name).ToArray();
51+
var fields = fieldInfos.OrderBy(f => f.Name, StringComparer.Ordinal).ToArray();
5252
return fields;
5353
}
5454
}

0 commit comments

Comments
 (0)