Export (0) Print
Expand All

MethodBase.GetMethodBody Method

When overridden in a derived class, gets a MethodBody object that provides access to the MSIL stream, local variables, and exceptions for the current method.

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

[<ReflectionPermissionAttribute(SecurityAction.Demand, Flags = ReflectionPermissionFlag.MemberAccess)>]
abstract GetMethodBody : unit -> MethodBody 
[<ReflectionPermissionAttribute(SecurityAction.Demand, Flags = ReflectionPermissionFlag.MemberAccess)>]
override GetMethodBody : unit -> MethodBody

Return Value

Type: System.Reflection.MethodBody
A MethodBody object that provides access to the MSIL stream, local variables, and exceptions for the current method.

ExceptionCondition
InvalidOperationException

This method is invalid unless overridden in a derived class.

You do not have to override the GetMethodBody in order to use it. You can call the GetMethodBody method on MethodInfo and ConstructorInfo objects, because the method is overridden in the runtime versions of these classes. For example, the runtime version of the MethodInfo class derives from the MethodInfo class, which in turn derives from the MethodBase class.

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 LocalVariables property is used to obtain a list of LocalVariableInfo objects and display their types and index order. The ExceptionHandlingClauses property is used to obtain a list of exception-handling clauses.

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft