更新时间:2022-12-04 19:51:02
您必须把我的头顶部的几个选择
的typeof(IMyInterface的).IsAssignableFrom(typeof运算(的MyType))
typeof运算(的MyType).GetInterfaces()。包含(typeof运算(IMyInterface的))
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 off the top of my head
typeof(IMyInterface).IsAssignableFrom(typeof(MyType))
typeof(MyType).GetInterfaces().Contains(typeof(IMyInterface))