Is there a way to intercept setters and getters in C#?

前端 未结 11 1230
旧时难觅i
旧时难觅i 2021-01-03 18:15

In both Ruby and PHP (and I guess other languages as well) there are some utility methods that are called whenever a property is set. ( *instance_variable_set*

11条回答
  •  抹茶落季
    2021-01-03 19:20

    Not out of the box. You would need to insert code into each properties setter and getter, either manually or automatically using IL rewriting.

    When you want to do it manually, you can't use automatic properties any more.
    When you want to do it automatically, have a look at AOP.

提交回复
热议问题