![](/img/trans.png)
[英]How to get all attributes and attributes data of a method using reflection in C#
[英]Read all methode attributes using reflection in C#
我正在尝试读取方法的所有属性,该方法包含多个相同类型的属性,例如:
[field(Feld = "x86", Index = 1)]
[field(Feld = "x93", Index = 2)]
...
[field(Feld = "x107", Index = 9)]
public string Methodename() {}
读取属性如下:
Attribute mAttr = Attribute.GetCustomAttribute
(methodInfo, typeof (fieldAttribute), false) as fieldAttribute;
这抛出一个AmbiguousMatchException 。 我如何阅读多个属性?
谢谢
使用GetCustomAttributes代替GetCustomAttribute :)
例如:
Attribute[] attributes = Attribute.GetCustomAttributes
(methodInfo, typeof (fieldAttribute), false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.