471,344 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Help with EnumMemberAttribute?

Hi,

I have an enum below which I need to be able to reference by passing
in "Insured Only". When I do this it says that it cannot be found as
the actual enum shows as InsuredOnly. Is there anyway I can pass in
the correct value i.e. "Insured Only" instead of InsuredOnly?

Appreciate any help on this.
[System.Runtime.Serialization.EnumMemberAttribute(V alue="Insured
Only")]
InsuredOnly = 0,

[System.Runtime.Serialization.EnumMemberAttribute(V alue="Insured and
Spouse")]
InsuredandSpouse = 1,
Jul 2 '08 #1
4 5091
How are you passing it in? For example, XmlSerializer (and a few
others) respect XmlEnumAttribute.
Enum.Parse only uses the actual value, but you can use reflection to
roll your own parse routine that looks at some attribute. I've seen
DescriptionAttribute used in this way many times...

Marc
Jul 2 '08 #2
On 2 Jul, 11:14, Marc Gravell <marc.grav...@gmail.comwrote:
How are you passing it in? For example, XmlSerializer (and a few
others) respect XmlEnumAttribute.
Enum.Parse only uses the actual value, but you can use reflection to
roll your own parse routine that looks at some attribute. I've seen
DescriptionAttribute used in this way many times...

Marc
Hi Marc,

Thanks for your reply.

I am passing it in like below. classofUse[0] = "Insured Only" while
the enum is "InsuredOnly". I have read about refraction but not sure
how I can do it as per my example below. Really appreciate any
suggestions/code snippets.

Description =
(VehicleUsageDescription)Enum.Parse(typeof(Vehicle UsageDescription),
classofUse[0])
Jul 2 '08 #3
Here's an example; it isn't the slickest I've seen (personally I'd use
generics a bit more), but:

http://blog.waynehartman.com/articles/84.aspx

Marc
Jul 2 '08 #4
On Jul 2, 12:22*pm, Marc Gravell <marc.grav...@gmail.comwrote:
Here's an example; it isn't the slickest I've seen (personally I'd use
generics a bit more), but:

http://blog.waynehartman.com/articles/84.aspx

Marc
Marc,

Thank you very much for the link; I had to make some amendments to get
it to work how I needed it but it was then spot on.

Thanks again

Jul 2 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by wukexin | last post: by
3 posts views Thread by Colin J. Williams | last post: by
7 posts views Thread by Corepaul | last post: by
5 posts views Thread by Steve | last post: by
8 posts views Thread by Mark | last post: by

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.