开发者

XmlElement Attribute order is not saved

开发者 https://www.devze.com 2023-03-25 10:02 出处:网络
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?

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消