0

我正在尝试读取包含多个相同类型的属性的方法的所有属性,例如:

[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

1 回答 1

4

使用GetCustomAttributes而不是 GetCustomAttribute :)

例如:

Attribute[] attributes = Attribute.GetCustomAttributes
              (methodInfo, typeof (fieldAttribute), false);
于 2012-09-14T08:21:49.990 回答