MemberInfo.GetCustomAttrbutes由两个overload version: public abstract object[] GetCustomAttributes(bool inherit); public abstract object[] GetCustomAttributes(Type attrtype, bool inherit);调用必须加上参数(比如true, false...)。 而且返回值也不是Attribute[],而是object[]。所以: foreach(object o in ...) { Attribute attr = o as Attribute; ... ... }
public abstract object[] GetCustomAttributes(bool inherit);
public abstract object[] GetCustomAttributes(Type attrtype, bool inherit);调用必须加上参数(比如true, false...)。
而且返回值也不是Attribute[],而是object[]。所以:
foreach(object o in ...) {
Attribute attr = o as Attribute;
... ...
}