Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2006

Tip: Looking for answers? Try searching our database.

Autogenerate enumerations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Bron - 19 Sep 2006 23:35 GMT
Hello,

Does  xsd.exe  support generating  .NET  enumerations from XSD
enumerations?  

That is, if I have
             
       ...
             
    <xs:simpleType name="US_STATE">
        <xs:restriction base="xs:string">
            <xs:enumeration
                value="AL"
            />

            <xs:enumeration
                value="AK"
            />

            <xs:enumeration
                value="AZ" />

            ...
           
            </xs:restriction>               
    </xs:simpleType>

    <xs:element name="State" type"US_STATE" >
   
       ...

as part of my schema, then as part of my generated dataset, I would like to
see something like the following (in C#):

    public enum US_STATE
    {
        AL,
        AK,
        AZ,
        ...
    }
   

    ...

    public WhateverRow AddWhateverRow(
        ...
        US_STATE STATE,
        ...
    )
   
   
    public US_STATE STATE
    {
        get
        {
            return ((US_STATE)
                                (this[this.tableWhatever.STATEColumn]));
        }
        set
        {
            this[this.tableWhatever.STATEColumn] = value;
        }
    }
   
The advantage would be to catch validation errors at compile time and the
ability to leverage IntelliSense (i.e. catching errors BEFORE compile time,
at programming-time :).

-Dan

PS:  Similar questions apply to other  xs:restrictions  , such as
xs:maxLength  , but I'm really most interested in  xs:enumeration.
olrt - 25 Sep 2006 16:22 GMT
Dan Bron a écrit :

> Hello,
>
> Does  xsd.exe  support generating  .NET  enumerations from XSD
> enumerations?

Hi, I don't know if it might help you but as the ASP.NET XML
WebServices documentation says, the .NET enum type is supported.
When serialized, the enum is transcripted to a string whose value is
the enum item.

However I don't know if the XSD enum type is supported.

Regards,
Olivier.
John Saunders - 25 Sep 2006 18:33 GMT
Dan Bron a écrit :

> Hello,
>
> Does  xsd.exe  support generating  .NET  enumerations from XSD
> enumerations?

Hi, I don't know if it might help you but as the ASP.NET XML
WebServices documentation says, the .NET enum type is supported.
When serialized, the enum is transcripted to a string whose value is
the enum item.

However I don't know if the XSD enum type is supported.

XSD doesn't have an "enum" type. The enumeration facet is simply a way of
constraining the lexical space of a simple type to one of the enumerated
values. The type of the item remains the type being restricted. For
instance:

<xs:simpleType name="SomeType">
   <xs:restriction base="xs:int">
       <xs:enumeration value="1"/>
       <xs:enumeration value="3"/>
   </xs:restriction>
</xs:simpleType>

This defines "SomeType" as an xs:int which is restricted by having only 1
and 3 as possible values. It does not define the same sort of thing as a
programming language enum. Notice, for instance, the lack of a name to go
with the value "1".

John

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.