简体   繁体   English

通过反射获取事件订阅

[英]Get Event Subscriptions with Reflection

I'm trying to loop through all event subscriptions for an object that : INotifyPropertyChanged This is as far as I can get: 我试图遍历一个对象的所有事件订阅: INotifyPropertyChanged这是我所能得到的:

EventInfo e1 = typeof(INotifyPropertyChanged).GetEvent("PropertyChanged",
   BindingFlags.Instance | BindingFlags.Public);

Now how would I go about getting all subscriptions to that event for a given INotifyPropertyChanged object? 现在,我将如何获取给定INotifyPropertyChanged对象对该事件的所有订阅?

Thanks! 谢谢!

There isn't any simple way to create a generic solution for this since you have no way of knowing what the backing store for any given event might be. 没有任何简单的方法可以为此创建通用解决方案,因为您无法知道任何给定事件的后备存储。 While attempting to infer the backing store is possible, it's not exactly a robust or low-cost solution. 虽然可以推断出后备存储,但它并非完全可靠或低成本的解决方案。 If you could share your end goal, it might be possible to suggest a more easily managed approach. 如果您可以分享自己的最终目标,则可能会建议一种更易于管理的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM