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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -