I have an enumeration defined as follows:
public enum Format {
Normal = 1,
Type2 = 2,
Type3 = 3
}
I’m trying to use Reflection and calling a dynamic type-casting function. However in the code below, the value of “value” is “3” and not “Type3”, and it is not be recognized as an enum. Is it possible to use the int value, 3 to recognize the enumeration?
Type enumType = property.PropertyType;
if (Enum.IsDefined(enumType, value))
return Enum.Parse(enumType, value);
You need to call
Enum.ToObject()to convert the raw value to a boxed instance of the enum.