MethodBody Class

 

Provides access to the metadata and MSIL for the body of a method.

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

System.Object
  System.Reflection.MethodBody

[<ComVisibleAttribute(true)>]
type MethodBody = class end

NameDescription
System_CAPS_protmethodMethodBody()

Initializes a new instance of the MethodBody class.

NameDescription
System_CAPS_pubpropertyExceptionHandlingClauses

Gets a list that includes all the exception-handling clauses in the method body.

System_CAPS_pubpropertyInitLocals

Gets a value indicating whether local variables in the method body are initialized to the default values for their types.

System_CAPS_pubpropertyLocalSignatureMetadataToken

Gets a metadata token for the signature that describes the local variables for the method in metadata.

System_CAPS_pubpropertyLocalVariables

Gets the list of local variables declared in the method body.

System_CAPS_pubpropertyMaxStackSize

Gets the maximum number of items on the operand stack when the method is executing.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetILAsByteArray()

Returns the MSIL for the method body, as an array of bytes.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

The MethodBody class provides access to information about the local variables and exception-handling clauses in a method body, and to the Microsoft intermediate language (MSIL) that makes up the method body.

You can use the token-resolution methods of the module class, such as ResolveType, ResolveMethod, and ResolveType, to resolve the tokens in the method body to Type objects, MethodInfo objects, and FieldInfo objects that provide detailed information about the types, methods, and fields accessed by the MSIL in the method body.

System_CAPS_noteNote

Parsing method bodies requires a thorough understanding of metadata and MSIL instruction formats. Information can be found in the Common Language Infrastructure (CLI) documentation, especially "Partition II: Metadata Definition and Semantics" and "Partition III: CIL Instruction Set". The documentation is available online; see ECMA C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.

To obtain a MethodBody object for a given method, first obtain a MethodInfo object for the method, then call the MethodInfo object's GetMethodBody method.

The following code example defines a test method named MethodBodyExample and displays its local variable information and exception-handling clauses. The MethodBase.GetMethodBody method is used to obtain a MethodBody object for the test method.

The example uses the LocalVariables property to obtain a list of LocalVariableInfo objects and then displays their types and index order. The ExceptionHandlingClauses property is used to obtain a list of exception-handling clauses.

System_CAPS_noteNote

Not all computer languages can generate ExceptionHandlingClauseOptions.Filter clauses. The Visual Basic example shows a filter clause, using a Visual Basic When expression, which is omitted from the examples for other languages.

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

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: