【发布时间】:2012-05-24 10:06:24
【问题描述】:
是否可以在另一个属性的代码中测试一个属性是否存在?
假设你有以下类定义:
public class Inception {
[Required]
[MyTest]
public int Levels { get; set; }
}
public class MyTestAttribute : ValidationAttribute {
public override bool IsValid(object o){
// return whether the property on which this attribute
// is applied also has the RequiredAttribute
}
}
... MyTestAttribute.IsValid 是否可以确定 Inception.Levels 是否具有RequiredAttribute?
【问题讨论】:
-
哦哦!好一个!我猜不是,但这只是一个猜测。
标签: c# reflection custom-attributes