OpCodes.Ldflda 欄位


尋找物件中的欄位位址,該位址的參考目前位於評估堆疊中。Finds the address of a field in the object whose reference is currently on the evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Ldflda;
public static readonly System.Reflection.Emit.OpCode Ldflda;
 staticval mutable Ldflda : System.Reflection.Emit.OpCode
Public Shared ReadOnly Ldflda 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
7C < T >7C < T > ldflda fieldldflda field 將指定物件中 field 的位址推送至堆疊。Pushes the address of 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 address of the specified field in the object is found.

  3. 指定欄位的位址會推送至堆疊。The address of the specified field is pushed onto the stack.

ldflda 指令會將位於物件中的欄位位址推送至堆疊。The ldflda instruction pushes the address of a field located in an object onto the stack. 物件必須在堆疊上當做物件參考(類型 O)、managed 指標(類型 &)、非受控指標(類型 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.

ldflda 傳回的值是 managed 指標(類型 &),除非物件以非受控指標的形式推送至堆疊,在此情況下,傳回位址也是非受控指標(類型 native int)。The value returned by ldflda is a managed pointer (type &) unless the object is pushed onto the stack as an unmanaged pointer, in which case the return address is also an unmanaged pointer (type native int).

ldflda 指令的前面可以是 UnalignedVolatile 前置詞的其中一個或兩個。The ldflda instruction can be preceded by either or both of the Unaligned and Volatile prefixes.

如果物件不在其存取所在的應用程式域內,則會擲回 InvalidOperationExceptionInvalidOperationException is thrown if the object is not within the application domain from which it is being accessed. 無法載入不在存取應用程式域內的欄位位址。The address of a field that is not inside the accessing application domain cannot be loaded.

如果物件為 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.

下列 Emit 方法多載可以使用 ldflda opcode:The following Emit method overload can use the ldflda opcode:

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