有没有办法用属性覆盖自动属性的 setter 和 getter?
像这样:
[CustomAttribute]
public int Value { get; set; }
...
public class CustomAttibute : Attribute
{
public override NotExistingPropertySetter(object value)
{
if (((int)value) < 10 )
{
value = 10;
}
}
}
最佳答案
没有。属性永远不会“执行”。您将需要构建一个构造来查找属性并在找到时执行某些操作。
.NET 中的 AoP(面向方面的编程)只能通过使用 PostSharp 等第三方软件实现。
关于c# - 覆盖属性 setter 和 getter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21733428/