被调用的方法如果取得调者的局部变量?
ljyit 2009-03-29 10:45:49 fun1()
{
int a=1;
int b=2;
funTest(name);
}
funTest(string str)
{
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
System.Reflection.MethodBody mb = trace.GetFrame(1).GetMethod().GetMethodBody();
foreach (System.Reflection.LocalVariableInfo lvi in mb.LocalVariables)
{
//在这里,虽然lvi能得到fun1()中的局部变量类型,但如何取得局部变量的名字和值呢? }
}