Dynamic Event raising. How?

  • Thread starter Thread starter Tiberiu Covaci
  • Start date Start date
T

Tiberiu Covaci

Hi all,

I'm trying to be "smart" and have some kind of dynamic event invocation. I
have differfent events, all of them raised by my application. Because I do
not want to wait for some answers I call BeginInvoke and send EndInvoke as a
parameter for my callback method.

Now. What I want to do I something similar, but using reflection. Instead of
having a switch based on the event name I would like to use EventInfo from
System.Reflection. Everithing works fine, if I useInvoke Method, but how
sould I do this for async call?

Thanks
Tibi.
 
A code snippet will be the following

class T : EventArgs{
....
}
class MyClass {
public event EventHandler<T> Evt1;
public event EventHandler<T> Evt2;
private OnEvt1(){
if(Evt1 != null)
Evt1(this, new T());
}
private OnEvt2(){
if(Evt2 != null)
Evt2(this, new T());
}
}

What I want to achieve is

class .... {

.....
OnSomeEvent(string eventName){
EventInfo evtInf = this.GetType().GetEvent(eventName);
// and here to invoke the method....
}


How do I do that?
 
Back
Top