Differentiate generic methods by type parameters only using reflection?

Posted by Brian Vallelunga on Stack Overflow See other posts from Stack Overflow or by Brian Vallelunga
Published on 2014-05-27T15:21:43Z Indexed on 2014/05/27 15:24 UTC
Read the original article Hit count: 263

Filed under:
|
|

I'm trying to use reflection to get a specific MethodInfo of a class, but am unsure how to differentiate between the two following methods:

public class Test
{
    public IBar<T1> Foo<T1>();
    public IBar<T1, T2> Foo<T1, T2>();
}

How can I get a reference to the different Foo methods, assuming I know the number of type parameters? Just calling typeof(Test).GetMethod("Foo") will throw an exception that the method name is ambiguous and there aren't a differing number of parameters to check.

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics