Cast. Should be easy

  • Thread starter Thread starter The Last Gunslinger
  • Start date Start date
T

The Last Gunslinger

I need to cast a boxed byte to an enum without knowing the enum type
beforehand.

ie
object Obj = (byte)MyEnum.MyValue;
Type EnumType = typeof(MyEnum);
EnumType Val = (EnumType)Obj;

Results in
The type or namespace name 'EnumType' could not be found (are you
missing a using directive or an assembly reference?)


The reason I need this is so I can populate an object properly from a db
using reflection.

Cheers
JB
 
Back
Top