Enumerations

J

John Hom

Greetings,

I was wondering if there was a way of dynamically
creating enumerations. For example, we could do it
statically like:

enum stuff
zero,
one,
two,
three
end enum

But what if we later discover we need to add "four" to
stuff?

There are two methods, Enum.Parse(), that take a comma-
delimited string, but I don't think this is what I want.

Any help would be greatly appreciated!

Happy Holidays to all!

John
 
B

Blumidoo

I was wondering if there was a way of dynamically
creating enumerations. (...)

Well...
There is, but it's not worth the effort.

For example you could create the list in the runtime, then create a source
module (*.vb) dynamically that contains your enum, _then_ call the VB.NET
compiler, and _then_ late-bind to the resulting assembly.
Whoa...

--
sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
 
H

Herfried K. Wagner [MVP]

* "John Hom said:
I was wondering if there was a way of dynamically
creating enumerations. For example, we could do it
statically like:

enum stuff
zero,
one,
two,
three
end enum

But what if we later discover we need to add "four" to
stuff?

Add it in the code... What's the problem? Why do you need to "add" it
at runtime? Maybe you are looking for a collection, not for an
enumeration.
 
R

Rob Teixeira [MVP]

Well, if you ignore the nasty version problems that will happen if you go
this route, you can use System.Reflection.Emit to create types dynamically
at runtime.
However, since Enums are mostly a convention of convenience for the
PROGRAMMER working with code, it doesn't really do much good to add more at
runtime, does it?

-Rob Teixeira [MVP]
 

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

Top