c# - Customise serialisation of Dictionary to Yaml -


i'm looking find clean method of customising output yamldotnet serializer.

i have following poco:

public class myclass{   public string foo { get;set; }   public dictionary<string, string> bar { get;set; } } 

if set values on like

var class = new myclass{ foo = "bla" }; class.bar["key1"] = "val1"; class.bar["key2"] = "val2"; 

and serialize results:

foo: bla bar:   key1: val1   key2: val2 

however, need is

foo: bla key1: val1 key2: val2 

i can't add key1, key2 etc properties of myclass unknown until runtime (both value , number of keys). there way can using yamldotnet?

i've considered using reflection convert in myclass dictionary<string, object> prefer cleaner implementation.

is there way can control serialization degree?

a simple solution implement idictionary<string, string> in myclass. members need implemented enumerator. there return content of dictionary, entry each additional property.

if prefer keep poco clean, create class implements iyamltypeconverter. don't have pc @ hand implement you, use code example:

https://dotnetfiddle.net/1plicc

(sorry, copying code here not working on smart phone. add code when when have access proper pc)


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -