ILGenerator.Emit Method (OpCode, MethodInfo)

May 11, 2014

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the metadata token for the given method.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public virtual void Emit(
	OpCode opcode,
	MethodInfo meth


Type: System.Reflection.Emit.OpCode
The MSIL instruction to be emitted onto the stream.
Type: System.Reflection.MethodInfo
A method that is the target of opcode.


meth is null.


meth is a generic method for which the MethodBase.IsGenericMethodDefinition property is false.

The instruction values are defined in the OpCodes enumeration.

The location of meth is recorded so that the instruction stream can be patched if necessary when persisting the module to a portable executable (PE) file.

If meth represents a generic method, it must be a generic method definition. That is, its MethodBase.IsGenericMethodDefinition property must be true.

The following example demonstrates the use of Emit method overloads to emit an instruction that requires a FieldInfo and an instruction that requires a MethodInfo. The first instruction loads an object from a static field (Shared field in Visual Basic), and the second instruction calls the get accessor for a property of the object.

This code is part of a larger example provided for the BeginExceptionBlock method.

adderIL.Emit(OpCodes.Ldsfld, demoOutput);
adderIL.Emit(OpCodes.Callvirt, getter);

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

© 2014 Microsoft