I need to know that how to check any event handler already assigned ? (in QuickWatch)
I'm not sure if I understood the question correctly, but I will give it a shot:
How to check if any event handlers attached to an event TestEvent
:
TestEvent
will be null if no event handlers attached.
If one handler attached (single-cast delegate) _invocationList == 0
:
Paste the following to the QuickWatch expression string:
((System.Reflection.RuntimeMethodInfo)(((System.Delegate)(TestEvent))._methodBase)).Name
to find out what event handler is attached.
If more than one handler attached (multicast delegate) _invocationList > 0
:
You need to look through _invocationList
, for example to check first attached method:
((System.Reflection.RuntimeMethodInfo)(((System.Delegate)(((object[])(((System.MulticastDelegate)(TestEvent))._invocationList))[0]))._methodBase)).Name
To check other attached handlers: change index to 1, 2, etc or just expand each element of the _invocationList
array.
Alternatively to using Name
property which is just a handler method name, you can use m_toString
field which is method signature.
In all the examples about replace TestEvent
with the name of your event.
[Edit] Didn't realize you are using WPF. WPF event system is much more complicated.
Let's say you have a button and what to check if any handler is attached to MouseLeftButtonDown
event:
button1
).UIElement
. Or to get there quickly paste this ((System.Windows.UIElement)(button1)).EventHandlersStore
to the expression input.EventHandlersStore
._entries
._mapStore
.[MS.Utility....]
_entry0
, _entry1
, ... _entry_n
. Each of those are all the events that the button has handlers assigned too.Value
=> _listStore
._entry0
, _entry1
... again. Those are all the handlers attached to this particular event.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With