Firing an event / function on a property? (C#)

后端 未结 8 1472
你的背包
你的背包 2021-02-08 11:46

I am using a class that I cannot edit, it has a property (a boolean) of which it would be nice to be informed when it changes, I can\'t edit the properties get or set as I am im

8条回答
  •  你的背包
    2021-02-08 12:28

    As previously mentioned, the most direct method (and that which requires the least change to code) is to use an AOP library such as PostSharp.

    However, a solution can be achieved using traditional C#/.NET by using the dependency property pattern, used throughtout WPF to great effect. I suggest to read up on this, and consider implementing such a system (or at least a simplified version of it) for your project, if appropiate.

提交回复
热议问题