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 121707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:00:48+00:00 2026-05-11T04:00:48+00:00

I want to serialize my enum-value as an int, but i only get the

  • 0

I want to serialize my enum-value as an int, but i only get the name.

Here is my (sample) class and enum:

public class Request {     public RequestType request; }  public enum RequestType {     Booking = 1,     Confirmation = 2,     PreBooking = 4,     PreBookingConfirmation = 5,     BookingStatus = 6 } 

And the code (just to be sure i’m not doing it wrong)

Request req = new Request(); req.request = RequestType.Confirmation; XmlSerializer xml = new XmlSerializer(req.GetType()); StringWriter writer = new StringWriter(); xml.Serialize(writer, req); textBox1.Text = writer.ToString(); 

This answer (to another question) seems to indicate that enums should serialize to ints as default, but it doesn’t seem to do that. Here is my output:

<?xml version='1.0' encoding='utf-16'?> <Request xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>   <request>Confirmation</request> </Request> 

I have been able to serialize as the value by putting an ‘[XmlEnum(‘X’)]’ attribute on every value, but this just seems wrong.

  • 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. 2026-05-11T04:00:48+00:00Added an answer on May 11, 2026 at 4:00 am

    Most of the time, people want names, not ints. You could add a shim property for the purpose?

    [XmlIgnore] public MyEnum Foo {get;set;}  [XmlElement('Foo')] [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)] public int FooInt32 {     get {return (int)Foo;}     set {Foo = (MyEnum)value;} } 

    Or you could use IXmlSerializable, but that is lots of work.

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

Sidebar

Related Questions

I want to serialize this class: public class CarDisplay { public string Name {
I want to serialize a simple object to JSON: public class JsonTreeNode { [DataMember(Name
I have this : [Flags] public enum InfoAbonne{civilite,name,firstname,email,adress,country } public class Formulaire { private
I have a class that I want to serialize [System.Xml.Serialization.XmlTypeAttribute(Namespace = http://xyz.com/schema)] public class
Possible Duplicate: How do I serialize an enum value as an int? Hi, all!
There is a class I want to serialize, and it implements Serializable, but one
I want to serialize a POJO in the name value string format in a
I want to Serialize a 60mb file into XML but it gives me System
I want to serialize a class to xml and store that in a field
i want to serialize this class, to store it on the sdcard of the

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.