【发布时间】:2017-07-07 07:45:05
【问题描述】:
我注意到类 MemberInfo 的 System.Reflection 包中有两个方法(一个类方法和一个扩展方法)具有相同的签名但返回类型不同:
类方法:
public abstract object[] GetCustomAttributes(Type attributeType, bool inherit)
扩展方法(在CustomAttributeExtensions内):
public static IEnumerable<Attribute> GetCustomAttributes(this MemberInfo element, Type attributeType, bool inherit)
我知道用这样的参数调用那个方法总是会调用类方法,所以我只是想知道:
如何调用扩展方法?
最重要的是,定义与类方法具有相同签名的扩展的目的是什么?
【问题讨论】:
-
您可以将其称为静态方法。
CustomAttributeExtensions.GetCustomAttributes(element, attribute, inherit); -
如果你能给我们更多的背景信息会有所帮助 - 这个
CustomAttributeExtensions类在哪里?
标签: c#