title: IL code to call method with out parameter
body: <p>I want to IL generate a dynamic method</p>
  
  <pre><code>delegate ArraySegment&lt;byte&gt; X(MyClass mc);
  </code></pre>
  
  <p>that calls a method of the signature on <code>mc</code> and returns its <code>out</code> parameter.</p>
  
  <pre><code>MethodInfo methInf = aClass.GetMethod("Y",
      BindingFlags.Public | BindingFlags.Instance, 
      null, new[] { typeof(ArraySegment&lt;byte&gt;).MakeByRefType() }, null);
  </code></pre>
  
  <p>but I don't know how to handle the out parameter. Here's the code I have so far.</p>
  
  <pre><code>DynamicMethod dm = new DynamicMethod("X", typeof(ArraySegment&lt;byte&gt;),
                                       new[] { typeof(MyClass) });
  ILGenerator il = dm.GetILGenerator();
  
  il.Emit(OpCodes.Ldarg_0);
  il.EmitCall(OpCodes.Callvirt, methInf, null);
  </code></pre>
  
  <p>What's needed to make the out param work?</p>