繁体   English   中英

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

[英]XSD: Using Visual studio xsd.exe not generating Array[] instead of List<>

我使用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 todo中的一种方法吗? 或者其他一些方式? 谢谢!

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

暂无
暂无

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

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