리플렉션으로 이벤트 핸들러를 설정하고 싶습니다. 모든 유형을 얻을 수는 있지만 얻을 수는 없습니다.형식 및 템플릿 인수로 반사에 의한 이벤트 처리기 설정
public delegate void MyHandler<T>(IMyInterface<T> pParam);
public interface IMyInterface<T>
{
MyHandler<T> EventFired { get; set; }
}
void myFunction()
{
//admit vMyObject is IMyInterface<ClassA>
var vMyObject = vObj as IMyInterface<ClassA>;
//get the generic type => ClassA
var vTypeGeneric = vTypeReturn.GenericTypeArguments.FirstOrDefault();
//build the type handler for the event MyHandler<ClassA>
Type vAsyncOP = typeof(MyHandler<>).MakeGenericType(vTypeGeneric);
// here I don't know how to create the Event handler to set EventFired
// dynamically with the code inside
var vEventFired = vMyObject.GetType().GetProperty("EventFired");
vEventFired.SetMethod etc...
}
람다/표현식을 사용하여 일부 코드를 발견했지만이 경우이 코드를 사용하는 방법을 모르겠습니다.
용액으로부터를, 그것은 일반을 그리워하지만 아래의 솔루션을 게시 할 수 있습니다. 도와 줘서 고마워. – Poppyto