工作代码示例:
var instances = from t in Assembly.GetExecutingAssembly().GetTypes() where t.GetInterfaces().Contains(typeof(ISomething)) && t.GetConstructor(Type.EmptyTypes) != null select Activator.CreateInstance(t) as ISomething;foreach (var instance in instances){ instance.Foo(); // where Foo is a method of ISomething}编辑 添加了对无参数构造函数的检查,以便对CreateInstance的调用将成功。



