XSD For Class C# Enum

Asked

Viewed 297 times

1

I’m generating a class with XSD.EXE from a schema. I’m summarizing posting only the part of the schema that generates Enum that I doubt.

<xs:simpleType name="TCodUfIBGE">
    <xs:annotation>
        <xs:documentation>Tipo Código da UF da tabela do IBGE</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
        <xs:whiteSpace value="preserve"/>
        <xs:enumeration value="11"/>
        <xs:enumeration value="12"/>
        <xs:enumeration value="13"/>
        <xs:enumeration value="14"/>
        <xs:enumeration value="15"/>
        <xs:enumeration value="16"/>
        <xs:enumeration value="17"/>
        <xs:enumeration value="21"/>
        <xs:enumeration value="22"/>
        <xs:enumeration value="23"/>
        <xs:enumeration value="24"/>
        <xs:enumeration value="25"/>
        <xs:enumeration value="26"/>
        <xs:enumeration value="27"/>
        <xs:enumeration value="28"/>
        <xs:enumeration value="29"/>
        <xs:enumeration value="31"/>
        <xs:enumeration value="32"/>
        <xs:enumeration value="33"/>
        <xs:enumeration value="35"/>
        <xs:enumeration value="41"/>
        <xs:enumeration value="42"/>
        <xs:enumeration value="43"/>
        <xs:enumeration value="50"/>
        <xs:enumeration value="51"/>
        <xs:enumeration value="52"/>
        <xs:enumeration value="53"/>
    </xs:restriction>
</xs:simpleType>

In class it’s getting like this:

Note: Also summarized.

 public enum TCodUfIBGE
 {

    /// <remarks/>
    [System.Xml.Serialization.XmlEnumAttribute("11")]
    Item11,

    /// <remarks/>
    [System.Xml.Serialization.XmlEnumAttribute("12")]
    Item12,

    /// <remarks/>
    [System.Xml.Serialization.XmlEnumAttribute("13")]
    Item13,
 }

Example:

 /// <remarks/>
    [System.Xml.Serialization.XmlEnumAttribute("11")]
    Item11 = 11,

Or else:

public enum TipoPessoa
{
   [System.Xml.Serialization.XmlEnumAttribute("1")]
    Fisica = 1,
   [System.Xml.Serialization.XmlEnumAttribute("2")]
    Juridica = 2
}

EDIT: Is there any way to generate this class with the values for the defined Enum items equal to those of the attribute?

Why in a real application it would be absurd ?

  • 1

    This is an exercise right? In a real application it would be absurd this kind of information stay in the code.

  • 1

    It is not for an application, I am doing several tricks with XSD.EXE to see how it works.

  • 1

    Ah good, if it is exercise/workout beauty. For a moment I found it kind of strange.

  • @Bacco, I’ll edit and add this question you commented.

  • 1

    Just in advance, in a real application if you leave an IBGE code table hardcoded on your system, you need to recompile the code every time you change something. If you query from DB, you can update at any time, and even have an interface to edit this data in DB.

  • @Bacco, got it. Thanks for your help.

  • Downloaded this schema from the NFe Correct?

  • Yes, from the website itself, http://www.nfe.fazenda.gov.br/

Show 3 more comments

1 answer

5


I solved the problem as follows.

When the schema in the VS there are some reference problems:


inserir a descrição da imagem aqui


Somehow this problem of FileioPermission affects the generation of the class by xsd (xsd xmldsig-core-schema_v1.01.xsd nfe_v3.10.xsd /c)

To get around the problem is necessary desbloquearthe file and remove the permission somente leitura (I did this all shcema files)

inserir a descrição da imagem aqui


Now you can generate the class again (xsd xmldsig-core-schema_v1.01.xsd nfe_v3.10.xsd /c) and you will see that it is possible to define the types that were previously not recognized according to the image:


inserir a descrição da imagem aqui


Source: https://stackoverflow.com/questions/3134352/how-do-i-modify-my-settings-to-allow-vs2010-to-load-3rd-party-xsd-files-from-the

  • 1

    That was exactly the problem. Thank you so much for helping.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.