覆盖属性setter和getter [英] Override property setter and getter
本文介绍了覆盖属性setter和getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法覆盖的汽车属性的setter和getter和一个属性?
是这样的:
[CustomAttribute]
公共int值{获得;组; }
...
公共类CustomAttibute:属性
{
公众覆盖NotExistingPropertySetter(对象的值)
{
如果(((int)的值)小于10)
{
值= 10;
}
}
}
解决方案
没有。从不执行的属性。您将需要建立一个结构寻找属性,做的东西,如果它的发现。
AOP(面向方面编程)在.NET中只能使用第三方软件,如PostSharp。
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;
}
}
}
解决方案
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.
这篇关于覆盖属性setter和getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文