Windows apps
Collapse the table of content
Expand the table of content
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
public ILGenerator GetILGenerator (
	int streamSize
public function GetILGenerator (
	streamSize : int
) : ILGenerator
Not applicable.



The size of the MSIL stream, in bytes.

Return Value

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.

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", 

// 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.
// 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.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

© 2017 Microsoft