views:

110

answers:

1

Hi again, now i have a more theorical question related with events and reflection. The question is: "Is or isn't possible to get the field of type delegate associated with an event via EventInfo?"

Basically when you define an event (implicitly), the compiler adds a private delegate field to your class (the delegate is of the same type of the delegate associated with the event you just declared, obviously). Is it possible to get that field via reflection, more specifically, via EventInfo?

And when you define an event explicitally?

Thanks in advance. cheers ;)

A: 
myEvent.GetType().GetGenericArguments()[0]

But make sure myTest isn't null before calling it. If you'd like to use the EventInfo:

typeof (Program).GetEvent("myTest").EventHandlerType.GetGenericArguments()[0]

or did you want the delegate type?

typeof (Program).GetEvent("myTest").EventHandlerType
Yuriy Faktorovich
Your answer is good, but i was asking if we can use any method of class EventInfo to retrieve the delegate field associated with the event.
Bruno
Or do you mean not the type, but a pointer to each of the delegates that have been added to the event?
Yuriy Faktorovich