Help with EnumMemberAttribute?

  • Thread starter Thread starter nomad
  • Start date Start date
N

nomad

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(Value="Insured
Only")]
InsuredOnly = 0,

[System.Runtime.Serialization.EnumMemberAttribute(Value="Insured and
Spouse")]
InsuredandSpouse = 1,
 
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
 
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(VehicleUsageDescription),
classofUse[0])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top