How to determine if a type implements an interface with C# reflection?
There are many ways to determine if a type implements an interface in C#1) using:
typeof(IMyInterface).IsAssignableFrom(typeof(MyType))
2) using
typeof(MyType).GetInterfaces().Contains(typeof(IMyInterface))
For a generic interface, it’s a bit different.
typeof(MyType).GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMyInterface<>))