我注意到有兩種方法(一類方法和一種擴展方法)具有相同簽名但不同的返回類型在包的System.Reflection類的MemberInfo:MemberInfo.GetCustomAttributes擴展超載
類方法:
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);' – NtFreX
如果你給我們更多的上下文會有幫助 - 這個CustomAttributeExtensions類在哪裏? –
這是參考https://msdn.microsoft.com/zh-cn/library/hh138301(v=vs.110).aspx – Andrea