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