I have the following code
public void MyMethod(object myClass)
{
if(myClass.GetType().IsSubclassOf(typeof(MyBaseClass)))
{
// Instantiate a generic list here....
// Assume that myClass is type Class1, e.g. List<Class1> abc = new List<Class1>();
}
}
Within the if statement I want to create a List of the type of myClass. Is this possible? I am assuming it is through reflection but I can’t see how to do it.
1 Answer