0

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?

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>

  • 1
    Does this answer your question? [How can i get enum to contain a dash (-)?](https://stackoverflow.com/questions/8852253/how-can-i-get-enum-to-contain-a-dash) – Owen Pauling May 06 '20 at 14:44

1 Answers1

0

A workaround is to use the 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. No additional code needed.

pmo44
  • 21
  • 2