title: How do I distinguish between two methods with the same name and number of parameters in a generic class?
body: <p>Here's my class:</p>
  
  <pre><code>public class MyClass&lt;T&gt;
  {
      public void MyMethod(T a)
      {
      }
  
      public void MyMethod(int a)
      {
      }
  }
  </code></pre>
  
  <p>How would I <code>Invoke</code> <code>MyMethod(T)</code> using <code>Reflection</code> even if <code>int</code> is the generic type parameter for <code>MyClass</code>?</p>
  
  <p>Here's a single statement that does it (Might be inefficient, but I like brevity):</p>
  
  <pre><code>var mc = new MyClass&lt;int&gt;();
  
  typeof(MyClass&lt;int&gt;).GetMethods().ElementAt(
      typeof(MyClass&lt;int&gt;).
      GetGenericTypeDefinition().
      GetMethods().ToList().FindIndex(m =&gt;
          m.Name.Equals("MyMethod") &amp;&amp; 
          m.GetParameters().Count() == 1 &amp;&amp;
          m.GetParameters()[0].ParameterType.IsGenericParameter)
      ).Invoke(mc, new object[] { 1 });
  </code></pre>