Can I get the method local variables through a stack trace in C#?

前端 未结 1 1953
借酒劲吻你
借酒劲吻你 2020-12-15 12:02

I want to get a detailed log about my stack trace. I can get a StackFrame and then the method and then get all the parameters of that method. Just as the following code:

相关标签:
1条回答
  • 2020-12-15 12:53

    You might want to look into LocalVariableInfo.

    Example fom MSDN // Get method body information.

    MethodInfo mi = typeof(Example).GetMethod("MethodBodyExample");
    MethodBody mb = mi.GetMethodBody();
    Console.WriteLine("\r\nMethod: {0}", mi);
    
    // Display the general information included in the 
    // MethodBody object.
    Console.WriteLine("    Local variables are initialized: {0}", 
        mb.InitLocals);
    
    foreach (LocalVariableInfo lvi in mb.LocalVariables)
    {
        Console.WriteLine("Local variable: {0}", lvi);
    }
    
    0 讨论(0)
提交回复
热议问题