title: Pass Method of Unknown Arguments/Return Type as Parameter in C#
body: <p>There's a similar question here:</p>
  
  <p><a href="https://stackoverflow.com/questions/2082615/pass-method-as-parameter-using-c-sharp">Pass Method as Parameter using C#</a></p>
  
  <p>Which assumes you know the method's arguments and return type. I'd like to do something a bit different. I'm looking to create a version of System.Reflection's .GetMethod(string) that instead takes a lambda function - so instead of:</p>
  
  <pre><code>MethodInfo methodInfo = typeof(MyClass).GetMethod("AddThing");
  </code></pre>
  
  <p>I could use a more compile-safe:</p>
  
  <pre><code>MethodInfo methodInfo = ReflectionHelper.GetMethod&lt;MyClass&gt;(mc =&gt; mc.AddThing);
  </code></pre>
  
  <p>So if ReflectionHelper knew the argument count and return type beforehand the answer would be simple-ish - for example if it had no arguments and returned string:</p>
  
  <pre><code>public static MethodInfo GetMethod&lt;T, TReturn&gt;(Expression&lt;Func&lt;T, Func&lt;TArg, TReturn&gt;&gt;&gt; expr)
  {
      return ((MethodCallExpression)expr.Body).Method;
  }
  </code></pre>
  
  <p>Except that I don't know the argument count/return type beforehand, and I'd like to avoid just spamming it with 20 overloads that cover most but not all cases.</p>
  
  <p>So, how do I do this?</p>