Skip to content
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

Why are object members sorted by name? #80

Open
xPaw opened this issue Jul 24, 2023 · 3 comments
Open

Why are object members sorted by name? #80

xPaw opened this issue Jul 24, 2023 · 3 comments

Comments

@xPaw
Copy link
Member

xPaw commented Jul 24, 2023

This loses developer defined order in classes when serializing.

https://github.com/SteamDatabase/ValveKeyValue/blob/ed10cc104681d33935fc2b7ea3d6701970a581f5/ValveKeyValue/ValveKeyValue/ObjectCopier.cs#L120

cc @yaakov-h

@yaakov-h
Copy link
Member

Probably for consistency/reliability, particularly for the unit tests.

In .NET 6 and earlier versions, the GetProperties method does not return properties in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which properties are returned, because that order varies. However, starting with .NET 7, the ordering is deterministic based upon the metadata ordering in the assembly.

-- https://learn.microsoft.com/en-us/dotnet/api/system.type.getproperties?view=net-7.0#system-type-getproperties

@xPaw
Copy link
Member Author

xPaw commented Jul 25, 2023

Right, that makes sense.

Perhaps we can order by MetadataToken, is that what .NET7 does?

@yaakov-h
Copy link
Member

I'm not sure what .NET 7 runtime does, its very hard to dig through this bit of the BCL/CLR codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants