Does reflection in C# offer a way to determine if some given System.Type type models some interface?
public interface IMyInterface {}
public class MyType : IMyInterface {}
// should yield 'true'
typeof(MyType)./* ????? */MODELS_INTERFACE(IMyInterface);
You have a few choices:
typeof(IMyInterface).IsAssignableFrom(typeof(MyType))typeof(MyType).GetInterfaces().Contains(typeof(IMyInterface))typeof(MyType).GetInterface(nameof(IMyInterface)) != nullFor a generic interface, it’s a bit different.