.net - generic function to return enum value -


i have 3 different enum , of 3 has same identifier different values. want access particular enum based on condition.

for example:

public enum type1      font = 10      color = 11  end enum  public enum type2      font = 20      color = 21 end enum  public enum type3      font = 30      color = 31 end enum 

and based on condition need access particular enum. example,

if(somecondition = 1)      return type1.font else if (somecondition = 2)     return type2.font else if (somecondition = 3)     return type3.font 

i need repeat same logic access other enum identifier. there way can write generic method return me enum value?

for example,

public function getenumvalue(enumtype, identifier) integer    return enumtype.identifier   end function 

is there way write above generic function return enum value?

updated: looking method getenumvalue(type1,font) returns enum value in integer (in case 10 type1.font)

your question extremely unclear.

you may looking

return enum.parse(enumtype, valuename); 

where enumtype type object , valuename string.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -