How do you generate new enumerations at runtime?

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

Guest

Okay, so the deal is, I'm using the enum structure to populate some list, the
problem is that I don't have the enums at compile time, they must be
generated at runtime (i.e. read from some file or what not). I need them to
be in the enum type of structure for a specific control that I've built (and
don't want to rebuild in some other manner). Is there a way to generate an
enum at runtime or am I stuck making a class that acts like the enum?
 
Okay, so the deal is, I'm using the enum structure to populate some
list, the problem is that I don't have the enums at compile time, they
must be generated at runtime (i.e. read from some file or what not).
I need them to be in the enum type of structure for a specific control
that I've built (and don't want to rebuild in some other manner). Is
there a way to generate an enum at runtime or am I stuck making a
class that acts like the enum?

You could try your hand at using EnumBuilder. I've never had luck making
it work. You may be different.

I would stick to a class. They are more flexible in the long run
 
Jebrew said:
Okay, so the deal is, I'm using the enum structure to populate some list, the
problem is that I don't have the enums at compile time, they must be
generated at runtime (i.e. read from some file or what not). I need them to
be in the enum type of structure for a specific control that I've built (and
don't want to rebuild in some other manner). Is there a way to generate an
enum at runtime or am I stuck making a class that acts like the enum?

Enums are supposed to be used to build type-safe code. If you haven't
got the need for that (ie. you're doing this at runtime instead of
compile time), why not just stick to a list of strings?
 
Hi,

In this escenario I would go for a class , enum (as some other poster said)
are intented to clarify your code (like avoiding using numbers) .


cheers,
 

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

Back
Top