2012-09-14 37 views
0

我想讀一下包含相同類型的多個屬性像梅索德的所有屬性:閱讀在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。我如何閱讀多個屬性?

謝謝

回答

4

使用GetCustomAttributes代替GetCustomAttribute :)

例如:

Attribute[] attributes = Attribute.GetCustomAttributes 
       (methodInfo, typeof (fieldAttribute), false); 
+0

喔人,我的GoTa是盲目的!我甚至找不到複數形式的相同方法名稱。謝謝 – CloudyMarble