未生成 xsd2code++ 限制
xsd2code++ restrictions not generated
我尝试使用 XSD2Code++(V4.2.0.31,许可版本)从 XSD 生成 C#-类。代码生成正在运行,但它忽略了限制。
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的原因。
也许有人比我更有经验,
提前谢谢你!
支持终于回答了我的问题,解决了我的问题。没有为可枚举属性生成限制。这是一个错误,应该在下一个版本(4.2.0.54 及更高版本)中解决。
无论如何,感谢您的宝贵时间!
我可以确认最新版本的 xsd2code++ (xsd2code.com) 正确生成了所有限制(也适用于可枚举属性)。
这里是结果:
[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;
}
}
我尝试使用 XSD2Code++(V4.2.0.31,许可版本)从 XSD 生成 C#-类。代码生成正在运行,但它忽略了限制。
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的原因。
也许有人比我更有经验, 提前谢谢你!
支持终于回答了我的问题,解决了我的问题。没有为可枚举属性生成限制。这是一个错误,应该在下一个版本(4.2.0.54 及更高版本)中解决。
无论如何,感谢您的宝贵时间!
我可以确认最新版本的 xsd2code++ (xsd2code.com) 正确生成了所有限制(也适用于可枚举属性)。
这里是结果:
[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;
}
}