先找出继承自该接口的接口和实现类,然后遍历这些类型,实例化实现类,最后执行接口的方法。
var type = typeof(IConfigRepository);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p.GetGenericTypeDefinition()));
foreach (var v in types)
{
if (v.IsClass)
{
(Activator.CreateInstance(v) as IConfigRepository).RemoveByConfigVersionID(ConfigVersionID,EnvType);
}
}