OpCodes.Isinst 字段


测试对象引用(O 类型)是否为特定类的实例。Tests whether an object reference (type O) is an instance of a particular class.

public: static initonly System::Reflection::Emit::OpCode Isinst;
public static readonly System.Reflection.Emit.OpCode Isinst;
 staticval mutable Isinst : System.Reflection.Emit.OpCode
Public Shared ReadOnly Isinst 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
75 < T >75 < T > isinst classisinst class 测试对象引用是否为 class 的实例,返回空引用或该类或接口的实例。Tests if an object reference is an instance of class, returning either a null reference or an instance of that class or interface.

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

  1. 对象引用被推送到堆栈上。An object reference is pushed onto the stack.

  2. 从堆栈中弹出对象引用并对其进行测试,以查看它是否是传递到 class 的类的实例。The object reference is popped from the stack and tested to see if it is an instance of the class passed in class.

  3. 结果(对象引用或空引用)被推送到堆栈上。The result (either an object reference or a null reference) is pushed onto the stack.

@no__t 为表示所需类的元数据标记。Class is a metadata token indicating the desired class. 如果堆栈顶部对象的类实现 class (如果 @no__t 为接口),或者为 class 的派生类(如果 class 为常规类),则将其强制转换为类型 @no__t,并将结果推送到堆栈上,与调用 Castclass 完全相同。If the class of the object on the top of the stack implements class (if class is an interface) or is a derived class of class (if class is a regular class) then it is cast to type class and the result is pushed on the stack, exactly as though Castclass had been called. 否则,在堆栈上推送空引用。Otherwise, a null reference is pushed on the stack. 如果对象引用本身为空引用,则 isinst 同样返回空引用。If the object reference itself is a null reference, then isinst likewise returns a null reference.

如果找不到类,则会引发 TypeLoadExceptionTypeLoadException is thrown if class cannot be found. 当 Microsoft 中间语言(MSIL)指令转换为本机代码而不是运行时,通常会检测到此情况。This is typically detected when the Microsoft Intermediate Language (MSIL) instructions are converted to native code rather than at runtime.

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

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