[英]Get MethodInfo for ICollection<T>
我有集合ICollection<T>
,我需要找到方法“Where”。 我怎么能這樣做?
我試過這樣的事情:
System.Type type = typeof(ICollection<T>);
MethodInfo info = type.GetGenericTypeDefinition().GetMethod("Where");
但它不起作用。 我需要它來創建動態表達式
它是一個擴展方法,因此它不在接口本身上,而是在Enumerable
類上:
typeof(Enumerable).GetMethods("Where", BindingFlags.Static | BindingFlags.Public)
然后選擇您需要的過載。
你需要
typeof(ICollection<>);
獲取ICollection<T>
的類型。但是,在ICollection<T>
沒有定義Where
方法。你應該從靜態Enumerable
類中獲取方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.