ILGenerator.EmitCalli Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream.
EmitCalli(OpCode, CallingConvention, Type, Type[]) |
Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying an unmanaged calling convention for the indirect call. |
EmitCalli(OpCode, CallingConventions, Type, Type[], Type[]) |
Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying a managed calling convention for the indirect call. |
- Source:
- ILGenerator.cs
- Source:
- ILGenerator.cs
- Source:
- ILGenerator.cs
Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying an unmanaged calling convention for the indirect call.
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())
Parameters
- unmanagedCallConv
- CallingConvention
The unmanaged calling convention to be used.
- parameterTypes
- Type[]
The types of the required arguments to the instruction.
Examples
The following code sample demonstrates the contextual usage of the EmitCalli method to call an unmanaged type method external to the dynamic class.
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 ...
Remarks
Use EmitCalli to put a Calli instruction onto the stream. Do not use Emit.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.1 |
- Source:
- ILGenerator.cs
- Source:
- ILGenerator.cs
- Source:
- ILGenerator.cs
Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying a managed calling convention for the indirect call.
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())
Parameters
- callingConvention
- CallingConventions
The managed calling convention to be used.
- parameterTypes
- Type[]
The types of the required arguments to the instruction.
- optionalParameterTypes
- Type[]
The types of the optional arguments for varargs
calls.
Exceptions
optionalParameterTypes
is not null
, but callingConvention
does not include the VarArgs flag.
Remarks
Use EmitCalli to put a Calli instruction onto the stream. Do not use Emit.
If optionalParameterTypes
specifies optional arguments, callingConvention
must include the CallingConventions.VarArgs flag.
Applies to
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: