c# - XSD:使用 Visual Studio xsd.exe 不生成 Array[] 而不是 List<>

标签 c# xml visual-studio-2010 xsd

我正在使用 xsd.exe 工具从 xsd 文件生成类。 xsd 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified"      attributeFormDefault="unqualified">
<xs:element name="BAXML">
<xs:annotation>
  <xs:documentation></xs:documentation>
</xs:annotation>
<xs:complexType>
  <xs:sequence>      
    <xs:element name="Limit" minOccurs="1" maxOccurs="10">    
     <xs:complexType>
        <xs:sequence>
          <xs:element name="LimitType">
            <xs:annotation>
              <xs:documentation></xs:documentation>
            </xs:annotation>
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:minLength value="3"/>
                <xs:maxLength value="10"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name="Amount">
            <xs:annotation>
              <xs:documentation></xs:documentation>
            </xs:annotation>
            <xs:simpleType>
              <xs:restriction base="xs:int">
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

输出是:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class BAXML {

private string counterpartyOrgNrField;

private BAXMLLimit[] limitField;


/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Limit")]
public BAXMLLimit[] Limit {
    get {
        return this.limitField;
    }
    set {
        this.limitField = value;
    }
}}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class BAXMLLimit {

private string limitTypeField;

private int amountField;

/// <remarks/>
public string LimitType {
    get {
        return this.limitTypeField;
    }
    set {
        this.limitTypeField = value;
    }}

/// <remarks/>
public int Amount {
    get {
        return this.amountField;
    }
    set {
        this.amountField = value;
    }
}}

代替:

private BAXMLLimit[] limitField;

我愿意这样

List<BAXMLLimit> limitField

xsd 中有办法做到这一点吗?还是别的什么方式? 谢谢!

最佳答案

尝试使用 xsd2code .这比 xsd.exe 更好用。您还可以通过设置 CollectionObjectType 属性将集合指定为一个选项.. 列表或数组。

关于c# - XSD:使用 Visual Studio xsd.exe 不生成 Array[] 而不是 List<>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7268637/

相关文章:

xml - 如何从字符串更新/替换 XElement 的元素?

java - 如何捕获 NoSuchMethodException

debugging - 如何用VS2010 CLR调试SQL Server 2k8

c# - 向接口(interface)/实现添加事件

android - 在字符串名称 xml 文件中包含 @

c# - 列表框仅显示一项

visual-studio-2010 - 使用Visual Studio 2010 Express打开非表达VS项目

c# - 正在分发 dll : What to do with . lib 文件吗?

c# - 从 GitHub 进行持续部署在 Azure 中失败(ASP.NET 5 和 MVC 6)

c# - Automapper 不填充目标对象