Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DynamicMethod.GetILGenerator Method (Int32)

Returns a Microsoft intermediate language (MSIL) generator for the method with the specified MSIL stream size.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public ILGenerator GetILGenerator(
	int streamSize
)

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.

NoteNote

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.
Type[] writeStringArgs = {typeof(string)};
// Get the overload of Console.WriteLine that has one
// String parameter.
MethodInfo writeString = typeof(Console).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, null);
// 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

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

Show:
© 2018 Microsoft