470,815 Members | 1,136 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

retrieving the XmlEnumAttribute and the enum-values (2)

This post is a followup to the thread "retrieving the XmlEnumAttribute values
for an Enum" in this same forum earlier this month, since my last query in
that thread went unanswered.

I have an enum defined (DotNet v2) as
public enum velocityUom
{ [System.Xml.Serialization.XmlEnumAttribute("m/s")]
ms = 21,



My original post was to ask how I could retrieve the XmlEnumAttribute values
for this Enum so that I could create a combo box with values like "m/s",
"cm/a", ... so that I don't have to hard-code the XML-enum values in my code.

Oleg Tkachenko answered with the following solution
Type enumType = typeof(velocityUom);
foreach (FieldInfo fi in enumType.GetFields())
{ object[] attrs = fi.GetCustomAttributes(typeof(XmlEnumAttribute),
if (attrs.Length > 0)
{ Console.WriteLine(((XmlEnumAttribute)attrs[0]).Name);

My question is, while looping through the FieldInfo to get the string
XMLEnumAttributes, is it possible to retrieve the corresponding enumerated
(int) value for each string?

Can anyone help?


Edward Clements

May 22 '06 #1
0 1451

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Kenneth | last post: by
20 posts views Thread by Glenn Venzke | last post: by
8 posts views Thread by Imran | last post: by
6 posts views Thread by randy1200 | last post: by
1 post views Thread by Randy | last post: by
2 posts views Thread by Randy | last post: by
3 posts views Thread by Cmtk Software | last post: by
5 posts views Thread by Sanjay Pais | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.