0
我有对象列表,其中包含静态EventHandler应侦听哪个类的信息文件夹。我知道这是行不通的,但你会得到这个想法..根据类型添加EventHandler
(事件处理程序不一定是静态的,类也可以是一个单身人士,但不知何故我必须添加一个基于指定类型的EventHandler )
foreach (Service s in InitialParams.Services)
{
FileSystemWatcher w = new FileSystemWatcher(s.WatchFolder);
w.Created += new FileSystemEventHandler(s.Type.GetMethod("FileAdded")); //This doesn't work
w.EnableRaisingEvents = true;
watchers.Add(w);
}