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>(...);
Comments
Post a Comment