Override setter and getter property

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; }

...

public class CustomAttibute : Attribute
{
    public override NotExistingPropertySetter(object value)
    {    
        if (((int)value) < 10 )
        {
            value = 10;
        }
    }
}
+1
source share
2 answers

No. The attribute is never executed. You will need to build a construct that looks for the attribute and does something if it finds one.

AoP (aspect-oriented programming) in .NET is only possible using third-party software such as PostSharp.

+3
source

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

+1
source

Source: https://habr.com/ru/post/1527879/


All Articles