Provides access to the metadata and MSIL for the body of a method.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|ExceptionHandlingClauses||Gets a list that includes all the exception-handling clauses in the method body.|
|InitLocals||Gets a value indicating whether local variables in the method body are initialized to the default values for their types.|
|LocalSignatureMetadataToken||Gets a metadata token for the signature that describes the local variables for the method in metadata.|
|LocalVariables||Gets the list of local variables declared in the method body.|
|MaxStackSize||Gets the maximum number of items on the operand stack when the method is executing.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetILAsByteArray||Returns the MSIL for the method body, as an array of bytes.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
The 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.
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.
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 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.
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.