在基类中实现 INotifyPropertyChanged 或类似的自定义事件
有没有办法做到这一点:
我需要开发最简单的方法来支持注册某些类的属性更改。除了手动添加 INotifyProperyChanged 支持之外,还有一种方法可以这样做:
class Base ... // all notification logic here
class Child
{
public string Name { get; set; }
public int SomeNumber { get; set; }
// etc....
}
这样我就可以执行 Child.PropertyChanged += some_handler 并仅在 Child 属性更改时收到通知。 这不适用于 NHibernate 或其他任何东西,它是供整个项目中手动使用的。我研究了一些使用 Castle Dynamic Proxy 执行此操作的示例(例如 这里),但我不明白如何利用它:(
当然想探索一般的框架和 AOP,我只是现在没有足够的时间......
谢谢如有任何意见请提前...
Is there a way to do this:
I need to develop the easiest way to support registering to property changes of some class. Apart from manual way of adding INotifyProperyChanged support, is there a way to do it like this:
class Base ... // all notification logic here
class Child
{
public string Name { get; set; }
public int SomeNumber { get; set; }
// etc....
}
so that I can do Child.PropertyChanged += some_handler and be notified only on Child property changes.
This isn't for NHibernate, or anything else, it is for manual use in entire project. I have looked into some examples of doing this with Castle Dynamic Proxy (like here), but I don't understand how to exploit it :(
Sure would like to explore there frameworks and AOP in general, I just don't have enuogh time right now ...
Thank you in advance for any comments...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代理或 AOP 确实是自动执行此操作的唯一选择,因此您需要找时间进行调查或执行好的老式方法。
Proxies or AOP really are your only options for doing this automagically, so you will need to either find the time to investigate or do it the good old-fashioned way.