【发布时间】:2017-05-29 17:32:53
【问题描述】:
我想调用一个方法,该方法在实现某些特定接口的类中。
我已经尝试并搜索了很多,但无法弄清楚该怎么做。 这是我的想法,但它不起作用。
希望有人可以帮助我。
// getting the list
List<Type> instances =
Assembly.GetExecutingAssembly()
.GetTypes()
.Where(a => a.GetInterfaces().Contains(typeof(ISearchThisInterface))).ToList();
foreach (Type instance in instances)
{
// here I want to execute the method of the classes that implement the interface
(instance as ISearchThisInterface).GetMyMethod();
}
在此先感谢
【问题讨论】:
标签: c# class methods interface