title: Expression.GetDelegateType and generic methods
body: <p>I need to create delegates with Reflection out of methods such as the following:</p>
  
  <pre><code>public void Serialize&lt;TElement&gt;(IList&lt;TElement&gt; value)
  {
  }
  </code></pre>
  
  <p>These methods have in common that they return <code>Void</code> and have one parameter with <strong>one</strong> generic argument. The parameter type doesn't specifically have to be <code>IList&lt;T&gt;</code>. I can't resolve <code>TElement</code> until before the delegate's invocation.</p>
  
  <p>Using the following method raises an exception:</p>
  
  <pre><code>static Delegate CreateOpenDelegate(MethodInfo method, object target)
  {
      var args = new List&lt;Type&gt;(method.GetParameters()
          .Select(param =&gt; param.ParameterType));
      args.Add(method.ReturnType);
      var delegateType = Expression.GetDelegateType(args.ToArray());
      return Delegate.CreateDelegate(delegateType, target, method);
  }
  </code></pre>
  
  <p>Is there a viable alternative to creating the delegate in runtime, just before its execution (once <code>TElement</code> becomes known and <code>MakeGenericMethod</code> can be called on the method)?</p>