Bit of a puzzler, I have a generic class
public abstract class MyClass : UserControl
{
}
and I have got a type like this
<
Something like this:
Type typeArgument = Type.GetType("Type From DB as String", true, true);
Type template = typeof(MyClass<>);
Type genericType = template.MakeGenericType(typeArgument);
object instance = Activator.CreateInstance(genericType);
Now you won't be able to use that as a MyClass
in terms of calling methods on it, because you don't know the T
... but you could define a non-generic base class or interface with some methods in which don't require T
, and cast to that. Or you could call the methods on it via reflection.