create enum at run time
-
Dear All, I have a DataTable which has 8 records and it will have more records at later too. the data table has two fields (columns) which is "Id" and "Name". I would like to create enum based on "Name" field and the value of enum based on "Id" field. Is it possible to create enums at run time using c#.
-
Dear All, I have a DataTable which has 8 records and it will have more records at later too. the data table has two fields (columns) which is "Id" and "Name". I would like to create enum based on "Name" field and the value of enum based on "Id" field. Is it possible to create enums at run time using c#.
-
Dear All, I have a DataTable which has 8 records and it will have more records at later too. the data table has two fields (columns) which is "Id" and "Name". I would like to create enum based on "Name" field and the value of enum based on "Id" field. Is it possible to create enums at run time using c#.
You can't. The enum has to be created before hand, but you can save the values to the database and parse them at run time by using Enum.Parse(). Please note that you ought to use "Enum" and not "enum", the first is a type the second is a keyword
If the post was helpful, please vote!
Why won't the worm just leave me be?
-
Well how exactly are you hoping to use them?
Life goes very fast. Tomorrow, today is already yesterday.
-
You can't. The enum has to be created before hand, but you can save the values to the database and parse them at run time by using Enum.Parse(). Please note that you ought to use "Enum" and not "enum", the first is a type the second is a keyword
If the post was helpful, please vote!
Why won't the worm just leave me be?
-
well i have checkboxes in many forms. when they are checked i want to insert the enum value in the child table. i can assign the value without run time, but i am afraid if the table "id" is changed than i am stack, so i am creating enums at run time.
sorry you are going to have to try to explain that again. why dont you give an example of a few check boxes and the values you would like to insert into your table when they are checked/unchecked
Member 6059028 wrote:
i am afraid if the table "id" is changed than i am stack
Do you mean the column name of the table or do you mean the actually id value for the table entry?
Life goes very fast. Tomorrow, today is already yesterday.
-
I have gone to create enum at run time using System.Reflection.Emit.EnumBuilder. i can create enums at run time using mentioned class. and hopefully it can be destroyed when you close the application.
Reflection is another matter. How are you expecting to be able to utilize it then?
If the post was helpful, please vote!
Why won't the worm just leave me be?
-
Dear All, I have a DataTable which has 8 records and it will have more records at later too. the data table has two fields (columns) which is "Id" and "Name". I would like to create enum based on "Name" field and the value of enum based on "Id" field. Is it possible to create enums at run time using c#.