【问题标题】:How to use XmlElementAttribute in VB.Net to order the fields for XML serialization如何在 VB.Net 中使用 XmlElementAttribute 对 XML 序列化的字段进行排序
【发布时间】:2010-12-07 19:21:40
【问题描述】:

我们需要为序列化为 XML 的类的字段指定特定的排序顺序。我明白在处理 XML 元素时依赖排序顺序不一定是好的做法,但在我们的例子中,这样做是有理由的。

所以...this answer for C# 建议使用XmlElementAttribute,我已将 C# 翻译为 VB:

<System.Xml.Serialization.XmlElementAttribute(Order = 1)> _
Public Property Foo() As String
etcs

但它抱怨Name 'Order 'is not declared。我是从 C# 翻译错误还是这里有其他问题?

【问题讨论】:

    标签: vb.net attributes xmlserializer c#-to-vb.net


    【解决方案1】:

    命名属性赋值语法不正确,应该是:

    <System.Xml.Serialization.XmlElementAttribute(Order := 1)>
    

    注意= 后面的额外:。这适用于不属于构造函数的命名属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多