C# 跟踪对象的所有事件触发
作者:作者不详  发布日期:2011-06-16 22:03:42
C# 跟踪对象的所有事件触发


The events of any object can be traced, by use of a single class, through the use of .NET Reflection.

Have you tried to understand the patterns of raised events of a complicated object? I needed to work with a very capable, very full-featured grid control from a ISV’s popular control collection. It wasn’t very long before I was very puzzled trying to figure out which of the many events provided by the control were the ones I wanted, and in which order they were raised. I started to write individual event handlers for the events I was interested in, but there were so many I thought I’d be better off generating tracing event handlers for all the events using a nice editor macro. But it turned out there were over 260 events for this grid control, and they were declared at various levels of the class hierarchy. I looked for a better way.

.NET Reflection turned out to be a very easy way to get access to the definition of the class I was interested in—or any other class for that matter. It is a simple process to get all the events that a class declares, and then to attach handlers to any or all of the events.

This article presents the simple-but-general event hooking/tracing class I built, which is provided (with a demo) as a download.



(注:ISV=Independent Software Vendors 的英文缩写,意为“独立软件开发商”)

我非常困难的尝试从控件的事件列表中找出我想要的事件及触发顺序,在此之前我并没有花费很长时间. 我开始编写个别的感兴趣的事件处理程序, 也有很多我使用宏编辑器生成的跟踪事件处理程序. 但事实证明,此表格控件有超过260个事件,并且它们在不同的类层级内定义,我想寻找更好的方法。





点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇