Hossein
Hossein

Reputation: 26004

How to create an enum dynamically in C#?

Is there a way that I can use to create Enums dynamically? I'm trying to get the names of tables inside a database and create a list of Enums which I would use when coding inside Visual Studio. Is it even possible?

I think I can get the name of tables in a database but the later part, I have no idea about it.

Upvotes: 0

Views: 1577

Answers (2)

Daniel A. White
Daniel A. White

Reputation: 191058

You can't create an enum easily at runtime.

However, you can use a T4 template to query your database and create a code file that could be compiled in.

Upvotes: 3

Craig Godden-Payne
Craig Godden-Payne

Reputation: 245

There isnt a way of doing this, you could manually create an enum that represents the database,

Maybe it would be better if you used a Dictionary<int, string>

Upvotes: 1

Related Questions