I am writing some code to read values from a database and convert them into an object.
My object has a few members whose type is custom defined enums.
I am trying something like this in order to convert a string variable to an enum:
var castTo = fieldInfo.PropertyType.GetType(); //returns a Type object, e.g. MyEnum
var parsedEnum = (castTo) Enum.Parse(castTo, valueFromSql);
The problem is that compiler wouldn't accept a variable that contains a Type object.
There is no problem if instead of the castTo variable I use an enum name, but it needs to be defined at runtime.