PowerApps-Tooling icon indicating copy to clipboard operation
PowerApps-Tooling copied to clipboard

Proof of Concept - YamlDotNet serialization and deserializaiton

Open tehcrashxor opened this issue 1 year ago • 0 comments

Proof of concept for using YamlDotNet for our serialization & deserialization needs.

  • Handles writing multiline strings in our preffered | style instead of YamlDotNet's default > via MultilineStyleEmitter.cs
  • Serialized YAML writes properties in the order defined by [YamlMember(Order = N)]
  • Allows overriding default proper names via [YamlMember(Alias = "example")]
  • Prevent serialization and deserialization of specific properties with [YamlIgnore]
  • Serialization includes quotes on values when those values could be mistaken for another type
    • strings containing numbers like 1 serialize to "1"
    • strings with bools or special values like true/false/no/null serialize to "true"/"false"/"no"/"null"
  • Deserialization uses provided type information, so typically resolves ambiguous types by using the provided type.
    • .Deserialize<string>(...) or deserializing an object with string or string collection properties will correctly handle reading 1, true, false, no without quotes as strings
    • Note: .Deserialize<string>(...) will however read null without quotes as null, as that is a valid value for the destination string type
  • Deserialization a polymorphic collection is doable, but requires more work. It is not currently included in the YamlPocoConverter.cs, but examples are provided with tests in ControlInfoPoC.cs
    • E.g., deserializing a List<Control> containing objects of inheriting types like Button or TextInput need to contain a mapping type line (ControlType in the included PoC), and the deserializer needs to be provided with that key-to-type mapping
  • Versioning of objects can also be handled by that same mapping, also included in the ControlInfoPoC.cs example

tehcrashxor avatar Dec 19 '23 21:12 tehcrashxor