ILGenerator.EmitCalli 方法

定義

Calli 指令放到 Microsoft Intermediate Language (MSIL) 資料流中。

多載

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

指定間接呼叫的 Unmanaged 呼叫慣例,將 Calli 指令放置到 Microsoft Intermediate Language (MSIL) 資料流中。

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

指定間接呼叫的 Managed 呼叫慣例,將 Calli 指令放置到 Microsoft Intermediate Language (MSIL) 資料流中。

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

來源:
ILGenerator.cs
來源:
ILGenerator.cs
來源:
ILGenerator.cs

指定間接呼叫的 Unmanaged 呼叫慣例,將 Calli 指令放置到 Microsoft Intermediate Language (MSIL) 資料流中。

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

參數

opcode
OpCode

要在資料流中發出的 MSIL 指令。 必須是 Calli

unmanagedCallConv
CallingConvention

要使用的 Unmanaged 呼叫慣例。

returnType
Type

結果的 Type

parameterTypes
Type[]

指令需要的參數型別。

範例

下列程式代碼範例示範方法的內容使用 EmitCalli 方式,以呼叫動態類別外部的 Unmanaged 型別方法。

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,
                     String::typeid,
                     gcnew array<Type^>( 0 ) );

// More IL code emission here ...
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 ...

備註

使用 EmitCalli 將指令放在 Calli 數據流上。 請勿使用 Emit

適用於

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

來源:
ILGenerator.cs
來源:
ILGenerator.cs
來源:
ILGenerator.cs

指定間接呼叫的 Managed 呼叫慣例,將 Calli 指令放置到 Microsoft Intermediate Language (MSIL) 資料流中。

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

參數

opcode
OpCode

要在資料流中發出的 MSIL 指令。 必須是 Calli

callingConvention
CallingConventions

要使用的 Managed 呼叫慣例。

returnType
Type

結果的 Type

parameterTypes
Type[]

指令需要的參數型別。

optionalParameterTypes
Type[]

varargs 呼叫的選擇性參數型別。

例外狀況

optionalParameterTypes 不是 null,但是 callingConvention 沒有包含 VarArgs 旗標。

備註

使用 EmitCalli 將指令放在 Calli 數據流上。 請勿使用 Emit

如果 optionalParameterTypes 指定選擇性自變數, callingConvention 則必須包含 CallingConventions.VarArgs 旗標。

適用於