c# - XML Deserialization - Parent element getting attribute value of child -
when deserializing xml using restsharp library, if have element contains nested element attribute same name, parent element takes on attribute value of nested element - how can prevent happening?
i have several classes (larger reduced form demonstrate) set deserialize xml.
[xmltype(anonymoustype = true)] [xmlroot(isnullable = false)] public class base { [xmlattribute("title")] public string title { get; set; } [xmlarray("base")] [xmlarrayitem("foo")] public list<foo> foos{ get; set; } public base() { foos = new list<foo>(); } } [xmltype(anonymoustype = true)] public class foo { [xmlattribute("style")] public string style { get; set; } [xmlelement("bar")] public list<bar> bars { get; set; } public foo() { bars = new list<bar>(); } } [xmltype(anonymoustype = true)] public class bar { [xmlattribute("style")] public string style { get; set; } [xmlelement("foo")] public list<foo> foos{ get; set; } public bar() { foos = new list<foo>(); } }
with xml like:
<base> <foo> <bar style="bold" /> <bar /> </foo> <foo> <bar style="bold" /> <bar /> </foo> </base>
when deserialized, have instance of foo foo.style = "bold"
expect foo.style = null
. how can prevent parent element taking child elements attribute value?
this appears issue restsharp library.
https://github.com/restsharp/restsharp/issues/752
i have yet find solution.
Comments
Post a Comment