How to check event handler assigned or not in QuickWatch
I need to know that how to check any ev开发者_StackOverflow社区ent 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:TestEventwill 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)).Nameto 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)).NameTo check other attached handlers: change index to 1, 2, etc or just expand each element of the
_invocationListarray.
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:
- Open QuickWhatch.
- Paste you button variable name (let's say
button1). - Drill down through the bases classes till you got to the
UIElement. Or to get there quickly paste this((System.Windows.UIElement)(button1)).EventHandlersStoreto the expression input. - Locate and expand property
EventHandlersStore. - Expand
_entries. - Expand
_mapStore. - Expand
[MS.Utility....] - You will see the list of
_entry0,_entry1, ..._entry_n. Each of those are all the events that the button has handlers assigned too. - To find out what handlers are assigned to, drill further to particular entry
Value=>_listStore. - You will see the list of
_entry0,_entry1... again. Those are all the handlers attached to this particular event.

加载中,请稍侯......
精彩评论