title: dynamic delegate to pass a method as parameter in C#
body: <p>Is there any way to use DLR to reference a method in C#?</p>
  
  <p>In dynamic languages like JavaScript or Python I could easily pass a method as an argument to another method. In C# being statically typed language, I either use <code>Delegate</code> type which needs lots of casting:</p>
  
  <pre><code>public static void AddMethod(Delegate del)
  {
      // implementation
  }
  </code></pre>
  
  <p>and then use casting whenever I call this method</p>
  
  <pre><code>static void Main(string[] args)
  {
      AddMethod(new Func&lt;object, bool&gt;(Test));
  }
  
  public static bool Test(object obj)
  {
      return true;
  }
  </code></pre>
  
  <p>Or, I need to define dozens of overloads to satisfy any method calls:</p>
  
  <pre><code>public static void AddMethod&lt;TResult&gt;(Func&lt;TResult&gt; method)
  {
  }
  
  public static void AddMethod&lt;T, TResult&gt;(Func&lt;T, TResult&gt; method)
  {
  }
  
  public static void AddMethod&lt;T1, T2, TResult&gt;(Func&lt;T1, T2, TResult&gt; method)
  {
  }
  
  public static void AddMethod&lt;T1, T2, T3, TResult&gt;(Func&lt;T1, T2, T3, TResult&gt; method)
  {
  }
  </code></pre>
  
  <p>Is there any cleaner way to define an argument as a placeholder for all other methods? (I'm trying to avoid <code>MethodInfo</code> or other <code>Reflection</code> stuff here)</p>
  
  <p>I was trying something like this:</p>
  
  <pre><code>public delegate dynamic DynamicDelegate(params dynamic[] args);
  
  public static void AddMethod(DynamicDelegate method)
  {
  }
  </code></pre>
  
  <p>But the compiler doesn't seem to accept a statically typed method for a dynamically declared delegates!</p>
  
  <p>Any other thoughts?</p>