customize the order of displaying elements while serialization using C# -
i have class defines elements below in c# item class
public class item { public string shortdesc {get;set;} [xmlarrayitem(elementname="category")] public list<string> categories = new list<string>(); public string subtype{get;set;} }
in code behind have code
item() itm = new item(); itm.subtype = "applications"; itm.categories.add("category1"); itm.categories.add("category2"); itm.categories.add("category3"); itm.shortdesc="short description";
i getting xml output when serialize object
xml:
<subtype>applications</subtype> <shortdesc>short description</shortdesc> <categories> <category>category1</category> <category>category2</category> <category>category3</category> </categories>
but want output in order
<subtype>applications</subtype> <categories> <category>category1</category> <category>category2</category> <category>category3</category> </categories> <shortdesc>short description</shortdesc>
how possible display way tried order=
takes xmlelement
public class item { [xmlelement("shortdesc", order=2)] public string shortdesc { get; set; } private readonly list<string> categories = new list<string>(); [xmlarray("categories", order = 3), xmlarrayitem("category")] public list<string> categories { { return categories; } } [xmlelement("sub-type", order = 1)] public string subtype { get; set; } }
note explicit [xmlarray]
, allows specify order=
. moved list property (which norm).
Comments
Post a Comment