在基类中实现 INotifyPropertyChanged 或类似的自定义事件

发布于 2024-08-06 08:39:12 字数 644 浏览 3 评论 0原文

有没有办法做到这一点:

我需要开发最简单的方法来支持注册某些类的属性更改。除了手动添加 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2024-08-13 08:39:12

代理或 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文