yamldotnet - How to deserialise child classes? -


i have list holds items of same base class of different child classes. how can deserialize this?

for example

class base { }  class child: base {    int property { get; set; } }  class ser {    public list<base> values { get; set; } } 

thanks

the deserializer has no way infer automatically child type expecting. therefore need tell type of child using tag. e.g:

yaml

- !!child   property: 1  - !!child   property: 2 

c#

var deserializer = new deserializer(); deserializer.registertagmapping("tag:yaml.org,2002:child", typeof(child));  var items = deserializer.deserialize<ser>(...); 

i have put working fiddle here


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -