I'm looking to find a clean method of customising the output from YamlDotNet serializer.
I have the following POCO:
public class MyClass{
public string Foo { get;set; }
public Dictionary<string, string> Bar { get;set; }
}
If I set values on it like
var class = new MyClass{ Foo = "bla" };
class.Bar["key1"] = "val1";
class.Bar["key2"] = "val2";
and serialize this then I will get the results:
Foo: bla
Bar:
key1: val1
key2: val2
However, what I need to get is
Foo: bla
key1: val1
key2: val2
I can't add key1, key2 etc as properties of MyClass as they are unknown until runtime (both the value and the number of keys). Is there a way that I can do this using YamlDotNet?
I've considered using reflection to convert everything in MyClass to a Dictionary<string, object>
but would prefer a cleaner implementation.
Is there any way that I can control serialization to this degree?