Better serialization of tuples
PathogenDavid opened this issue · comments
Right now, SharpYaml serializes tuples as plain structs:
Item1: 1
Item2: 2
Item3: 3
Item4: Hello, world!
While this is great and gets the job done, it is particularly lacking in two aspects:
- The names from named tuples are not used
- I would argue that tuples should be sequences. This would have the added benefit of making the generated YAML more similar to the C# tuple syntax, such as the YAML below:
[1, 2, 3, 'Hello, world!']
I've written a serializer to perform the latter: ValueTupleSerializer
It covers my needs, although it doesn't support the following yet:
- Nested tuples (The C# compiler generates these for tuples that are too long to fit into a single ValueTuple.)
- Old school System.Tuple
- Named tuples (I started to add them, but I am pretty sure I'd need to modify SharpYaml to support it.)
@xoofx, would you be interested in a pull request that adds support with tuples? If so, I can fix the few things above and submit a pull request.
I will note, however, that this would break backwards compatibility with previously serialized tuples. It might be possible to detect the old tuple format when deserializing and fall back to the old method, but I haven't given it much thought yet.
Not sure about this one. While looking at JSON.NET it seems that it is serialize with Item1...etc.
Why not a PR if you are really looking for this kind of serialization, but this should be optional and off by default in order to keep things compatible (you might be able to make a (de)serializer that can switch between the two implem.... but not sure it is super worth...)