title: Type inference for (ignoring) method parameters in order to select a MethodInfo
body: <p>We are creating a configuration API for some of our internal projects. The API is replacing an attribute-based configuration. The new API involves specifying methods within a class along with the options that go with it.</p>
  
  <pre><code>public static class Configuration&lt;T&gt; {
      public static void ForMethod(Expression&lt;Action&lt;T&gt;&gt; methodExpression, Options options) { //Option-1
           MethodInfo method = GetMethod(methodExpression);
           // do something with options
      }
  
      public static void ForMethod&lt;TResult&gt;(Expression&lt;Func&lt;T,TResult&gt;&gt; methodExpression, Options options) { //Option-2
           MethodInfo method = GetMethod(methodExpression);
           // do something with options
     }
  
     private static MethodInfo GetMethod(Expression expression) {
         // there's other checks done, but this is what it boils down to
         var methodCall = (MethodCallExpression) expression.Body;
         return methodCall.Method;
     }
  }
  
  class MyClass {
     void MyMethod() { ... }
  }
  
  Configuration&lt;MyClass&gt;.ForMethod(x =&gt; x.MyMethod(), ... );
  </code></pre>
  
  <p>This is great except for when the methods themselves have parameters. IE</p>
  
  <pre><code>class MyClass2 {
     void MyMethod2(int x) { }
     int SomeOtherMethod(int x) { return x*x; }
  }
  </code></pre>
  
  <p>These can be handled by expanding the configuration class like:</p>
  
  <pre><code>public static void ForMethod&lt;TResult, TIn&gt;(Expression&lt;Func&lt;T,TIn,TResult&gt;&gt; methodExpression, ...) { //Option-3
  }
  // and then called: 
  Configuation&lt;MyClass2&gt;.ForMethod&lt;int,int&gt;((x,y) =&gt; x.SomeOtherMethod(y), ...);
  </code></pre>
  
  <p>As more parameters get added it becomes a bit more clumsy. Technically we don't care about the parameters themselves, so long as we select the correct method. We <em>could</em> get around this by simply specifying everything as Option-1 (since we can also ignore the return type and specify everything as Actions) and just specifying the parameters using the <code>default</code> keyword, ie:</p>
  
  <p><code>Configuration&lt;MyClass2&gt;.ForMethod(x =&gt; x.SomeOtherMethod(default(int)), ...)</code></p>
  
  <p>However, this gets quite ugly.</p>
  
  <p><strong>Is there any way with type inference (or some other magic) to select the appropriate method without needing to explicitly state the parameter types?</strong> My hope would be something like this (although this do not work)</p>
  
  <p><code>Configuration&lt;MyClass2&gt;.ForMethod((x,y) =&gt; x.SomeOtherMethod(y), ...) // Option 3 with return type and type of input inferred</code></p>
  
  <p>or even </p>
  
  <p><code>Configuration&lt;MyClass2&gt;.ForMethod((x,y) =&gt; x.SomeOtherMethod, ...) // Option 3 with return type and input 1 inferred + as method group</code></p>
  
  <p>My gut tells me that this is not possible as I haven't been able to find any way around this online. My hope is that perhaps with a combination of extension methods and type inference this <em>could</em> be made possible, but I'm having difficulty finding anything that compiles. Is this even possible? </p>