How to find all the classes which implement a given interface?

前端 未结 6 1036
栀梦
栀梦 2020-11-27 10:36

Under a given namespace, I have a set of classes which implement an interface. Let\'s call it ISomething. I have another class (let\'s call it CClass

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 11:16

    A example using Linq:

    var types =
      myAssembly.GetTypes()
                .Where(m => m.IsClass && m.GetInterface("IMyInterface") != null);
    

提交回复
热议问题