I am setting the values from my DataRow into an object using Reflection. But my class has following Property:
public MyEnum EnumProperty
{
get; set;
}
How can I convert the Int32Value into the property enum type, using the following code:
ItemSetter {
...
else if (pInfo.PropertyType.IsEnum) {SetEnum(item, pInfo, pInfo.PropertyType, rowValue); //enum
}
else if (pInfo.PropertyType.IsGenericType && pInfo.PropertyType.GetGenericArguments()[0].IsEnum) {SetEnum(item,pInfo, pInfo.PropertyType.GetGenericArguments()[0], rowValue); //nullable enum
}
...
}
protected
virtual void SetEnum(T item, PropertyInfo pInfo, System.Type enumType, Object rowValue){pInfo.SetValue(item,rowValue) // How to cast
}