Ive得到了这个自定义属性:访问自定义属性的值
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited = true)]
class MethodTestingAttibute : Attribute
{
public string Value{ get; private set; }
public MethodTestingAttibute (string value)
{
this.Value= value;
}
}
要这样来使用:
[MethodTestingAttibute("2")]
public int m1() {return 3; }
而我做太困难是采取的“2”的价值MethodTestingAttibute
object result = method.Invoke(obj, new Type[] {}); // here i get the return
现在我想比较这个结果与方法TestingAttibute的值。我该怎么做?我试着往上走这条路,但没有成功:method.GetCustomAttributes(typeof运算(MethodTestAttibute),真)[0] ...
什么是正确获得访问Custoum领域属性?
我很困惑。你说“3”的意思是“2”吗? –
我的意思是2!对不起 – RCPT
非常接近:[any-know-a-quick-way-to-get-to-custom-attributes-on-an-enum-value](http://stackoverflow.com/questions/17772/anyone-know -a-快速的方式对获得到自定义属性上-AN-枚举值) – nawfal