本文整理汇总了C#中System.Reflection.MethodBase.GetMethodBody方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.GetMethodBody方法的具体用法?C# MethodBase.GetMethodBody怎么用?C# MethodBase.GetMethodBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.GetMethodBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Disassembler
private Disassembler(MethodBase method, ILStyler styler)
{
this._module = method.DeclaringType.Module;
this._styler = styler;
if (method.GetMethodBody() != null)
{
this._il = method.GetMethodBody().GetILAsByteArray();
}
}
示例2: MethodBodyReader
/// <summary>
/// MethodBodyReader constructor
/// </summary>
/// <param name="mi">
/// The System.Reflection defined MethodInfo
/// </param>
public MethodBodyReader(MethodInfo mi)
{
this.mi = mi;
if (mi.GetMethodBody() != null)
{
il = mi.GetMethodBody().GetILAsByteArray();
ConstructInstructions(mi.Module);
}
}
示例3: Class776
// Token: 0x06002E89 RID: 11913
// RVA: 0x0012E9C4 File Offset: 0x0012CBC4
public Class776(MethodBase methodBase_1)
{
this.methodBase_0 = methodBase_1;
byte[] array = (methodBase_1.GetMethodBody() != null) ? methodBase_1.GetMethodBody().GetILAsByteArray() : null;
if (array != null)
{
this.byte_0 = array;
this.method_3(methodBase_1.Module);
}
}
示例4: ILReader
/*
public ILReader(MethodBase enclosingMethod)
{
this.m_enclosingMethod = enclosingMethod;
MethodBody methodBody = m_enclosingMethod.GetMethodBody();
this.m_byteArray = (methodBody == null) ? new Byte[0] : methodBody.GetILAsByteArray();
this.m_position = 0;
}
*/
public ILReader2(MethodBase enclosingMethod)
{
this.m_enclosingMethod = enclosingMethod;
MethodBody methodBody = m_enclosingMethod.GetMethodBody();
this.m_byteArray = (methodBody == null) ? new Byte[0] : methodBody.GetILAsByteArray();
this.m_position = 0;
}
示例5: ExceptionDetails
public ExceptionDetails(Exception ex, MethodBase info)
{
var methodBody = info.GetMethodBody();
Exception = ex;
MethodName = info.Name;
MethodBody = methodBody != null ? methodBody.ToString() : "undefined";
}
示例6: MethodBodyReader
MethodBodyReader (MethodBase method)
{
this.method = method;
this.body = method.GetMethodBody ();
if (this.body == null)
throw new ArgumentException ("Method has no body");
var bytes = body.GetILAsByteArray ();
if (bytes == null)
throw new ArgumentException ("Can not get the body of the method");
if (!(method is ConstructorInfo))
method_arguments = method.GetGenericArguments ();
if (method.DeclaringType != null)
type_arguments = method.DeclaringType.GetGenericArguments ();
if (!method.IsStatic)
this_parameter = new ThisParameter(method.DeclaringType);
this.parameters = method.GetParameters ();
this.locals = body.LocalVariables;
this.module = method.Module;
this.il = new ByteBuffer (bytes);
this.instructions = new List<Instruction> ((bytes.Length + 1) / 2);
}
示例7: NaiveMethodNameExtractor
public NaiveMethodNameExtractor(Delegate @delegate)
{
delegateMethod = @delegate.Method;
body = delegateMethod.GetMethodBody();
Debug.Assert(body != null);
module = delegateMethod.Module;
stream = new MemoryStream(body.GetILAsByteArray());
Read();
}
示例8: DoInitStackAnalysis
protected override void DoInitStackAnalysis(MethodBase aMethod)
{
base.DoInitStackAnalysis(aMethod);
switch (OpCode)
{
case Code.Ldloc:
var xBody = aMethod.GetMethodBody();
if (xBody != null)
{
StackPushTypes[0] = xBody.LocalVariables[Value].LocalType;
if (StackPushTypes[0].IsEnum)
{
StackPushTypes[0] = StackPushTypes[0].GetEnumUnderlyingType();
}
}
return;
case Code.Ldloca:
StackPushTypes[0] = typeof(void*);
return;
case Code.Ldarga:
StackPushTypes[0] = typeof (void*);
return;
case Code.Ldarg:
var xArgIndexCorrection = 0;
if (!aMethod.IsStatic)
{
if (Value == 0)
{
StackPushTypes[0] = aMethod.DeclaringType;
if (StackPushTypes[0].IsEnum)
{
StackPushTypes[0] = StackPushTypes[0].GetEnumUnderlyingType();
}
else
{
if (StackPushTypes[0].IsValueType)
{
StackPushTypes[0] = typeof (void*);
}
}
return;
}
xArgIndexCorrection = -1;
}
var xParams = aMethod.GetParameters();
StackPushTypes[0] = xParams[Value + xArgIndexCorrection].ParameterType;
if (StackPushTypes[0].IsEnum)
{
StackPushTypes[0] = StackPushTypes[0].GetEnumUnderlyingType();
}
return;
default:
break;
}
}
示例9: OnExit
public void OnExit(MethodBase method)
{
Console.WriteLine("OnExit");
var mi = (MethodInfo) method;
var p = method.GetParameters();
var b = method.GetMethodBody();
var st = new StackTrace();
StackFrame sf = st.GetFrame(1); //previous method call
}
示例10: GetIntermediateLanguageFromMethodInfoBase
/// <summary>
/// Get intermediate language of passed method.
/// </summary>
/// <param name="methodInfo"> The method info. </param>
/// <returns> The intermediate language as a byte array. </returns>
/// <exception cref="ArgumentException">Thrown if methodBody is null.</exception>
private static IEnumerable<byte> GetIntermediateLanguageFromMethodInfoBase(MethodBase methodInfo)
{
var methodBody = methodInfo.GetMethodBody();
if (methodBody == null)
{
throw new ArgumentException("Method Body is null");
}
return methodBody.GetILAsByteArray();
}
示例11: MethodBodyReader
/// <summary>
/// MethodBodyReader constructor
/// </summary>
/// <param name="method">The method to read the body from.</param>
/// <param name="language">Code language to use for text representations of code.</param>
public MethodBodyReader(MethodBase method, ILanguageInfo language)
{
try
{
this.method = method;
this.language = language ?? new DefaultLanguageInfo();
MethodBody body = method.GetMethodBody();
if (body != null)
{
il = body.GetILAsByteArray();
ConstructInstructions(method.Module);
}
}
catch (Exception ex)
{
throw new InvalidOperationException(String.Format("Failed to read the body of {0}'s {1}.", method.DeclaringType, method), ex);
}
}
示例12: MethodBodyReader
private MethodBodyReader(MethodBase method)
{
_method = method;
_body = method.GetMethodBody();
if (_body == null)
throw new ArgumentException("Method has no body");
var iLAsByteArray = _body.GetILAsByteArray();
if (iLAsByteArray == null)
throw new ArgumentException("Can not get the body of the method");
if (!(method is ConstructorInfo))
_methodArguments = method.GetGenericArguments();
if (method.DeclaringType != null)
_typeArguments = method.DeclaringType.GetGenericArguments();
_parameters = method.GetParameters();
_locals = _body.LocalVariables;
_module = method.Module;
_il = new ByteBuffer(iLAsByteArray);
}
示例13: CopyMethodBody
void CopyMethodBody(MethodBase Base, ILGenerator Gen)
{
MethodBody Body = Base.GetMethodBody();
CopyLocals(Gen, Body);
byte[] Bytes = Body.GetILAsByteArray();
var ExceptionTrinkets = new List<int>();
var LabelTargets = new Dictionary<int, Label>();
var LabelOrigins = new Dictionary<int, Label[]>();
MineExTrinkets(Body, ExceptionTrinkets);
// There's a reason we mine these labels. First of all, we need to get the switchmaps. Because
// there is no way to bang a number of bytes in the IL, we mine the targets of a switch operation
// and save them to be marked when we walk through the method again to copy the opcodes. Secondly,
// the microsoft C# compiler sometimes uses the leave.s opcode instead of the leave opcode at the
// end of a try block. This is all fine, but System.Reflection.Emit forces a leave opcode on the
// IL when we call BeginCatchBlock() and friends, offering no way to use the leave.s opcode instead.
// The simple result is that we are left with putting the leave instruction with its 4-byte
// argument in the IL against our will. This screws over all branch targets with an offset of +3
// bytes. Consequently, we have to mine *all* branch targets and re-mark them to prevent segfaults
// and the like in the runtime. This overhead could all have been avoided, had SRE given us just
// a tiny bit more of control over the IL that was to be emitted.
MineLabels(Bytes, Gen, LabelOrigins, LabelTargets);
for(int i = 0; i < Bytes.Length; i++)
{
CopyTryCatch(Gen, i, Body, ExceptionTrinkets);
CopyLabels(Gen, i, LabelTargets);
CopyOpcode(Bytes, ref i, Gen, Base.Module, ExceptionTrinkets, LabelOrigins);
}
// If we do not throw this exception, SRE will do it, but with much less debugging information.
foreach(int i in LabelTargets.Keys)
throw new Exception("Unmarked label destined for RVA "+i.ToString("X"));
}
示例14: Disassemble
public DisassembledMethod Disassemble(MethodBase method)
{
Contract.Requires(method != null);
Contract.Requires(CanDisassemble(method));
var methodBody = method.GetMethodBody();
if (methodBody == null)
{
throw new NotSupportedException(method.DeclaringType +" {" + method.ToString() + "} "+ method.GetMethodImplementationFlags() );
}
Contract.Assert(methodBody!=null);
// ReSharper disable PossibleNullReferenceException
var ilBytes = methodBody.GetILAsByteArray();
// ReSharper restore PossibleNullReferenceException
Type returnType = method is MethodInfo
? (method as MethodInfo).ReturnType
: typeof (void);
var handlingClauses = methodBody.ExceptionHandlingClauses;
Type[] genericParameters = null;
if (method.IsGenericMethod)
{
genericParameters = method.GetGenericArguments();
}
return new DisassembledMethod(
ilBytes,
Scan(ilBytes, handlingClauses),
new ModuleMetadataResolver(method.Module),
handlingClauses,
methodBody.LocalVariables,
returnType,
method.GetParameters(),
method.IsGenericMethodDefinition ,
genericParameters );
}
示例15: MethodDetail
public MethodDetail(RootDetail parent, MethodBase mi)
: base(parent, mi)
{
CodeStringBuilder csb = new CodeStringBuilder(AppendMode.Text);
csb.AppendMethodName(mi);
_name = csb.ToString();
_visibility = VisibilityUtil.GetVisibilityFor(mi);
_category = "method";
MethodBody body = null;
try
{
body = mi.GetMethodBody();
}
catch (VerificationException)
{
// "Operation could destabilize the runtime" on .NET 3.0 WPF PresentationCore.dll
}
if (body != null)
{
_body = GenericUtility.GetILAsHashedText(mi);
}
csb = new CodeStringBuilder();
AppendAttributesDeclaration(csb);
MethodInfo bi = null;
if (mi is MethodInfo)
{
bi = ((MethodInfo)mi).GetBaseDefinition();
}
csb.Mode = AppendMode.Html;
csb.AppendVisibility(_visibility);
csb.AppendText(" ");
csb.Mode = AppendMode.Both;
if (mi.IsAbstract)
{
if (!mi.DeclaringType.IsInterface)
{
csb.AppendKeyword("abstract ");
}
}
else if (mi.IsVirtual && !mi.IsFinal)
{
if (!object.ReferenceEquals(mi, bi))
{
csb.AppendKeyword("override ");
}
else
{
csb.AppendKeyword("virtual ");
}
}
else if (mi.IsStatic)
{
csb.AppendKeyword("static ");
}
if (mi is MethodInfo)
{
csb.AppendParameter(((MethodInfo)mi).ReturnParameter);
}
csb.AppendText(" ");
csb.AppendText(_name);
csb.AppendText("(");
CodeStringBuilder csbParameters = new CodeStringBuilder(AppendMode.Text);
foreach (ParameterInfo pi in mi.GetParameters())
{
csb.AppendParameter(pi);
csb.AppendText(", ");
csbParameters.AppendParameterType(pi);
csbParameters.AppendText(", ");
_parameterCount++;
}
if (mi.GetParameters().Length > 0)
{
csb.RemoveCharsFromEnd(2);
csbParameters.RemoveCharsFromEnd(2);
}
csb.AppendText(")");
if (mi is MethodInfo)
{
csb.AppendGenericRestrictions(mi);
}
_declaration = csb.ToString();
//.........这里部分代码省略.........