请参见下面的示例。我需要将通过反射获得的 DoSomething 方法连接到一个事件。
class Program {
private static event EventHandler MyEvent;
static void Main(string[] args)
{
object aType = new SomeType();
var type = aType.GetType();
var method = type.GetMethod("DoSomething");
if (method != null)
{
MyEvent += method;//How do I wire this up?
}
}
}
public class SomeType {
public void DoSomething() {
Debug.WriteLine("DoSomething ran.");
}
}