How to get the attribute of a Enum value by using refection? For example, we have a Enum:
Enum MyEnum
{
[Description("A")]
a,
[Description("B")]
b
}
And in my class I have a property of type MyEnum:
class MyClass
{
MyEnum Prop {set;get;}
}
During the run time, how can I get the description from the actual value of Prop by not hard coding "MyEnum" in m y function?
string GetDescription(PropertyInfo propInfo)
{
var type = propertyInfo.PropertyType;
var value = propertyInfo.GetValue(this);
????????
}
Aucun commentaire:
Enregistrer un commentaire