Cast. Should be easy

  • Thread starter The Last Gunslinger
  • 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top