How to get invocation list for an event.

P

Peter Rilling

How can I get access to the invocation list for a multicast delegate (i.e.
an event) at runtime?

Suppose that I have a reference to a class that has an event. I would like
to be able to enumerate through the list of registered handlers. I can see
that a MulticastDelegate has the GetInvocationList method, but I cannot seem
to find a way to it. This would need to be done using reflection because I
want to be able to access this list from outside the class that contains the
event.
 
J

Jay B. Harlow [MVP - Outlook]

Peter,
| How can I get access to the invocation list for a multicast delegate (i.e.
| an event) at runtime?
Remember that an Event encapsulates a Delegate field, similar to how a
Property encapsulates other fields.

For a given event, you are going to have to know what its underlying field
is. The "problem" is going to be that an underlying field may not actually
be used, instead all the delegates may be stored in an EventHandlerList,
which is exposed via Component.Events property.

http://msdn.microsoft.com/library/d...emcomponentmodelcomponentclasseventstopic.asp

http://msdn.microsoft.com/library/d...mComponentModelEventHandlerListClassTopic.asp

Of course the use of Component.Events & EventHandlerList is completely
optional... So you may need to know on a type by type, along with event by
event, basis, how its underlying delegate is being stored...


| This would need to be done using reflection because I
| want to be able to access this list from outside the class that contains
the
| event.
Generally spelunking into the implementation details of a class is "bad
form" as the implementation details may change between releases of a
product...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| How can I get access to the invocation list for a multicast delegate (i.e.
| an event) at runtime?
|
| Suppose that I have a reference to a class that has an event. I would
like
| to be able to enumerate through the list of registered handlers. I can
see
| that a MulticastDelegate has the GetInvocationList method, but I cannot
seem
| to find a way to it. This would need to be done using reflection because
I
| want to be able to access this list from outside the class that contains
the
| event.
|
|
 

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