Is it possible to implement Property Changed as Attribute?

为君一笑 提交于 2019-12-01 21:53:16

Check out Fody, and the PropertyChanged add-in. It will modify the IL after compilation to add the code to raise the PropertyChanged event for your properties. It's similar to PostSharp, mentioned in Lasse's answer, but it's free and open-source.

You will need some kind of AOP system to do this.

Either something where you wrap or inherit from your class, and dynamically generate the necessary plumbing in the wrapper/descendant to handle this, or some system like Postsharp that rewrites your code after compilation.

There is nothing built into .NET to handle this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!