OpCodes.Ldfld 字段

定义

查找对象中其引用当前位于计算堆栈的字段的值。Finds the value of a field in the object whose reference is currently on the evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Ldfld;
public static readonly System.Reflection.Emit.OpCode Ldfld;
 staticval mutable Ldfld : System.Reflection.Emit.OpCode
Public Shared ReadOnly Ldfld As OpCode 

字段值

注解

下表列出了指令的十六进制和 Microsoft 中间语言(MSIL)程序集格式以及简短的参考摘要:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

格式Format 程序集格式Assembly Format 说明Description
7B < T >7B < T > ldfld fieldldfld field 将指定对象中的字段的值推送到堆栈上。Pushes the value of a field in a specified object onto the stack.

堆栈转换行为顺序如下:The stack transitional behavior, in sequential order, is:

  1. 对象引用(或指针)被推送到堆栈上。An object reference (or pointer) is pushed onto the stack.

  2. 从堆栈中弹出对象引用(或指针);找到对象中指定字段的值。The object reference (or pointer) is popped from the stack; the value of the specified field in the object is found.

  3. 存储在字段中的值将被推送到堆栈上。The value stored in the field is pushed onto the stack.

@No__t-0 指令将位于对象中的字段的值推送到堆栈上。The ldfld instruction pushes the value of a field located in an object onto the stack. 对象必须位于堆栈上以作为对象引用(类型为 O)、托管指针(类型 &)、非托管指针(类型 native int)、暂时性指针(类型 *)或值类型的实例。The object must be on the stack as an object reference (type O), a managed pointer (type &), an unmanaged pointer (type native int), a transient pointer (type *), or an instance of a value type. 可验证代码中不允许使用非托管指针。The use of an unmanaged pointer is not permitted in verifiable code. 对象的字段由必须引用字段成员的元数据标记指定。The object's field is specified by a metadata token that must refer to a field member. 返回类型与字段关联的类型相同。The return type is the same as the one associated with the field. 字段可以是实例字段(在这种情况下,对象不得为空引用)或静态字段。The field may be either an instance field (in which case the object must not be a null reference) or a static field.

@No__t-0 指令前面可以是 Unaligned 和/或 @no__t 前缀。The ldfld instruction can be preceded by either or both of the Unaligned and Volatile prefixes.

如果对象为 null,并且该字段不是静态的,则会引发 NullReferenceExceptionNullReferenceException is thrown if the object is null and the field is not static.

如果在元数据中找不到指定的字段,则会引发 MissingFieldExceptionMissingFieldException is thrown if the specified field is not found in the metadata. 当 Microsoft 中间语言(MSIL)指令转换为本机代码而不是在运行时,通常会检查此情况。This is typically checked when Microsoft Intermediate Language (MSIL) instructions are converted to native code, not at run time.

以下 @no__t 0 方法重载可以使用 @no__t 操作码:The following Emit method overload can use the ldfld opcode:

  • ILGenerator (OpCode,FieldInfo)ILGenerator.Emit(OpCode, FieldInfo)

适用于