Q: Customise serialisation of Dictionary to Yaml 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?

A: A simple solution is to implement IDictionary<string, string> in MyClass. The only members that actually need to be implemented are the enumerator. There you would return the content of the dictionary, as well as another entry for each additional property.
If you prefer to keep your POCO clean, you could create a class that implements IYamlTypeConverter. I don't have a PC at hand to implement it for you, but you could use the this code as an example:
https://dotnetfiddle.net/1plIcc
(Sorry, copying the code here is not working on a smart phone. I will add the code when when I have access to a proper PC)
