C# MethodInfo GetMethodBody

Description

MethodInfo GetMethodBody 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.

Syntax

MethodInfo.GetMethodBody has the following syntax.


[ReflectionPermissionAttribute(SecurityAction.Demand, Flags = ReflectionPermissionFlag.MemberAccess)]
public virtual MethodBody GetMethodBody()

Returns

MethodInfo.GetMethodBody method returns A MethodBody object that provides access to the MSIL stream, local variables, and exceptions for the current method.

Example


using System;/*  w  w  w  . j  a  va 2  s  . c  om*/
using System.Reflection;

public class Example
{
    public static void Main()
    {
        MethodInfo mi = typeof(Example).GetMethod("MethodBodyExample");
        MethodBody mb = mi.GetMethodBody();
        Console.WriteLine(mi);

        Console.WriteLine(mb.InitLocals);
        Console.WriteLine(mb.MaxStackSize);
    }
    public void MethodBodyExample(object arg)
    {
        int var1 = 42;
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo