gpt4 book ai didi

c# - 序列化时的订单字段

转载 作者:行者123 更新时间:2023-11-30 15:05:56 25 4
gpt4 key购买 nike

我正在用 xml 序列化一个对象,但我似乎无法更改字段序列化的顺序。

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,此处简要提及:

custom xml serialization

在这里:

Proper way to implement IXmlSerializable?

关于c# - 序列化时的订单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8518022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com