所以我尝试创建一个PluginService,它从一个文件夹加载程序集并检查它是否实现了某个接口。我使用界面
public interface IService
{
void Start();
void Stop();
void Restart();
}
和班级
public class Service : IService
{
public Service()
{
}
public void Restart()
{
}
public void Start()
{
}
public void Stop()
{
}
}
我从pogorman那里找到了this Question,这对我很有帮助。
编辑:
抱歉,我的意思是此代码段不是DoesTypeImplementInterface
currentAssembly.GetTypes()
.Where(t => t != typeof(T) && typeof(T).IsAssignableFrom(t))
.ToList()
.ForEach(x => implementors.Add((T)Activator.CreateInstance(x)));