473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Enum - XmlEnum

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

Apr 12 '07 #1
2 10017
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"wasco77" <wa*****@gmail.comwrote in message
news:11**********************@w1g2000hsg.googlegro ups.com...
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

Apr 12 '07 #2

Thanks a lot!
Walter

Apr 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michel | last post by:
Hi there, I have an enum field that I serialize: public ParameterDirection Direction = ParameterDirection.Out; The enum looks like this: public enum ParameterDirection { In, Out, Both };
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
3
by: slamb | last post by:
Hi all, Does anyone know of a way to deserialize xml data that has an element that represents an enum value but is actually an int? I know I can use to tag enum values, that works but is too...
1
by: Richard Bysouth | last post by:
Hi Does anyone know of a way to deserialize xml data that has an element that represents an enum value but is actually an integer? I know I can use to tag enum values, that works but is too...
2
by: Martin Engelhardt | last post by:
Hi, I want to use the following: Class Test ... Public Enum TestEnum as integer Enum1 = 128 Enum2 = 256 End Enum
1
by: Powers | last post by:
I currently have a large number of enums implemented into my Web Service. I am reworking the XML serialization of these enums. At present, each enum has hardcoded values, for example: xAttrs...
3
by: Diego | last post by:
I have an Enum like this: public enum DAYS { Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6,
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.