Re: Events and delegates
From: Sgt. Sausage (nobody_at_nowhere.com)
Date: 09/13/04
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Dispaly Properties"
- Previous message: Thom Little: "Dispaly Properties"
- In reply to: mdb: "Re: Events and delegates"
- Next in thread: Sgt. Sausage: "Re: Events and delegates"
- Reply: Sgt. Sausage: "Re: Events and delegates"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 13 Sep 2004 14:15:21 -0400
"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xns95638D9FB17DBmbrayctiusacom@207.46.248.16...
> Jon Skeet [C# MVP] <skeet@pobox.com> wrote in
> news:MPG.1bafe8cc7b18d3ce98b3ef@msnews.microsoft.com:
>
> > You can't in all cases. In some cases it's relatively straightforward.
> > If the event has been defined in C# as:
> >
> > public event Foo;
>
> Assuming that the event is formed in a normal manner, though, you can
> access the Method and Target parameters of the event delegates...
>
> public event Event_Handler evt;
> Delegate[] delArray = evt.GetInvocationList();
> for(int i=0; i<delArray.Length; i++)
> {
> Delegate ev = delArray[i];
> Trace.WriteLine(ev.Method);
> Trace.WriteLine(ev.Target);
> }
Thanks, but that doesn't get it either.
Given evt.GetInvocationList() -- how does one do this
dynamically, at runtime. You knew, at compile time, that
it's "evt". I don't know this.
I know there's an event named "evt" -- I got that via the
Reflection mentioned in my original post. How do I,
at run time, do something like:
this.("evt").GetInvocationList
or, more to my question:
EventInfo[] events = this.GetType().GetEvents( BindingFlags.Instance |
BindingFlags.Public |
BindingFlags.NonPublic );
for (int i = 0; i < events.Length; i++)
{
// This is the line (below)
this.(events[i].Name).GetInvocationList //wrong!!
// how do I get the InvocationList, knowing that I've got the name
// of the event in events[i].Name ???
}
- Next message: Nicholas Paldino [.NET/C# MVP]: "Re: Dispaly Properties"
- Previous message: Thom Little: "Dispaly Properties"
- In reply to: mdb: "Re: Events and delegates"
- Next in thread: Sgt. Sausage: "Re: Events and delegates"
- Reply: Sgt. Sausage: "Re: Events and delegates"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|