Printing parameter values ​​along the stack trace

Printing a stack trace is not so difficult to use System.Diagnostics. I am wondering if it is possible to print the VALUES values ​​of the parameters passed to each method to the stack trace, and if not, why.

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.

+5
source share
1 answer

You cannot do this, at least not with the classes provided System.Diagnostics. The class StackFramedoes not provide a way to access the values ​​of the argument ( MethodBase.GetParametersprovides information about the declared parameters, for example, their names and types, but not the values ​​of the actual arguments)

I think this can be done using the CLR debugging API, but probably not from C #

+2

All Articles