Dynamic Event raising. How?

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.
 
T

Tiberiu Covaci

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top