简体   繁体   English

序列化时的订单字段

[英]Order fields when serializing

I am xml serializing an object and I cannot seem to change the order in which the fields are serialized. 我是xml序列化一个对象,我似乎无法改变字段序列化的顺序。

Ie

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

Comes out as (pseudocode) 出来的(伪代码)

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

When I need 当我需要的时候

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

Can anyone help? 有人可以帮忙吗?

If you cannot achieve this via decorating the class with XML attributes (which you cannot do if you require XML attributes instead of XML elements as output), you may need to implement IXmlSerializable yourself, mentioned briefly here: 如果你不能通过使用XML属性修饰类来实现这一点(如果你需要 XML属性而不是XML元素作为输出就无法做到),你可能需要自己实现IXmlSerializable ,这里简要提到:

custom xml serialization 自定义xml序列化

And here: 和这里:

Proper way to implement IXmlSerializable? 正确的方法来实现IXmlSerializable?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM