DynamicMethod::GetILGenerator Method (Int32)
.NET Framework (current version)
Returns a Microsoft intermediate language (MSIL) generator for the method with the specified MSIL stream size.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- streamSize
-
Type:
System::Int32
The size of the MSIL stream, in bytes.
Return Value
Type: System.Reflection.Emit::ILGenerator^An ILGenerator object for the method, with the specified MSIL stream size.
After a dynamic method has been completed, by calling the CreateDelegate or Invoke method, any further attempt to add MSIL is ignored. No exception is thrown.
Note |
|---|
There are restrictions on unverifiable code in dynamic methods, even in some full-trust scenarios. See the "Verification" section in Remarks for DynamicMethod. |
The following code example demonstrates this method overload. This code example is part of a larger example provided for the DynamicMethod class.
// Create an array that specifies the parameter types of the // overload of Console::WriteLine to be used in Hello. array<Type^>^ writeStringArgs = { String::typeid }; // Get the overload of Console::WriteLine that has one // String parameter. MethodInfo^ writeString = Console::typeid->GetMethod("WriteLine", writeStringArgs); // Get an ILGenerator and emit a body for the dynamic method, // using a stream size larger than the IL that will be // emitted. ILGenerator^ il = hello->GetILGenerator(256); // Load the first argument, which is a string, onto the stack. il->Emit(OpCodes::Ldarg_0); // Call the overload of Console::WriteLine that prints a string. il->EmitCall(OpCodes::Call, writeString, nullptr); // The Hello method returns the value of the second argument; // to do this, load the onto the stack and return. il->Emit(OpCodes::Ldarg_1); il->Emit(OpCodes::Ret);
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Show:
