Re: Events and delegates

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sgt. Sausage (nobody_at_nowhere.com)
Date: 09/13/04


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 ???

   }



Relevant Pages

  • Re: Any problems with massive loop unrolling on 8088?
    ... >> looking into just generating the raw REP MOVS and REP STOS. ... > generated, `xchg cx,ax` is one byte. ... > at compile time, then limited unrolling makes sense. ... please re-read my original post -- I don't think you understand what I ...
    (comp.lang.asm.x86)
  • Re: Variable division, assignment and sprintf in one line
    ... at compile time and you'll only do a single division each ... Oh, and furthermore, if you happened to read my original post, I had ... asked how to perform what you state above, WITHOUT needing the left hand ...
    (perl.beginners)