我只拿到了参数 类型方面的东东, 实例的想不到, 一切皆有可能, 基址偏移?using System; using System.Diagnostics; using System.Reflection;namespace stacktrace { class program { static void Main() { program p = new program(); p.a(1); } /// 直接调用 b , 编译器优化导致调用堆栈上无 a 的调用 int a(int p) { b(); return p++; }
void b() { //在这写什么代码能够取得调用堆栈里 方法a中参数p的值? StackFrame fr = new StackFrame(1); MethodBase mb = fr.GetMethod(); Console.WriteLine(mb.GetType()); Console.WriteLine(mb.Name); ParameterInfo[] pars = mb.GetParameters(); foreach (ParameterInfo p in pars) { Console.Write(p.ParameterType); Console.Write('\t'); Console.WriteLine(p.Name); } } } }
{
b(p);
} void b(int p)
{
//在这写什么代码能够取得调用堆栈里 方法a中参数p的值?
}
void a(int p)
{
b(p);
}void b(int p)
{
//得到值
}
using System.Diagnostics;
using System.Reflection;namespace stacktrace
{
class program
{
static void Main()
{
program p = new program();
p.a(1);
}
/// 直接调用 b , 编译器优化导致调用堆栈上无 a 的调用
int a(int p)
{
b();
return p++;
}
void b()
{
//在这写什么代码能够取得调用堆栈里 方法a中参数p的值?
StackFrame fr = new StackFrame(1);
MethodBase mb = fr.GetMethod();
Console.WriteLine(mb.GetType());
Console.WriteLine(mb.Name);
ParameterInfo[] pars = mb.GetParameters();
foreach (ParameterInfo p in pars)
{
Console.Write(p.ParameterType);
Console.Write('\t');
Console.WriteLine(p.Name);
}
}
}
}