K
Klerk
I have a base class Control and a 2 derived classes Control<T>:Control
and ControlEnum:Control.
The reason I have Control<T> and ControlEnum is these classes have a
field called "value" whose type is unknown until runtime. If it's type
is an enum, the enum definition itself isnt known until run time.
So at runtime I am basically doing the following:
1. get type of value
2. if int create Control<int>
if float create Control<float> etc
if enum build "list" of names and values and create ControlEnum
(passing names[] values[] to its ctor)
I initially had the field "value" defined in the base class, but moved
it into the two subclass as I couldnt come up with a way of
dynamically creating an enum and passing it as T to Control<T>.
Now I have an ArrayList of controls and want to be able to access
"value" like so
foreach(control c in controls)
tmp = c.Value
and here I get stuck not knowing what the type of c.Value is!
How do I design the classes to handle this? I am newbie to oops
concepts so any advice would be greatly appreciated. Thanks a lot.
and ControlEnum:Control.
The reason I have Control<T> and ControlEnum is these classes have a
field called "value" whose type is unknown until runtime. If it's type
is an enum, the enum definition itself isnt known until run time.
So at runtime I am basically doing the following:
1. get type of value
2. if int create Control<int>
if float create Control<float> etc
if enum build "list" of names and values and create ControlEnum
(passing names[] values[] to its ctor)
I initially had the field "value" defined in the base class, but moved
it into the two subclass as I couldnt come up with a way of
dynamically creating an enum and passing it as T to Control<T>.
Now I have an ArrayList of controls and want to be able to access
"value" like so
foreach(control c in controls)
tmp = c.Value
and here I get stuck not knowing what the type of c.Value is!
How do I design the classes to handle this? I am newbie to oops
concepts so any advice would be greatly appreciated. Thanks a lot.