user1229895 user1229895 - 6 months ago 30
C# Question

Check if 'T' inherits or implements a class/interface

Is there a way to test if T inherits/implements a class/interface?

private void MyGenericClass<T> ()
if(T ... inherits or implements some class/interface


There is a Method called Type.IsAssignableFrom().

It is used like this:


If you are targeting .NET Core, the method has moved to TypeInfo: