简体   繁体   English

将 xsd 枚举转换为枚举 c #

[英]converting an xsd enumeration to enum c #

in an xsd file I had a type enumeration with options N1 and N2 (as below) which through the conversion to a c# class was represented by an enum type, now to the type enumeration the option N2.1 has been added, which cannot be represented as an option in an enum type (dot is not allowed), what can I do?在 xsd 文件中,我有一个带有选项 N1 和 N2 的类型枚举(如下所示),它通过转换为 c# class 已添加到枚举类型,现在不能由枚举类型表示1。表示为枚举类型中的一个选项(不允许使用点),我该怎么办?

Thanks谢谢

<xs:simpleType name="NaturaType">
<xs:restriction base="xs:string">
  <xs:enumeration value="N1">
    <xs:annotation>
      <xs:documentation>Escluse ex. art. 15</xs:documentation>
    </xs:annotation>
  </xs:enumeration>
  <xs:enumeration value="N2">
    <xs:annotation>
      <xs:documentation>Non soggette</xs:documentation>
    </xs:annotation>
  </xs:enumeration>
</xs:restriction>

A workaround is to use the XmlEnumAttribute :一种解决方法是使用XmlEnumAttribute

public enum NaturaType
{
    /// <remarks/>
    N1,
    /// <remarks/>
    N2,
    /// <remarks/>
    [XmlEnumAttribute("N2.1")]
    N2_1,
    /// <remarks/>
    [XmlEnumAttribute("N2.2")]
    N2_2,
    /// <remarks/>
    N3,
    ...
}

It is used to validate an xml with an xsd.它用于验证 xml 和 xsd。 No additional code needed.不需要额外的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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