lundi 26 janvier 2015

GetMethod with generic overrload [duplicate]


This question already has an answer here:




I have a class with two methods, overloaded with identical name and arguments, but one is generic:



public class Foo
{
public string Bar(string s) { throw new NotImplementedException(); }
public T Bar<T>(string s) { throw new NotImplementedException(); }
}


How can I get the MethodInfo for one of these methods? e.g:



var fooType = typeof(Foo);
var methodInfo = fooType.GetMethod("Bar", new[] { typeof(string) }); // <-- [System.Reflection.AmbiguousMatchException: Ambiguous match found.]


.NET Fiddle here






Aucun commentaire:

Enregistrer un commentaire