クラスが一連のイベントを提供するイベントベースのシステムを作成し、そのメンバーメソッドを持つ別のクラスをイベントハンドラーとして最初のクラスにアタッチできます...私はただこのようなことをしたいだけです
if(isMethodCompatibleToEvent(...))
{
connectMethodToEvent(...)
}
リフレクションを介して、これは接続が行われる方法です:
void connectMethodToEvent(object methodTarget, MethodInfo mi,
object eventTarget, EventInfo ei)
{
Delegate handler = Delegate.CreateDelegate(ei.EventHandlerType, methodTarget, mi);
ei.AddEventHandler(eventTarget, handler);
}
メソッドがイベントと互換性がない場合、例外がスローされます。これを修正するために、メソッド デリゲートを作成する前にいくつかのチェックを作成したいのですが、どうすればよいでしょうか?
bool isMethodCompatibleToEvent(object methodTarget, MethodInfo mi,
object eventTarget, EventInfo ei)
{
// HOW ?
}