Printing the stack trace is not so difficult when using System.Diagnostics. I am wondering if it is possible to print the VALUES of the parameters passed to each method up the stack trace, and if not why not.
Here is my preliminary code:
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?
}
}
}
}
Thanks in advance.
You can’t do that, at least not with the classes provided by
System.Diagnostics. TheStackFrameclass doesn’t provide a way to access the argument values (MethodBase.GetParametersprovides information about the declared parameters, e.g. their names and types, but not the values of the actual arguments)I think it’s possible to do it with the CLR debugging APIs, but probably not from C#