Emit Method (OpCode, FieldInfo)

ILGenerator.Emit Method (OpCode, FieldInfo)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Puts the specified instruction and metadata token for the specified field onto the Microsoft intermediate language (MSIL) stream of instructions.

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

public virtual void Emit(
	OpCode opcode,
	FieldInfo field


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

The instruction values are defined in the OpCodes enumeration.

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

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

© 2017 Microsoft