Geeks With Blogs

News

Google My Blog

Catch me at: The List!


My InstallScript Utility Belt My Amazon Wishlist
My Standard Disclaimer


Archives
Chris G. Williams Beware: I mix tech and personal interests here.

Is there a way (in vb.net) to dynamically create an enum at runtime?

The enum would always have the same items in it, just in a different order (thereby having different values assigned to each item.)

This enum would then be used at runtime by code that already exists.  Crazy huh?

One way I thought off accomplishing this would be to create a file dynamically and then read it back in somehow populating the enum, but the existing code already references the enum(s) in more than one place, so anything other than an enum could require some substantial rewriting.

 

Posted on Wednesday, May 2, 2007 4:33 PM | Back to top


Comments on this post: From the "why am I the only one asking these questions" department...

# re: From the "why am I the only one asking these questions" department...
Requesting Gravatar...
if you didn't define the enum statically, you could use reflection, and reflection.emit to dynamically build the enum declaration, and then reference that in your code.

I think.
Left by Cullen on May 02, 2007 5:09 PM

# re: From the "why am I the only one asking these questions" department...
Requesting Gravatar...
Ok...so the enum's are always being passed into the functions as such, but the enum values themselves will need to be changed...

Is there too much code to alter to do something like create a custom collection of objects that have a static property and a dynamic property, where you can fill the objects with whatever value based on the static value and have the functions being passed the objects determine the dynamic value?

D
Left by D'Arcy from Winnipeg on May 02, 2007 5:45 PM

# re: From the "why am I the only one asking these questions" department...
Requesting Gravatar...
Like Cullen notes, you could use reflection. On the other hand, the whole coolness of enums is to have them available at design time. I think you're going to run into the design time wall with pretty much any approach
Left by Bill on May 02, 2007 9:56 PM

Your comment:
 (will show your gravatar)


Copyright © Chris G. Williams | Powered by: GeeksWithBlogs.net