我如何找到一个事件的方法 [英] How can I find the method that is for an event

查看:162
本文介绍了我如何找到一个事件的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共事件UnloadHandler卸载; 
public delegate void UnloadHandler();

然后在程序中有调用Unload(),当我点击F12看到它的实现再次跳到那个事件声明。那么如何找到这个Unload()方法的真实体?

解决方案

卸载不是一种方法,它是一个事件 - 它



当事件发生时,附加的任何处理程序将依次执行。您可以通过 Delegate.GetInvocationList ,但你不能神奇地跳到实现代码。



可以通过搜索源代码来查找事件处理程序附加的地方,语法为 Unload + = / * something * / 这将告诉您事件发生时计划运行的内容。


In a C# source there is something like this:

public event UnloadHandler Unload;
public delegate void UnloadHandler();

then in the program there are calls to Unload() , when I hit F12 to see the implementation it again jump to that event declaration. So how can I find the real body of this Unload() method?

解决方案

Unload is not a method, it's an event -- it does not have a "real body".

When the event is raised, any handlers attached to it will be executed in turn. You can get the list of attached handlers from code inside the class through Delegate.GetInvocationList, but you cannot magically jump to the implementing code.

What you can do is find the places where event handlers are attached with the syntax Unload += /* something */ by searching the source; this will tell you exactly what is scheduled to run when the event is raised.

这篇关于我如何找到一个事件的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆