简体   繁体   中英

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

Im using the xsd.exe tool to generate classes from a xsd file. The xsd file:

<?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>

The output is:

/// <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;
    }
}}

Instead of:

private BAXMLLimit[] limitField;

I would like it to be

List<BAXMLLimit> limitField

Is there a way in the xsd todo this? Or some other way? Thx!

Try using xsd2code . This works better than xsd.exe. You can also specify as an option how you want your collections to be.. List or an Array by setting the CollectionObjectType property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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