473,405 Members | 2,344 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,405 software developers and data experts.

Conversion of XmlText enum attributes

Hi there,

I have an enum field that I serialize:

[XmlAttribute("direction"), XmlText(typeof(ParameterDirection))]
public ParameterDirection Direction = ParameterDirection.Out;

The enum looks like this:
public enum ParameterDirection { In, Out, Both };

In the generated XML, the value has to be lowercase. But, since "In" is a
reserved word, I cannot have this as an enum value.

How can I do this in a generic way?

Any help appreciated,
Thanks,
Michel
Nov 12 '05 #1
2 2833
"Michel" <mi****@nospam.nl> wrote in message news:c0**********@reader11.wxs.nl...
public enum ParameterDirection { In, Out, Both };

In the generated XML, the value has to be lowercase. But, since "In" is a
reserved word, I cannot have this as an enum value.

How can I do this in a generic way?


The XmlEnumAttribute can be applied to the members of an Enum to
alter the text representation of their value emitted by XmlSerializer.

public enum ParameterDirection {
[XmlEnum( "in")] In,
[XmlEnum( "out")] Out,
[XmlEnum( "both")] Both
};

That should be all you need to make it work.
Derek Harmon
Nov 12 '05 #2
Thanks Derek,

Exactly what I needed.

"Derek Harmon" <lo*******@msn.com> wrote in message
news:uN****************@tk2msftngp13.phx.gbl...
"Michel" <mi****@nospam.nl> wrote in message

news:c0**********@reader11.wxs.nl...
public enum ParameterDirection { In, Out, Both };

In the generated XML, the value has to be lowercase. But, since "In" is a reserved word, I cannot have this as an enum value.

How can I do this in a generic way?


The XmlEnumAttribute can be applied to the members of an Enum to
alter the text representation of their value emitted by XmlSerializer.

public enum ParameterDirection {
[XmlEnum( "in")] In,
[XmlEnum( "out")] Out,
[XmlEnum( "both")] Both
};

That should be all you need to make it work.
Derek Harmon

Nov 12 '05 #3

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

Similar topics

2
by: Anirudh | last post by:
Hi, i wanted to know if there is any way to convert an object to XMlText to XMLElement. Thanks in advance.
4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
10
by: Ken Allen | last post by:
The ToString() function, when applied to a variable that is an enumeration type, results in a string that is the name of the enumerated value that was defined in the source code. This is cool, but...
3
by: Sanjay Pais | last post by:
I know that string/char enum is not possible in c# (.NET2.0) I need to create the equivalent of this: public enum HOW_GOOD { AWESOME = "A", GREAT= "G", NOT_TOO_BAD = "N", TERRIBLE="T" }
1
by: thejeffross | last post by:
I have a memory problem that keeps causing server resets, so I'm using WinDbg to figure out what the problem is. When I look at the heap, WinDbg tells me that there are over one million XmlText...
1
by: Joe HM | last post by:
Hello - I have two Enums for which I would like to define type conversions ... Public Enum eA A2 = 0 A2 = 1 End Enum Public Enum eB B1 = 2
1
by: None | last post by:
I'm trying to mark up an enum in a .h file such that when it is emitted to the .idl file the elements of the enum can be marked up with helpstring attributes. Microsoft has a published sample...
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...
3
by: Chevron Boyde | last post by:
Hi There I have some codes that represent Sale Types i.e. A = On Account, C = Cash, D = Debtor, V = Voucher I want to create an enum or struct to work with the logical names like "Cash" as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.