簡體   English   中英

在C#中使用反射讀取所有methode屬性

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM