OpCodes.Callvirt Campo

Definición

Llama a un método enlazado tardíamente en un objeto e inserta el valor devuelto en la pila de evaluación.Calls a late-bound method on an object, pushing the return value onto the evaluation stack.

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

Valor de campo

OpCode

Comentarios

En la tabla siguiente se muestra el formato de ensamblado hexadecimal de la instrucción y del lenguaje intermedio de Microsoft (MSIL), junto con un breve resumen de referencia:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

FormatoFormat Formato de ensambladoAssembly Format DescripciónDescription
6F < T >6F < T > callvirt methodcallvirt method Llama a un método específico asociado a obj .Calls a specific method associated with obj.

El comportamiento de transición de la pila, en orden secuencial, es el siguiente:The stack transitional behavior, in sequential order, is:

  1. objSe inserta una referencia de objeto en la pila.An object reference obj is pushed onto the stack.

  2. Los argumentos arg1 de método a través argN se insertan en la pila.Method arguments arg1 through argN are pushed onto the stack.

  3. Los argumentos arg1 de método a través de argN y la referencia obj de objeto se extraen de la pila; la llamada al método se realiza con estos argumentos y el control se transfiere al método en al obj que hace referencia el token de metadatos del método.Method arguments arg1 through argN and the object reference obj are popped from the stack; the method call is performed with these arguments and control is transferred to the method in obj referred to by the method metadata token. Cuando se completa, el método de destinatario genera un valor devuelto y se envía al autor de la llamada.When complete, a return value is generated by the callee method and sent to the caller.

  4. El valor devuelto se inserta en la pila.The return value is pushed onto the stack.

La callvirt instrucción llama a un método enlazado en tiempo de ejecución en un objeto.The callvirt instruction calls a late-bound method on an object. Es decir, el método se elige en función del tipo en tiempo de ejecución de, obj en lugar de la clase en tiempo de compilación visible en el puntero de método.That is, the method is chosen based on the runtime type of obj rather than the compile-time class visible in the method pointer. Callvirt se puede usar para llamar a métodos virtuales y de instancia.Callvirt can be used to call both virtual and instance methods. La callvirt instrucción puede estar inmediatamente precedida por un tail Tailcall prefijo () para especificar que el marco de pila actual debe liberarse antes de transferir el control.The callvirt instruction may be immediately preceded by a tail (Tailcall) prefix to specify that the current stack frame should be released before transferring control. Si la llamada transfiere el control a un método de mayor confianza que el método original, no se liberará el marco de pila.If the call would transfer control to a method of higher trust than the original method the stack frame will not be released.

El token de metadatos del método proporciona el nombre, la clase y la firma del método al que se va a llamar.The method metadata token provides the name, class and signature of the method to call. La clase asociada a obj es la clase de la que es una instancia de.The class associated with obj is the class of which it is an instance. Si la clase define un método no estático que coincide con el nombre de método y la firma indicados, se llama a este método.If the class defines a non-static method that matches the indicated method name and signature, this method is called. De lo contrario, todas las clases de la cadena de clase base de esta clase se comprueban en orden.Otherwise all classes in the base class chain of this class are checked in order. Es un error si no se encuentra ningún método.It is an error if no method is found.

Callvirt extrae el objeto y los argumentos asociados de la pila de evaluación antes de llamar al método.Callvirt pops the object and the associated arguments off the evaluation stack before calling the method. Si el método tiene un valor devuelto, se inserta en la pila cuando se completa el método.If the method has a return value, it is pushed on the stack upon method completion. En el lado del destinatario, obj se tiene acceso al parámetro como argumento 0, arg1 como argumento 1, etc.On the callee side, the obj parameter is accessed as argument 0, arg1 as argument 1, and so on.

Los argumentos se colocan en la pila en orden de izquierda a derecha.The arguments are placed on the stack in left-to-right order. Es decir, el primer argumento se calcula y se coloca en la pila, después el segundo argumento, el tercero, hasta que todos los argumentos necesarios se encuentran sobre la pila en orden descendente.That is, the first argument is computed and placed on the stack, then the second argument, then the third, until all necessary arguments are atop the stack in descending order. La referencia de la instancia obj (siempre necesaria para callvirt ) debe insertarse antes que cualquiera de los argumentos visibles para el usuario.The instance reference obj (always required for callvirt) must be pushed before any of the user-visible arguments. La firma (llevada en el token de metadatos) no necesita contener una entrada en la lista de parámetros para el puntero this.The signature (carried in the metadata token) need not contain an entry in the parameter list for the this pointer.

Tenga en cuenta que también se puede llamar a un método virtual mediante la Call instrucción.Note that a virtual method can also be called using the Call instruction.

MissingMethodException se produce si no se encuentra un método no estático con el nombre y la signatura indicados en la clase asociada a obj o a cualquiera de sus clases base.MissingMethodException is thrown if a non-static method with the indicated name and signature could not be found in the class associated with obj or any of its base classes. Normalmente, esto se detecta cuando las instrucciones del lenguaje intermedio de Microsoft (MSIL) se convierten en código nativo, en lugar de en tiempo de ejecución.This is typically detected when Microsoft Intermediate Language (MSIL) instructions are converted to native code, rather than at runtime.

NullReferenceException se produce si obj es NULL.NullReferenceException is thrown if obj is null.

SecurityException se produce si la seguridad del sistema no concede al llamador acceso al método llamado.SecurityException is thrown if system security does not grant the caller access to the called method. La comprobación de seguridad puede producirse cuando el CIL se convierte en código nativo en lugar de en tiempo de ejecución.The security check may occur when the CIL is converted to native code rather than at run time.

Nota

Al llamar a métodos de System. Object en tipos de valor, considere la posibilidad de usar el constrained prefijo con la callvirt instrucción.When calling methods of System.Object on value types, consider using the constrained prefix with the callvirt instruction. Esto elimina la necesidad de emitir diferentes IL dependiendo de si el tipo de valor invalida el método, evitando un posible problema de control de versiones.This removes the need to emit different IL depending on whether or not the value type overrides the method, avoiding a potential versioning problem. Considere la posibilidad de usar el constrained prefijo al invocar métodos de interfaz en tipos de valor, ya que el método de tipo de valor que implementa el método de interfaz se puede cambiar mediante MethodImpl .Consider using the constrained prefix when invoking interface methods on value types, since the value type method implementing the interface method can be changed using a MethodImpl. Estos problemas se describen con más detalle en el Constrained código de operación.These issues are described in more detail in the Constrained opcode.

La siguiente Emit sobrecarga del método puede utilizar el callvirt código de operación:The following Emit method overload can use the callvirt opcode:

Se aplica a