can I create an enum dynamically in the code?

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Can I create an enum dynamically in the code, e.g. data base driven?

Thanks!
Ryan
 
Would it be better to just use integer or char instead?

Afterall, the enum's effective value would be something of the sort.
 
Hi,

And use it how?

the only reason of the enum is to gives meanful names to values, just use
the values from the DB
 
Can I create an enum dynamically in the code, e.g. data base driven?

Thanks!
Ryan

How about EnumBuilder in system.Reflection.Emit ?
 
Can I create an enum dynamically in the code ...

enum My_enm : int
{
First_value,
Second_value
}

int l_enm_val = 7;
Enum l_new_enm_ins;
Type l_enm_typ;
Object l_enm_obj

l_enm_typ = typeof( My_enm );

l_new_enm_ins = ( Enum ) Activator.CreateInstance(l_enm_typ);

l_new_enu_ins = ( Enum ) Activator.CreateInstance(l_enm_typ, l_num_value );

l_enm_obj = ( My_enm ) Enum.ToObject( l_enm_typ, l_enm_val );

Hope this helps.

Shawnk
 

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

Similar Threads

about enum 3
Enum TypeConverter 3
Dynamic Enum 3
dynamic enum creation 4
Merge Info From Two Enums 1
Enums & Constructors? 4
enum type 3
Options for replacing enums stored in database.... 4

Back
Top