【发布时间】:2015-01-26 17:42:50
【问题描述】:
我有一个类有两个方法,重载了相同的名称和参数,但一个是通用的:
public class Foo
{
public string Bar(string s) { throw new NotImplementedException(); }
public T Bar<T>(string s) { throw new NotImplementedException(); }
}
我怎样才能获得这些方法之一的MethodInfo?
例如:
var fooType = typeof(Foo);
var methodInfo = fooType.GetMethod("Bar", new[] { typeof(string) }); // <-- [System.Reflection.AmbiguousMatchException: Ambiguous match found.]
【问题讨论】:
标签: c# .net generics reflection generic-programming