How would it be possible to remove all event handlers of the 'Click' event of a 'Button'?

.net, c#, event-handling, events

Solution

You can't, basically - at least not without reflection and a lot of grubbiness.

Events are strictly "subscribe, unsubscribe" - you can't unsubscribe someone else's handler, any more than you can change someone else's reference to an object.

Problem

I have a button control, and I'd need to remove all the event handlers attached to its Click event. How would that be possible? ``` Button button = GetButton(); button.Click.RemoveAllEventHandlers(); ```

Original source

Related problems