how to find event handlers of given event using reflection

  • Thread starter Thread starter Grzegorz Danowski
  • Start date 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).
 
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.
 
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
 
Back
Top