Create an enum at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How does one go about creating an enum at runtime from an array of strings?
 
Steve,

Do you want to use it at runtime, or do you just want to generate it?
If you want to use it, it's not going to do you much good, since you will
have to use reflection to actually use it.

However, if you just want to emit the type, take a look at the
EnumBuilder class in the System.Reflection.Emit namespace.

Hope this helps.
 
I need to actually use the enum after generating it.

What I want to do is create a string[] at runtime and display the values as
a drop-down choice in a propertygrid. The only way I know to do it is to
convert the strings to enum's and put the enumeration into a propertygrid.
Do you have another idea of how this can be accomplished.
--
Steve


Nicholas Paldino said:
Steve,

Do you want to use it at runtime, or do you just want to generate it?
If you want to use it, it's not going to do you much good, since you will
have to use reflection to actually use it.

However, if you just want to emit the type, take a look at the
EnumBuilder class in the System.Reflection.Emit namespace.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve Teeples said:
How does one go about creating an enum at runtime from an array of
strings?
 

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


Back
Top