P
Paul Welter
I'm trying to get a method using Type.GetMethod. There are two methods with
that same name, one is a standard method, the other is a Generic method.
How do I get the Generic method? Is there a BindingFlag that will only get
the Generic one? Here is an example ...
[TestClass()]
public class UserTest
{
public ArrayList GetCollection()
{ return new ArrayList(); }
public List<T> GetCollection<T>()
{ return new List<T>(); }
[TestMethod()]
public void GetCollectionTest()
{
Type genType = typeof(UserTest);
MethodInfo info = genType.GetMethod("GetCollection");
MethodInfo genInfo = info.MakeGenericMethod(typeof(User));
object obj = genInfo.Invoke(this, null);
List<User> users = obj as List<User>;
}
}
If I run this code, I get an AmbiguousMatchException. If I remove the first
GetCollection, it works. Any ideas?
thanks
~ Paul
that same name, one is a standard method, the other is a Generic method.
How do I get the Generic method? Is there a BindingFlag that will only get
the Generic one? Here is an example ...
[TestClass()]
public class UserTest
{
public ArrayList GetCollection()
{ return new ArrayList(); }
public List<T> GetCollection<T>()
{ return new List<T>(); }
[TestMethod()]
public void GetCollectionTest()
{
Type genType = typeof(UserTest);
MethodInfo info = genType.GetMethod("GetCollection");
MethodInfo genInfo = info.MakeGenericMethod(typeof(User));
object obj = genInfo.Invoke(this, null);
List<User> users = obj as List<User>;
}
}
If I run this code, I get an AmbiguousMatchException. If I remove the first
GetCollection, it works. Any ideas?
thanks
~ Paul