claunia / plist-cil

C#/.NET parser for Apple and GnuStep Property List (aka plist), based on Java's dd-plist
Other
56 stars 17 forks source link

Sort key-value pairs alphabetically by key name when serializing dictionaries to XML #74

Open relgit opened 2 years ago

relgit commented 2 years ago

I'd like to suggest that plist-cil will sort key-value pairs alphabetically when it serializes a dictionary to XML, in the same way that plutil writes processed plists on the Mac.

While this will have no effect whatsoever on the data when deserialized, it will help greatly in cases where files are compared or diffed with previous versions to detect changes.

Right now the package serializes the pairs in the order that the Dictionary class provides, which is undefined. This means that a file loaded and written-back right away multiple times can potentially be different from one write to the other.

I'm considering plist-cil for a project which will process the about 200 plist files on the ProfileManifests project on an ongoing basis, and it is crucial to me that file output will be consistent and reproducible.

I can make the changes myself, but I'd like to see if there is openness to the idea around here 🙂

qmfrederik commented 2 years ago

I'm not really convinced this should be a feature of plist-cil. If it is, at the very least, it should be opt-in.

claunia commented 2 years ago

I see the usefulness of what @relgit is asking, but @qmfrederik why exactly you think it shall be opt-in?

We can have it as an option in the serializer so we use a SortedDictionary