除了数据绑定之外,.NET Framework 中是否使用 INotifyPropertyChanging / Changed?
如果你有一个 BindingList
If you have a BindingList<Person> for example and you bind it to a control, if your Person class doesn't implement INotfiyPropertyChanging / Changed, your changes to the underlying List won't show up in your control automatically. My question is, are there any other uses for these interfaces as far as the framework is concerned? I'm not talking about using these interfaces to implement your own actions based on these events, I'm talking about in the .NET Framework itself, is there ever another need to implement these interfaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能 100% 自信地说,但由于您没有任何其他答案,而且我自己也很感兴趣,所以我刚刚启动了 Reflector 并检查了哪些类依赖于 INotifyPropertyChanged,简短的答案似乎是:不,它并没有真正用于其他任何用途。
查看这些类,一些非数据绑定引用是:
System.Configuration.ApplicationSettingsBase - 因此,如果您决定实现自己的应用程序设置提供程序,那么它应该公开 INPC 功能。 因此,它在 DataBinding 之外的某个领域使用,但范围非常狭窄。
System.Printing.PrintTicket 还实现了 INPC。 我没有通过 .NET 进行大量打印,因此这可能很重要,也可能不重要。 我真的不能说。
因此,为了更全面地回答这个问题:如果您不是数据绑定,我怀疑您会发现让您的类实现 INotifyPropertyChanged 有任何好处,有一些边缘情况,该接口在 DataBinding 上下文之外使用,但是如果您如果您在这些领域工作过,您很快就会发现这一点。
I can't speak with 100% confidence, but since you didn't have any other answers and I was interested myself I've just fired up Reflector and checked which classes have a dependency on INotifyPropertyChanged, and the short answer appears to be: No, it isn't really used for anything else.
Looking through the classes, some of the non-databinding references are:
System.Configuration.ApplicationSettingsBase - so if you decide to implement your own provider for application settings then it should expose INPC functionality. So there is one area where it is used outside of DataBinding, but a very narrow niche.
System.Printing.PrintTicket also implements INPC. I haven't done a great deal of printing through .NET, so this may be important, it may not. I really couldn't say.
So, to answer the question more fully: If you aren't databinding I doubt you'll find any benefit to making your classes implement INotifyPropertyChanged, there are a few edge cases where the interface is used outside of a DataBinding context, but if you were working in those areas you'll quickly find that out for yourself.