我有這個小問題,我無法弄清楚哪些參數傳遞給Type.GetMethod以獲取非泛型類型的泛型方法的MethodInfo。 具體來說,我有這種類型的定義:如何獲取非泛型.NET類型的泛型方法的MethodInfo?
public static class A
{
public static B F<T>(bool dummy)
{
}
public static B F<T>(IEnumerable<T> arg)
{
...
}
}
我嘗試了好幾種在Type.GetMethod需要,但沒有將返回在F方法的MethodInfo。
我知道我可以調用Type.GetMethods或Type.FindMember,但我對Type.GetMethod感興趣。
任何想法?
謝謝。
編輯
其實,我的代碼是一個比較複雜的。泛型方法被重載,所以我不能只使用函數名稱來使用Type.GetMethod。 我想這些變種:
typeof(A).GetMethod("F", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
typeof(A).GetMethod("F`1", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
typeof(A).GetMethod("F[T]", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
typeof(A).GetMethod("F[[T]]", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
請發佈您嘗試過的代碼。 – 2009-10-26 13:36:23
更改了我的問題。謝謝。 – mark 2009-10-26 13:48:12
@Mark我改變了我的答案。 – 2009-10-26 14:13:56