CreateMethodBody Method

MethodBuilder.CreateMethodBody Method (Byte[], Int32)

 

Creates the body of the method using a supplied byte array of Microsoft intermediate language (MSIL) instructions.

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

member CreateMethodBody : 
        il:byte[] *
        count:int -> unit

Parameters

il
Type: System.Byte[]

An array containing valid MSIL instructions. If this parameter is null, the method's body is cleared.

count
Type: System.Int32

The number of valid bytes in the MSIL array. This value is ignored if MSIL is null.

Exception Condition
ArgumentOutOfRangeException

The count is not within the range of indexes of the supplied MSIL instruction array and il is not null.

InvalidOperationException

The containing type was previously created using CreateType.

-or-

This method was called previously on this MethodBuilder with an il argument that was not null.

-or-

For the current method, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

This method creates the method's body from il, an array containing MSIL instructions as opcodes. The number of bytes of valid MSIL is given by count.

System_CAPS_noteNote

This is currently not fully supported. The user cannot supply the location of token fix ups and exception handlers.

In the example provided below, a simple method that adds two integers is generated via opcode using CreateMethodBody.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Return to top
Show:
© 2016 Microsoft