2017-01-02 37 views
0

我試圖從XSD使用XSD2Code ++(V4.2.0.31,許可版本)生成C#類。代碼生成工作正常,但省略了限制。xsd2code ++限制不生成

XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name ="Product"> 
     <xs:complexType> 
      <xs:sequence maxOccurs="3"> 
       <xs:element name="Header" minOccurs="1" maxOccurs="1"/> 
       <xs:element name="Body"/> 
       <xs:element name ="value2" maxOccurs="1"> 
        <xs:simpleType> 
         <xs:restriction base="xs:string"> 
          <xs:minLength value="20" /> 
          <xs:maxLength value="22" /> 
         </xs:restriction> 
        </xs:simpleType> 
       </xs:element> 
       <xs:element name ="value4" maxOccurs="1"> 
        <xs:simpleType> 
         <xs:restriction base="xs:int"> 
          <xs:minInclusive value="5" /> 
          <xs:maxInclusive value="6" /> 
         </xs:restriction> 
        </xs:simpleType> 
       </xs:element> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

,並生成該代碼,限制失蹤。我希望看到他們在制定者。

// ------------------------------------------------------------------------------ 
// <auto-generated> 
// Generated by Xsd2Code++. Version 4.2.0.31 
// <NameSpace>xsd2code_Probierprojekt</NameSpace><Collection>List</Collection><codeType>CSharp</codeType><EnableDataBinding>False</EnableDataBinding><GenerateCloneMethod>False</GenerateCloneMethod><GenerateDataContracts>False</GenerateDataContracts><DataMemberNameArg>OnlyIfDifferent</DataMemberNameArg><DataMemberOnXmlIgnore>False</DataMemberOnXmlIgnore><CodeBaseTag>Net40</CodeBaseTag><InitializeFields>All</InitializeFields><GenerateUnusedComplexTypes>False</GenerateUnusedComplexTypes><GenerateUnusedSimpleTypes>False</GenerateUnusedSimpleTypes><GenerateXMLAttributes>True</GenerateXMLAttributes><OrderXMLAttrib>False</OrderXMLAttrib><EnableLazyLoading>False</EnableLazyLoading><VirtualProp>False</VirtualProp><PascalCase>False</PascalCase><AutomaticProperties>False</AutomaticProperties><PropNameSpecified>None</PropNameSpecified><PrivateFieldName>StartWithUnderscore</PrivateFieldName><PrivateFieldNamePrefix></PrivateFieldNamePrefix><EnableRestriction>True</EnableRestriction><RestrictionMaxLenght>True</RestrictionMaxLenght><RestrictionRegEx>True</RestrictionRegEx><RestrictionRange>True</RestrictionRange><ValidateProperty>True</ValidateProperty><ClassNamePrefix></ClassNamePrefix><ClassLevel>Public</ClassLevel><PartialClass>True</PartialClass><ClassesInSeparateFiles>False</ClassesInSeparateFiles><ClassesInSeparateFilesDir></ClassesInSeparateFilesDir><TrackingChangesEnable>False</TrackingChangesEnable><GenTrackingClasses>False</GenTrackingClasses><HidePrivateFieldInIDE>False</HidePrivateFieldInIDE><EnableSummaryComment>False</EnableSummaryComment><EnableAppInfoSettings>False</EnableAppInfoSettings><EnableExternalSchemasCache>False</EnableExternalSchemasCache><EnableDebug>False</EnableDebug><EnableWarn>False</EnableWarn><ExcludeImportedTypes>False</ExcludeImportedTypes><ExpandNesteadAttributeGroup>False</ExpandNesteadAttributeGroup><CleanupCode>False</CleanupCode><EnableXmlSerialization>True</EnableXmlSerialization><SerializeMethodName>Serialize</SerializeMethodName><DeserializeMethodName>Deserialize</DeserializeMethodName><SaveToFileMethodName>SaveToFile</SaveToFileMethodName><LoadFromFileMethodName>LoadFromFile</LoadFromFileMethodName><EnableEncoding>False</EnableEncoding><EnableXMLIndent>False</EnableXMLIndent><Encoder>UTF8</Encoder><Serializer>XmlSerializer</Serializer><sspNullable>False</sspNullable><sspString>False</sspString><sspCollection>False</sspCollection><sspComplexType>False</sspComplexType><sspSimpleType>False</sspSimpleType><sspEnumType>False</sspEnumType><BaseClassName>EntityBase</BaseClassName><UseBaseClass>False</UseBaseClass><GenBaseClass>False</GenBaseClass><CustomUsings></CustomUsings><AttributesToExlude></AttributesToExlude> 
// </auto-generated> 
// ------------------------------------------------------------------------------ 
#pragma warning disable 

namespace xsd2code_Probierprojekt 
{ 
using System; 
using System.Diagnostics; 
using System.Xml.Serialization; 
using System.Collections; 
using System.Xml.Schema; 
using System.ComponentModel; 
using System.IO; 
using System.Text; 
using System.ComponentModel.DataAnnotations; 
using System.Xml; 
using System.Collections.Generic; 


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34209")] 
[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 Product 
{  
    private List<object> _header; 
    private List<object> _body; 
    private List<string> _value2; 
    private List<double> _value4; 
    private static XmlSerializer serializer; 

    public Product() 
    { 
     this._value4 = new List<double>(); 
     this._value2 = new List<string>(); 
     this._body = new List<object>(); 
     this._header = new List<object>(); 
    } 


    [System.Xml.Serialization.XmlElementAttribute("Header", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public List<object> Header 
    { 
     get 
     { 
      return this._header; 
     } 
     set 
     { 
      this._header = value; 
     } 
    } 


    [System.Xml.Serialization.XmlElementAttribute("Body", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public List<object> Body 
    { 
     get 
     { 
      return this._body; 
     } 
     set 
     { 
      this._body = value; 
     } 
    } 


    [System.Xml.Serialization.XmlElementAttribute("value2", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public List<string> value2 
    { 
     get 
     { 
      return this._value2; 
     } 
     set 
     { 
      this._value2 = value; 
     } 
    } 


    [System.Xml.Serialization.XmlElementAttribute("value4", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    public List<double> value4 
    { 
     get 
     { 
      return this._value4; 
     } 
     set 
     { 
      this._value4 = value; 
     } 
    } 

Serialisers and Deserialisers etc. 

} 
} 

#pragma warning restore 

當然,我可以自己驗證它,但我的公司希望從XSD生成更快的限制並避免錯誤。這是對專業版xsd2code進行掃描的原因。

也許有人比我更有經驗, 先謝謝了!

回答

0

支持終於回答了我的問題,並解決了我的問題。沒有爲可枚舉的屬性生成限制。這是一個錯誤,應該在下一個版本(4.2.0.54及以上版本)中解決。

無論如何,謝謝你的時間!

0

我可以確認最新版本的xsd2code ++(xsd2code.com)可以正確生成所有限制(也適用於可枚舉的屬性)。

Screenshot of xsd2code++

+0

我不能給予好評,因爲我沒有足夠的聲譽。該錯誤已解決,非常感謝您的確認! –

0

下面的結果:

[System.Xml.Serialization.XmlElementAttribute("value2", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    [System.ComponentModel.DataAnnotations.StringLengthAttribute(22, MinimumLength = 20)] 
    public List<string> value2 
    { 
     get 
     { 
      return this._value2; 
     } 
     set 
     { 
      System.ComponentModel.DataAnnotations.ValidationContext validatorPropContext = new System.ComponentModel.DataAnnotations.ValidationContext(this, null, null); 
      validatorPropContext.MemberName = "value2"; 
      Validator.ValidateProperty(value, validatorPropContext); 
      this._value2 = value; 
     } 
    } 


    [System.Xml.Serialization.XmlElementAttribute("value4", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] 
    [System.ComponentModel.DataAnnotations.RangeAttribute(5, 6)] 
    public List<int> value4 
    { 
     get 
     { 
      return this._value4; 
     } 
     set 
     { 
      System.ComponentModel.DataAnnotations.ValidationContext validatorPropContext = new System.ComponentModel.DataAnnotations.ValidationContext(this, null, null); 
      validatorPropContext.MemberName = "value4"; 
      Validator.ValidateProperty(value, validatorPropContext); 
      this._value4 = value; 
     } 
    }