Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:43:31+00:00 2026-05-26T04:43:31+00:00

I have an xsd file from which I am generating a C# class. In

  • 0

I have an xsd file from which I am generating a C# class. In order to provide easier maintenance, I’d like to define an enumeration within the xsd file only so that when I have to change the enum, I only have to update it in one place. I know how to create the enum, but when the C# code is generated, I need the enum members to have custom values, so the result would be similar to:

public enum SetupTypeEnum {
    None = 0,
    NewInstall = 1,
    Modify = 2,
    Upgrade = 4,
    Uninstall = 8
}

Is there any way to write the xsd to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:43:31+00:00Added an answer on May 26, 2026 at 4:43 am

    You can add annotations specific for code generation (this only works for svcutil, not for xsd.exe) to your xsd file. The xsd definition for your enum would be something like this:

    <xs:simpleType name="SetupTypeEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="None">
                <xs:annotation>
                    <xs:appinfo>
                        <EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/">0</EnumerationValue>
                    </xs:appinfo>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="NewInstall">
                <xs:annotation>
                    <xs:appinfo>
                        <EnumerationValue xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1</EnumerationValue>
                    </xs:appinfo>
                </xs:annotation>
            </xs:enumeration>
            ...
        </xs:restriction>
    </xs:simpleType>
    

    These annotations allow you to explicitly define the numerical value of each enum value. You can find an example on this msdn page if you search for “EnumerationValue”.

    Update: John Saunders correctly states in his comment that this doesn’t work if you use xsd.exe. However, if you use svcutil.exe to create the C# code, then the annotations will work.

    Example of using svcutil.exe:

    svcutil /dconly "D:\test.xsd" /o:"D:\test.cs"
    

    If you use svcutil instead of xsd.exe, then the generated code will by slightly different. The most important difference is that svcutil will generate attributes for DataContractSerialization instead of XmlSerialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I have needed to create a class file from an XML XSD schema,
I have a CSV file, and a XSD from which I need to create
I have this Maven task to generate Java classes from an XSD file using
I have an XSD file which is used to generate some objects which are
I have created a C# class file by using a XSD-file as an input.
I have a gigantic QuickBooks SDK .XSD schema file which defines XML requests/responses that
I have a WCF service. I built from an xsd file from another department.
I have a package which just includes and xsd file to generate (via JAXB)
I have xsd file. I want to generate my entity model from this schema
I have a simple XML file here which I converted to XSD with xsd.exe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.