I wrote the following code in my class and expected that the order will remain. but in the dll the order is not saved, is there any way to save the order?
my code:
[XmlElement(Type = typeof(ConfigItem))]
[XmlElement(ElementName = "Item")]
public List<ConfigItem> Items
{
开发者_如何转开发 get { return subItems_; }
set { subItems_ = value; }
}
Dll property header from ILSpy:
[XmlElement(ElementName = "Item"), XmlElement(Type = typeof(ConfigItem))]
public List<ConfigItem> Items
{
get
{
return this.subItems_;
}
set
{
this.subItems_ = value;
}
}
the order is important because the output xml is different, in case of
[XmlElement(ElementName = "Item"), XmlElement(Type = typeof(ConfigItem))]
the xml looks like that:
<ConfigItem Id="2" Value="">
and in the opposite order of attributes, meaning like that:
[XmlElement(Type = typeof(ConfigItem)), XmlElement(ElementName = "Item")]
the xml looks like that:
<Item Id="2">
Any one can help me?
精彩评论