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:
对象引用 (或指针) 被推送到堆栈上。An object reference (or pointer) is pushed onto the stack.
从堆栈中弹出对象引用 (或指针) ;找到对象中指定字段的值。The object reference (or pointer) is popped from the stack; the value of the specified field in the object is found.
存储在字段中的值将被推送到堆栈上。The value stored in the field is pushed onto the stack.
ldfld指令将位于对象中的字段的值推送到堆栈上。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. 该字段可以是实例字段 (在这种情况下,对象不能为 null 引用) 或静态字段。The field may be either an instance field (in which case the object must not be a null reference) or a static field.
ldfld指令前面可以是和/或 Unaligned Volatile 前缀。The ldfld instruction can be preceded by either or both of the Unaligned and Volatile prefixes.
NullReferenceException 如果对象为 null,并且该字段不是静态的,则会引发。NullReferenceException is thrown if the object is null and the field is not static.
MissingFieldException 如果在元数据中找不到指定的字段,则会引发。MissingFieldException 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.
以下 Emit 方法重载可以使用 ldfld 操作码:The following Emit method overload can use the ldfld opcode: