"BK" <bl*************@rogers.com> wrote in message
news:eG*************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a class which has a lot of events (>100). For some reasons, I have
to go through all invocation lists to do something. What I'm wondering is
that, is there any way to use reflection to get their InvocationList without
going through each event?
Are you aware of the alternate way to declare events?
public event EventHandler Something
{
add {add "value" to some list}
remove {remove "value" from the list}
}
The System.Web.UI.Control class defines its events this way. It also
declares an "Events" property of type EventHandlerList. The EventHandlerList
class defines AddHandler and RemoveHandler methods, and an indexer. These
all take an arbitrary object as a parameter:
private static readonly object SomeEvent = new object();
public event EventHandler Something
{
add
{
Events.AddHandler(SomeEvent, value);
}
remove
{
Events.RemoveHandler(SomeEvent, value);
}
}
protected virtual void OnSomething(EventArgs e)
{
EventHandler someEventDelegate = (EventHandler) Events[SomeEvent];
if (someEventDelegate != null)
someEventDelegate(this, e);
}
Now, it seems to me that you could do something similar, perhaps using a
HashTable instead of an EventHandlerList. You would then be able to iterate
over the hashtable and access each event handler in the loop.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
}