C# 带有数据注释验证的complextype的Xml模式序列化
我有以下模式部分:C# 带有数据注释验证的complextype的Xml模式序列化,c#,xml-serialization,data-annotations,complextype,C#,Xml Serialization,Data Annotations,Complextype,我有以下模式部分: <xs:element name="authorizationNumber" type="authorizationIdType"> </xs:element> <xs:complexType name="authorizationIdType"> <xs:choice> <xs:element name="authorizationIdNumber" type="authorizationNumb
<xs:element name="authorizationNumber" type="authorizationIdType">
</xs:element>
<xs:complexType name="authorizationIdType">
<xs:choice>
<xs:element name="authorizationIdNumber" type="authorizationNumberType">
</xs:element>
<xs:element name="authorizationIdFree" type="xs:string">
</xs:element>
</xs:choice>
</xs:complexType>
<xs:simpleType name="authorizationNumberType">
<xs:restriction base="xs:string">
<xs:length value="17"/>
<xs:pattern value="(0[1-9]|1[0-9])(P0[1-3]|G0[1-5]|T0[1-2])\d{12}"/>
</xs:restriction>
</xs:simpleType>
问题是,由于它是一个复杂的类型,数据注释没有包含在内,但我不知道在这种情况下如何包含它们,因为只有当公共对象项的类型为authorizationIdNumber时,才必须应用它们
例如,在另一个元素的简单情况下,会生成如下注释:
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public authorizationIdType authorizationNumber { get; set; }
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="x")]
public partial class authorizationIdType
{
[System.Xml.Serialization.XmlElementAttribute("authorizationIdFree", typeof(string), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlElementAttribute("authorizationIdNumber", typeof(string), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public object Item { get; set; }
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType2 ItemElementName { get; set; }
}
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="x", IncludeInSchema=false)]
public enum ItemChoiceType2
{
[System.Xml.Serialization.XmlEnumAttribute(":authorizationIdFree")]
authorizationIdFree,
[System.Xml.Serialization.XmlEnumAttribute(":authorizationIdNumber")]
authorizationIdNumber
}
[System.ComponentModel.DataAnnotations.StringLengthAttribute(5)]
[System.ComponentModel.DataAnnotations.RegularExpressionAttribute("[0-9]{5}")]
public string PostalCode{ get; set; }
也许是台词:
[System.Xml.Serialization.XmlElementAttribute("authorizationIdNumber", typeof(string), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
应该是这样的:
[System.Xml.Serialization.XmlElementAttribute("authorizationIdNumber", typeof(authorizationNumberType), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
并创建一个类类型来保存带有数据注释的字符串值?这是我不知道如何编码的部分,因此序列化和属性实例化继续正常工作,但包括数据注释验证