ILGenerator.EmitCalli Méthode

Définition

Place une instruction Calli sur le flux msIL (Microsoft intermediate language).

Surcharges

Nom Description
EmitCalli(OpCode, CallingConvention, Type, Type[])

Place une instruction Calli sur le flux msIL (Microsoft intermediate language), en spécifiant une convention d’appel non managée pour l’appel indirect.

EmitCalli(OpCode, CallingConventions, Type, Type[], Type[])

Place une instruction Calli sur le flux msIL (Microsoft intermediate language), en spécifiant une convention d’appel managée pour l’appel indirect.

EmitCalli(OpCode, CallingConvention, Type, Type[])

Place une instruction Calli sur le flux msIL (Microsoft intermediate language), en spécifiant une convention d’appel non managée pour l’appel indirect.

public:
 void EmitCalli(System::Reflection::Emit::OpCode opcode, System::Runtime::InteropServices::CallingConvention unmanagedCallConv, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public:
 virtual void EmitCalli(System::Reflection::Emit::OpCode opcode, System::Runtime::InteropServices::CallingConvention unmanagedCallConv, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public void EmitCalli(System.Reflection.Emit.OpCode opcode, System.Runtime.InteropServices.CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes);
public virtual void EmitCalli(System.Reflection.Emit.OpCode opcode, System.Runtime.InteropServices.CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes);
member this.EmitCalli : System.Reflection.Emit.OpCode * System.Runtime.InteropServices.CallingConvention * Type * Type[] -> unit
abstract member EmitCalli : System.Reflection.Emit.OpCode * System.Runtime.InteropServices.CallingConvention * Type * Type[] -> unit
override this.EmitCalli : System.Reflection.Emit.OpCode * System.Runtime.InteropServices.CallingConvention * Type * Type[] -> unit
Public Sub EmitCalli (opcode As OpCode, unmanagedCallConv As CallingConvention, returnType As Type, parameterTypes As Type())
Public Overridable Sub EmitCalli (opcode As OpCode, unmanagedCallConv As CallingConvention, returnType As Type, parameterTypes As Type())

Paramètres

opcode
OpCode

Instruction MSIL à émettre sur le flux. Doit être Calli.

unmanagedCallConv
CallingConvention

Convention d’appel non managée à utiliser.

returnType
Type

Résultat Type .

parameterTypes
Type[]

Types des arguments requis pour l’instruction.

Exemples

L’exemple de code suivant illustre l’utilisation contextuelle de la EmitCalli méthode pour appeler une méthode de type non managée externe à la classe dynamique.

MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("MyMethod",
                  MethodAttributes.Public,
                  returnType, mthdParamTypes);
                            
// We will assume that an external unmanaged type "LegacyNumber" has been loaded, and
// that it has a method "ToString" which returns a string.

MethodInfo unmanagedMthdMI = Type.GetType("LegacyNumber").GetMethod("ToString");
ILGenerator myMthdIL = myMthdBuilder.GetILGenerator();

// Code to emit various IL opcodes here ...

// Load a reference to the specific object instance onto the stack.

myMthdIL.Emit(OpCodes.Ldc_I4, addrOfLegacyNumberObject);
myMthdIL.Emit(OpCodes.Ldobj, Type.GetType("LegacyNumber"));

// Make the call to the unmanaged type method, telling it that the method is
// the member of a specific instance, to expect a string
// as a return value, and that there are no explicit parameters.
myMthdIL.EmitCalli(OpCodes.Calli,
           System.Runtime.InteropServices.CallingConvention.ThisCall,
               typeof(string),
           new Type[] {});

// More IL code emission here ...
    Dim myMthdBuilder As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod", _
                    MethodAttributes.Public, _
                    returnType, mthdParamTypes)
  
    ' We will assume that an external unmanaged type "LegacyNumber" has been loaded, and
    ' that it has a method "ToString" which returns a string.

    Dim unmanagedMthdMI As MethodInfo = Type.GetType("LegacyNumber").GetMethod("ToString")
    Dim myMthdIL As ILGenerator = myMthdBuilder.GetILGenerator()
  
    ' Code to emit various IL opcodes here ...
    ' Load a reference to the specific object instance onto the stack.

    myMthdIL.Emit(OpCodes.Ldc_I4, addrOfLegacyNumberObject)
    myMthdIL.Emit(OpCodes.Ldobj, Type.GetType("LegacyNumber"))
  
    ' Make the call to the unmanaged type method, telling it that the method is
    ' the member of a specific instance, to expect a string 
    ' as a return value, and that there are no explicit parameters.

    myMthdIL.EmitCalli(OpCodes.Calli, System.Runtime.InteropServices.CallingConvention.ThisCall, _
                  GetType(String), New Type() {})

' More IL code emission here ...

Remarques

Permet EmitCalli de placer une Calli instruction dans le flux. N’utilisez pas Emit.

S’applique à

EmitCalli(OpCode, CallingConventions, Type, Type[], Type[])

Place une instruction Calli sur le flux msIL (Microsoft intermediate language), en spécifiant une convention d’appel managée pour l’appel indirect.

public:
 void EmitCalli(System::Reflection::Emit::OpCode opcode, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, cli::array <Type ^> ^ optionalParameterTypes);
public:
 virtual void EmitCalli(System::Reflection::Emit::OpCode opcode, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, cli::array <Type ^> ^ optionalParameterTypes);
public void EmitCalli(System.Reflection.Emit.OpCode opcode, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes);
public virtual void EmitCalli(System.Reflection.Emit.OpCode opcode, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes);
member this.EmitCalli : System.Reflection.Emit.OpCode * System.Reflection.CallingConventions * Type * Type[] * Type[] -> unit
abstract member EmitCalli : System.Reflection.Emit.OpCode * System.Reflection.CallingConventions * Type * Type[] * Type[] -> unit
override this.EmitCalli : System.Reflection.Emit.OpCode * System.Reflection.CallingConventions * Type * Type[] * Type[] -> unit
Public Sub EmitCalli (opcode As OpCode, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type(), optionalParameterTypes As Type())
Public Overridable Sub EmitCalli (opcode As OpCode, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type(), optionalParameterTypes As Type())

Paramètres

opcode
OpCode

Instruction MSIL à émettre sur le flux. Doit être Calli.

callingConvention
CallingConventions

Convention d’appel managée à utiliser.

returnType
Type

Résultat Type .

parameterTypes
Type[]

Types des arguments requis pour l’instruction.

optionalParameterTypes
Type[]

Types des arguments facultatifs pour varargs les appels.

Exceptions

optionalParameterTypes n’est pas null, mais callingConvention n’inclut pas l’indicateur VarArgs .

Remarques

Permet EmitCalli de placer une Calli instruction dans le flux. N’utilisez pas Emit.

Si optionalParameterTypes vous spécifiez des arguments facultatifs, callingConvention vous devez inclure l’indicateur CallingConventions.VarArgs .

S’applique à