By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,563 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,563 IT Pros & Developers. It's quick & easy.

Help with EnumMemberAttribute?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.