我应该使用某种库或编写一些代码(或使用其他方式)来检查在任意对象上调用事件的顺序吗?
我的目标是编写这样的代码:
var ei = new EventInterceptor(_someInstance);
ei.EventFired += (s,e) => { Logger.Log("{0} fired {1}", s.ToString(), e.ToString(); }
我认为我可以用反射逻辑编写它,但如果有东西存在,我宁愿使用它。 (我认为)这对于研究 ado.net 和 winforms datagridview 等复杂对象非常有用......
My goal is to write code like this:
var ei = new EventInterceptor(_someInstance);
ei.EventFired += (s,e) => { Logger.Log("{0} fired {1}", s.ToString(), e.ToString(); }
I think I can write this up in reflection logic, but if there's something out there I'd rather use it. This would be incredibly useful (i think) for studying complicated objects like in ado.net and the winforms datagridview...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
davidbakin @ CodeProject 提供了基于反射的事件跟踪器:
跟踪由任何 C# 对象引发的事件
替代方案:如果您的平台是 Vista 或 Windows 7,您可以尝试 Windows 事件跟踪 (ETW),尽管学习曲线似乎有点陡峭。
此外,在 相关问题的答案。
A Reflection-based event tracer is available from davidbakin @ CodeProject:
Tracing Events Raised by Any C# Object
Alternatives: if your platform is Vista or Windows 7, you might try Event Tracing for Windows (ETW), though it seems like the learning curve is a bit steep.
Also, a suggestion for an event logger class (probably something similar to the Code Project article) was given in the answer to a related question.