Connecting Tech Pros Worldwide Help | Site Map

dynamic enum creation

  #1  
Old July 21st, 2006, 05:25 PM
Steve Teeples
Guest
 
Posts: n/a
Given this definition of an enum:

enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}

Is there a way to dynamically create this same enum at runtime? I want to
read variable data from a file, but this data into an enum to allow the user
to make a choice from a CheckedListBox. I am able to do this from a
predefined enum definition but want to be able to do it with variable data
read from files. As the mouse moves over the enumeration the "Description"
is shown to the user.

Is there some example somewhere of how this can be done?

--
-----------
Thanks,
Steve
  #2  
Old July 21st, 2006, 05:45 PM
Mythran
Guest
 
Posts: n/a

re: dynamic enum creation



"Steve Teeples" <SteveT@newsgroups.nospamwrote in message
news:A3D9A748-25BC-4AA1-9671-DBF370F4A689@microsoft.com...
Quote:
Given this definition of an enum:
>
enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}
>
Is there a way to dynamically create this same enum at runtime? I want to
read variable data from a file, but this data into an enum to allow the
user
to make a choice from a CheckedListBox. I am able to do this from a
predefined enum definition but want to be able to do it with variable data
read from files. As the mouse moves over the enumeration the
"Description"
is shown to the user.
>
Is there some example somewhere of how this can be done?
>
--
-----------
Thanks,
Steve
I think what you are looking for in this context is not an enum
(programmatic name) but instead a list of dynamic values read from a
database (text file, spreadsheet, dbms, etc.). What you could do to get
this to work would be to load your data into a DataTable and then bind this
DataTable to the CheckedListBox. I'm not sure without testing, but I
believe this to be an easier route than dynamically creating an enum.

HTH,
Mythran


  #3  
Old July 21st, 2006, 05:45 PM
Michael Bray
Guest
 
Posts: n/a

re: dynamic enum creation


=?Utf-8?B?U3RldmUgVGVlcGxlcw==?= <SteveT@newsgroups.nospamwrote in
news:A3D9A748-25BC-4AA1-9671-DBF370F4A689@microsoft.com:
Quote:
Given this definition of an enum:
>
enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}
>
Is there a way to dynamically create this same enum at runtime? I
want to read variable data from a file, but this data into an enum to
allow the user to make a choice from a CheckedListBox. I am able to
do this from a predefined enum definition but want to be able to do it
with variable data read from files. As the mouse moves over the
enumeration the "Description" is shown to the user.
>
Is there some example somewhere of how this can be done?

Are you specifically tied to dynamically creating an enum? Because you
don't have to add enum's to a CheckedListBox - you can add any object that
overrides ToString and it will display whatever the output of ToString is.

So instead of going to the pain of dynamically creating an enum, just
create a class that overrides ToString and create one for each value you
read from the database.

It doesn't answer your question, but it seems to address the issue you are
trying to solve.

-mdb
  #4  
Old July 21st, 2006, 05:55 PM
Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a

re: dynamic enum creation


Hi ,

Frankly there is no use at all for a "dynamic enum" , an enum is just a nice
way to give names to values, it's intended only at easying the written of
code and is interpreted at compile time.

What you are after is a collection


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Steve Teeples" <SteveT@newsgroups.nospamwrote in message
news:A3D9A748-25BC-4AA1-9671-DBF370F4A689@microsoft.com...
Quote:
Given this definition of an enum:
>
enum MyEnum {
[Description("This is a descripiton of D1")]
d1=1,
[Description("This is a description of D2")]
d2=2
}
>
Is there a way to dynamically create this same enum at runtime? I want to
read variable data from a file, but this data into an enum to allow the
user
to make a choice from a CheckedListBox. I am able to do this from a
predefined enum definition but want to be able to do it with variable data
read from files. As the mouse moves over the enumeration the
"Description"
is shown to the user.
>
Is there some example somewhere of how this can be done?
>
--
-----------
Thanks,
Steve

  #5  
Old August 3rd, 2006, 12:25 AM
Brennon WIlliams
Guest
 
Posts: n/a

re: dynamic enum creation


No use for a Dynamic enum?

How would you suggest creating a list to be displayed in a property grid, built with values only exposed at runtime?

A collection will not give you a list of values, but a new property grid view with each collection item as an object.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic construction of va_list pete m answers 1 June 4th, 2007 04:55 AM
Between static & dynamic polymorphism... rwf_20 answers 15 November 22nd, 2005 04:14 AM
How do you figure out how much memory a class is using? Joe Fallon answers 15 November 20th, 2005 06:29 PM
xine player steve answers 3 July 19th, 2005 05:17 PM