有没有办法覆盖的汽车属性的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.
上一篇:如何使用ICLRStrongName :: StrongNameSignatureVerificationEx方法来确定延迟签名的程序集方法来、如何使用、程序、StrongNameSignatureV