序列化时的顺序字段
问题描述:
我是xml序列化对象,我似乎无法改变字段序列化的顺序。序列化时的顺序字段
I.e.
public class foo{
string a {get;set;}
string b {get;set;}
}
出来的(伪)
<foo b="world" a="hello" />
当我需要
<foo a="hello" b="world" />
谁能帮助?
答
如果您无法通过decorating the class with XML attributes做到这一点(你不能这样做,如果你需要 XML,而不是属性的XML元素作为输出),您可能需要实现IXmlSerializable
自己,这里简要地提到:
在这里:
在XML
,两个输出是等价的。你的消费程序不符合XML标准吗?无论如何,我不认为没有自定义序列化过程是可能的。它适用于具有[Order property of XmlElementAttribute class](http://msdn.microsoft.com/zh-cn/library/system.xml.serialization.xmlelementattribute.order.aspx)的元素,并且没有属性 – 2011-12-15 09:49:40