I have written the following code where I am trying to determine whether a generic classes type inherits from a base class. I think this is easier to explain what I am doing in code. Could anybody please provide some insight into how to get around this issue.
public class MyGeneric<T>
{
}
public class MyBaseClass
{
}
public class MyClass1 : MyBaseClass
{
}
static void Main(string[] args)
{
MyGeneric<MyClass1> myList = new MyGeneric<MyClass1>();
if(myList.GetType() == typeof(MyGeneric<>))
{
// Not equal
}
// This is the test I would like to pass!
if(myList.GetType() == typeof(MyGeneric<MyBaseClass>))
{
// Not equal
}
if(myList.GetType() == typeof(MyGeneric<MyClass1>))
{
// Equal
}
}