序列化时的顺序字段

问题描述:

我是xml序列化对象,我似乎无法改变字段序列化的顺序。序列化时的顺序字段

I.e.

public class foo{ 
string a {get;set;} 
string b {get;set;} 
} 

出来的(伪)

<foo b="world" a="hello" /> 

当我需要

<foo a="hello" b="world" /> 

谁能帮助?

+1

,两个输出是等价的。你的消费程序不符合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

如果您无法通过decorating the class with XML attributes做到这一点(你不能这样做,如果你需要 XML,而不是属性的XML元素作为输出),您可能需要实现IXmlSerializable自己,这里简要地提到:

custom xml serialization

在这里:

Proper way to implement IXmlSerializable?

在XML