使用 System.Diagnostics
打印堆栈跟踪并不难。我想知道是否有可能打印传递给每个方法的参数值,如果不行,为什么不行。
以下是我的初步代码:
public static class CallStackTracker
{
public static void Print()
{
var st = new StackTrace();
for (int i = 0; i < st.FrameCount; i++)
{
var frame = st.GetFrame(i);
var mb = frame.GetMethod();
var parameters = mb.GetParameters();
foreach (var p in parameters)
{
// Stuff probably goes here, but is there another way?
}
}
}
}
感谢您提前的帮助。
MethodInfo.GetParameters
返回的是声明的参数,而不是实际的参数值... - Thomas Levesque