Mike see code using reflections I put up... It does just this.

On 2/14/07, Mike Andrews <[EMAIL PROTECTED]> wrote:
Yep, can't agree more.
For this case it's just for testing and debugging.

I'm not interested in the Add/Remove handlers for the Event either.  I just
want the Delegate instances which belong to the CheckBox.CheckedChangedevent.

Since an instanced Delegate has a GetInvocationList() method, this is what I
would like to get.

Or a way to solve my previous problem.

Thanks,
Mike


On 2/14/07, Mike Woodring <[EMAIL PROTECTED]> wrote:
>
> Be advised:
>
> (1) That only works when the calling assembly(ies) have sufficient CAS
> permissions that allows reflection against non-public members; and
>
> (2) The class in question actually (a) does not provide a custom
> add/remove
> handler and (b) is implemented using a language like C# that creates a
> private field named after the event (in VB.NET, for example, the event
> member named "Foo" will result in a private field named "FooEvent").
>
> -Mike
> Bear Canyon Consulting LLC
> http://www.bearcanyon.com
> http://www.pluralsight.com/mike
>
>
> > -----Original Message-----
> > From: Discussion of advanced .NET topics.
> > [mailto:[EMAIL PROTECTED] On Behalf Of
> > gregory young
> > Sent: Wednesday, February 14, 2007 1:45 PM
> > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> > Subject: Re: [ADVANCED-DOTNET] Determining if an event has
> > been assigned a delegate...
> >
> > Here is a version that works from outside of the class ...
> >
> >
> >         static void PrintListenners(object o, string _EventName)
> >         {
> >             Type t = o.GetType();
> >             FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic |
> > BindingFlags.Instance);
> >             foreach (FieldInfo f in fields)
> >             {
> >                 Console.WriteLine(f.Name + " " +
> > f.ReflectedType.ToString());
> >             }
> >             FieldInfo fi = t.GetField(_EventName,
> > BindingFlags.NonPublic | BindingFlags.Instance);
> >             Delegate del = (Delegate)fi.GetValue(o);
> >             foreach (Delegate d in del.GetInvocationList())
> >             {
> >                 Console.WriteLine("Method Name: {0}", d.Method);
> >                 Console.WriteLine("Type Name: {0}", d.Target);
> >             }
> >         }
> >
> >
> > Cheers,
> >
> > Greg
> >
> >
> >
> > On 2/14/07, Zaman, Tanweer <[EMAIL PROTECTED]> wrote:
> > > You would assign this AddHandler delegate to CheckChanged
> > event in you Initialize method
> > >
> > > - Tanweer
> > >
> > > -----Original Message-----
> > > From: Discussion of advanced .NET topics.
> > [mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews
> > > Sent: Wednesday, February 14, 2007 2:52 PM
> > > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> > > Subject: [ADVANCED-DOTNET] Determining if an event has been
> > assigned a delegate...
> > >
> > > Guys,
> > >
> > > Do any of you know if it's possible to determine if an
> > event for an object has been assigned a delegate?
> > >
> > > Example:
> > >
> > > Dim cb As New CheckBox()
> > > cb.Name = "MyCheckBox"
> > > AddHandler(cb.CheckChanged, AddressOf CheckChanged)
> > >
> > > ...
> > >
> > > Public Sub CheckChanged(Object sender, EventArgs e) ...
> > > End Sub
> > >
> > > Is it possible to know if cb.CheckChanged has been assigned
> > a handler or not?
> > >
> > > Thanks,
> > > Mike
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor(r)  http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> > >
> > >
> > ==============================================================
> > ================
> > > Please access the attached hyperlink for an important
> > electronic communications disclaimer:
> > >
> > > http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> > >
> > ==============================================================
> > ================
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor(r)  http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> > >
> >
> >
> > --
> > Studying for the Turing test
> >
> > ===================================
> > This list is hosted by DevelopMentorR  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



--
Studying for the Turing test

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to