I am trying to instantiate a generic class using an object of type.
Basically, at runtime I will have a collection of objects of different types, and since there is no way to find out what types they will be exactly, I think I will have to use Reflection.
I was working on something like:
Type elType = Type.GetType(obj); Type genType = typeof(GenericType<>).MakeGenericType(elType); object obj = Activator.CreateInstance(genType);
This is good and good. ^ ___ ^
The problem is that I would like to access the method of my GenericType <> instance, which I cannot, because it was introduced as an object class. I can’t find a way to do this obj in a specific GenericType <> because it was a problem in the first place (i.e. I just can’t add something like :)
((GenericType<elType>)obj).MyMethod();
How to solve this problem?
Many thanks! ^ ___ ^
Richard Neil Ilagan
source share