how to find event handlers of given event using reflection

  • Thread starter Grzegorz Danowski
  • Start date
G

Grzegorz Danowski

Hello,

I'd like to hide control if any of its event handlers is forbidden for
current user (basing on PrincipalPermissionAttribute). How to list all
methods that handle given event?
I supposed that I should use reflection and I examined EventInfo class but I
haven't found in this class any information about handlers list, but there
is a possibility to add one (AddEventHandler method).
 
B

Ben Voigt

Grzegorz Danowski said:
Hello,

I'd like to hide control if any of its event handlers is forbidden for
current user (basing on PrincipalPermissionAttribute). How to list all
methods that handle given event?
Who wrote the control? In general you have to access the backing member
variable (delegate type) which holds the list of handlers.

If it is a standard .NET control, then probably you can read the value of
Control.Events (it's protected so use reflection), which contains an
EventHandlerList.

I suggest you use .NET Reflector and look at the source code for the add and
remove handlers of the event you're interested in.
 
G

Grzegorz Danowski

Ben Voigt said:
....
If it is a standard .NET control, then probably you can read the value of
Control.Events (it's protected so use reflection), which contains an
EventHandlerList.

Thanks, I will try it.
Grzegorz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top