c# - How to deserialize different xml-tags into a single list -
i have xml looks this
<root> <bosses> <boss>..some elements..</boss> <boss>..some elements..</boss> </bosses> <workers> <worker>..some elements..not same bosses</worker> <worker>..some elements..</worker> </workers> </root>
and few classes this
public class person { //properties common both bosses , workers } public class boss : person { //some properties unique bosses } public class worker : person { //some properties unique workers }
now, deserialize xml single list<person>
, quite frankly stumped on how that.
i can separate lists bosses , workers doing
[xmlelement("bosses")] public list<boss> bosses { get; set; } [xmlelement("workers")] public list<worker> workers { get; set; }
i've tried combining them naively doing this
[xmlelement("bosses")] [xmlelement("workers")] public list<person> people { get; set; }
but fails. if had take guess have tell dezerializer subclass of person
use bosses , use workers, if case, cant seem find how done.
so, please enlighten me!
edit (solution): know, asking question triggered new thoughts , able figure out solution. i'll post here in case else comes looking similar issues:
[xmlelement(elementname = "bosses", type = typeof(boss))] [xmlelement(elementname = "workers", type = typeof(worker))] public list<person> people { get; set; }
solution:
[xmlelement(elementname = "bosses", type = typeof(boss))] [xmlelement(elementname = "workers", type = typeof(worker))] public list<person> people { get; set; }
Comments
Post a Comment