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

GetCustomAttributeの代わりにGetCustomAttributesを使用してください:)

例えば:

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