Ben,
Do you have an example of how to do this this, or know where I can find one?
using System;
using System.Reflection;
delegate void FooEventHandler();
class Events
{
public event FooEventHandler Foo;
}
class Test
{
static void Handler1() { Console.WriteLine( "Handler1" ); }
static void Handler2() { Console.WriteLine( "Handler2" ); }
static void Main()
{
Events e = new Events();
e.Foo += new FooEventHandler(Handler1);
e.Foo += new FooEventHandler(Handler2);
Delegate d = (Delegate)e.GetType().GetField("Foo",
BindingFlags.NonPublic|BindingFlags.Instance).GetV alue(e);
foreach ( FooEventHandler f in d.GetInvocationList() )
f();
}
}
Now this assumes that the underlying delegate field is named the same
as the event (Foo in this case). That's not always true, and there's
no way to get the field name from the event name. There may not even
be a single underlying delegate field for each event.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
Please reply only to the newsgroup.