簡體   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