467,077 Members | 1,028 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

Getting the InvocationList for an event in a different class

I have a class with a DataTable built into it. Various places
subscribe to the DataTable.RowChanging event. I want to grab a list of
all the subscribers.

Normally I'd use GetInvocationList, but that only seems to work on
events that are defined in the same class. Events declared inside a
different class (even one inside the current one) won't let you use
that syntax.

Anyone got any ideas?

Thanks,

Andrew Ducker

Mar 21 '06 #1
  • viewed: 3853
Share:
3 Replies
Dnia 21-03-2006 o 11:37:17 Andrew Ducker <an****@ducker.org.uk> napisał:
I have a class with a DataTable built into it. Various places
subscribe to the DataTable.RowChanging event. I want to grab a list of
all the subscribers.

Normally I'd use GetInvocationList, but that only seems to work on
events that are defined in the same class. Events declared inside a
different class (even one inside the current one) won't let you use
that syntax.

Anyone got any ideas?


[PD] If you really know what you are doing you can use Reflector to check
how looks add method for this event. If it's "standard" event without
custom add method C# compiler generates hidden field and add and remove
methods operating on it, so you can acces this hidden delegate using
reflection and get the invocation list. In other case you must analyze the
custom code to see where the added delegates are stored and also acces it
via reflection.

--
Piotr Dobrowolski
Piotr.Dobrowolski@_usun_gmail.com
Mar 21 '06 #2
Hi,


Normally I'd use GetInvocationList, but that only seems to work on
events that are defined in the same class. Events declared inside a
different class (even one inside the current one) won't let you use
that syntax.

Anyone got any ideas?


A possible workaround is to define the event in your outer class, all the
consumers hook to this event, then only you subscribe to the DataTable'e
event. In this case you can do as you usually do.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 21 '06 #3
Andrew,

You cannot get the invocation list of event in other class. Events are
metadata objects only and they are set of 2 or 3 methods - add, remove and
invoke. How the events are implemented internaly is up to the implementing
classl it might use private field, collection of event handlers
(System.Windows.Forms controls for example) or maybe some other weird
method.

Keep in mind that invication list belongs to the delegate not the event
itself.
--
HTH
Stoitcho Goutsev (100)
"Andrew Ducker" <an****@ducker.org.uk> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...
I have a class with a DataTable built into it. Various places
subscribe to the DataTable.RowChanging event. I want to grab a list of
all the subscribers.

Normally I'd use GetInvocationList, but that only seems to work on
events that are defined in the same class. Events declared inside a
different class (even one inside the current one) won't let you use
that syntax.

Anyone got any ideas?

Thanks,

Andrew Ducker

Mar 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Christopher W. Douglas | last post: by
6 posts views Thread by Charles Law | last post: by
13 posts views Thread by Charles Law | last post: by
5 posts views Thread by Charles Bazi | last post: by
11 posts views Thread by mark | last post: by
33 posts views Thread by JamesB | last post: by
16 posts views Thread by Stefano Sabatini | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.