开发者

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:

  1. How to check if any event handlers attached to an event TestEvent:

    TestEvent will be null if no event handlers attached.

  2. 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.

  3. 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:

  1. Open QuickWhatch.
  2. Paste you button variable name (let's say button1).
  3. Drill down through the bases classes till you got to the UIElement. Or to get there quickly paste this ((System.Windows.UIElement)(button1)).EventHandlersStore to the expression input.
  4. Locate and expand property EventHandlersStore.
  5. Expand _entries.
  6. Expand _mapStore.
  7. Expand [MS.Utility....]
  8. You will see the list of _entry0, _entry1, ... _entry_n. Each of those are all the events that the button has handlers assigned too.
  9. To find out what handlers are assigned to, drill further to particular entry Value => _listStore.
  10. You will see the list of _entry0, _entry1 ... again. Those are all the handlers attached to this particular event.

How to check event handler assigned or not in QuickWatch

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜