繁体   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