From a methodbase, I need to get an array of the IL instructions, the location and kind of that methods exception handlers and the local variables in that methods.
To do this currently (for non dynamic methods I just do)
MethodBody pBody = pMethod.GetMethodBody();
Method = pMethod;
MethodName = pMethod.Name;
IsPublic = pMethod.IsPublic;
IsStatic = pMethod.IsStatic;
Instructions = pBody.GetILAsByteArray();
Variables = pBody.LocalVariables.ToArray();
Module = pMethod.Module;
MethodInfo pMethodInfo = pMethod as MethodInfo;
ReturnType = pMethodInfo == null ? typeof(void) : pMethodInfo.ReturnType;
ExceptionHandlers = pBody.ExceptionHandlingClauses.ToArray();
Position = 0;
mhashExceptionParameters = new HashSet<ParameterExpression>();
mdictLocalExpressions = new Dictionary<LocalVariableInfo, ParameterExpression>();
However, as has been noted before, GetMethodBody() doesn't work for dynamic methods (e.g. a method handle got from compiling a linq expression). I know certain answers here show how to get the IL instructions. But how do I get the other things in a methodbody, such as Variables and Exceptionhandlers?
For reference, see this question where solutions to getting the IL byte array are given. How do I get an IL bytearray from a DynamicMethod?