Possible Duplicates:
How to use reflection to call generic Method?
Select Right Generic Method with Reflection
Hi there
Let's say I have two following two methods in a class:
public void MyMethod(object val) {}
public void MyMethod<T>(T val) {}
With reflection, I could get the first Method like this:
Type[] typeArray = new Type[1];
typeArray.SetValue(typeof(object), 1);
var myMethod = myInstance.GetType().GetMethod("MyMethod", typeArray);
But how can I get the second, generic method?
I would do it like this:
We're looking for a method called "MyMethod" that is a generic method with a single type-parameter having no constraints, and one 'normal' parameter of the same type as the type-parameter.
Obviously, if you're not looking to be very precise, you can just do the bare minimum to disambiguate, such as: