![](/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.