Cast to a Generic Type at runtime
-
Hi, I have the following problem: I have a generic, which derives from a normal base class like this: public class MyClass : BaseClass { T m_Value; public SetValue(T val) { // ... } public T GetValue(){ ... } ; } These classes are stored in a generic dictionary, which is instantiated like this: dictionary dic = new dictionary(); At one point, I want to acess the SetValue Function, but I have to cast to the exact type, and typeof() / GetType doesn't works here. What I try to do looks similar like this, but I haven't a solution yet; MyClass< dic["Key"].GetType() > tC, tC2; tC.SetValue((dic["Key"].GetType())dic["Key"].GetValue()); This isn't correct (i left out the instantiation) , I know, but I need to cast at runtime to the exact generic type, stored at the position in the dictionary, for accessing the generic, type specific Get/Set function. Any comments ? Thanks, Florian