Enum - XmlEnum

W

wasco77

Hi all,
I've a problem using enum tag.
I need to create a structure like this:

// ---------------------------------------
[Serializable]
public enum typeSupply
{
[XmlEnum(Name = "5VOnly")]
5VOnly,
[XmlEnum(Name = "3V")]
3V
}
// ---------------------------------------

but I can't define an enum item starting with a number.
Do you know how define an item name starting with number?
I use it in order to serialize/deserialize an xml file, which include
a tag with that item.

Thanks in advance.
Walter
 
N

Nicholas Paldino [.NET/C# MVP]

Walter,

In C#, you can not use a number as the first character in an identifier.
You will have to do something like this:

public enum typeSupply
{
[XmlEnum(Name = "5VOnly")]
FiveVOnly,
[XmlEnum(Name = "3V")]
ThreeV
}

The Xml serialization engine will still be able to pick out values in
the XML file named "5VOnly" and "3V".

I am curious, are you applying the Serializable attribute because you
use this enumeration in Serialization with a Binary or Soap formatter as
well, or for XML serialization? If the answer is the latter, then you do
not need to put the Serializable attribute on the enumeration, because XML
serialization does not use this attribute.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top