Override property setter and getter

前端 未结 2 1914
谎友^
谎友^ 2020-12-20 07:35

Is there a way to override the setter and getter of an auto property with an attribute?

like this:

[CustomAttribute]
public int Value { get; set; }
<         


        
相关标签:
2条回答
  • 2020-12-20 07:48

    No. An attribute is never "executed". You would need to build a construct looking for the attribute and doing something if it's found.

    AoP (aspect oriented programming) in .NET is only possible by using third party software like PostSharp.

    0 讨论(0)
  • 2020-12-20 07:55

    I believe it will achieve this with AOP enter image description here

    0 讨论(0)
提交回复
热议问题