System.Reflection.Emit.ILGenerator.EmitCall Method

Puts a call or callvirt instruction onto the Microsoft intermediate language (MSIL) stream to call a varargs method.

Syntax

public virtual void EmitCall (OpCode opcode, System.Reflection.MethodInfo methodInfo, Type[] optionalParameterTypes)

Parameters

opcode
The MSIL instruction to be emitted onto the stream. Must be OpCodes.Call, OpCodes.Callvirt, or OpCodes.Newobj.
methodInfo
The varargs method to be called.
optionalParameterTypes
The types of the optional arguments if the method is a varargs method; otherwise, null.

Remarks

The ILGenerator.EmitCall(OpCode, System.Reflection.MethodInfo, Type[]) method is used to emit calls to varargs methods because there is no overload of the erload:System.Reflection.Emit.ILGenerator.Emit method that specifies the parameter types of the variable arguments.

To emit calls to methods that do not use the System.Reflection.CallingConventions.VarArgs calling convention, use the ILGenerator.Emit(OpCode, System.Reflection.MethodInfo) method overload.

Version Information

Beginning with the .NET Framework version 2.0, the ILGenerator.EmitCall(OpCode, System.Reflection.MethodInfo, Type[]) method does not throw an exception when optional parameter types are specified for a method that is not varargs. InvalidProgramException is thrown when the call is executed.

Requirements

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0