我希望能够从.NET中的堆栈帧获取所有参数值.有点像在Visual Studio调试器中看到调用堆栈中的值的方式.我的方法集中在使用StackFrame类,然后反映在ParameterInfo数组上.我在反射和属性方面取得了成功,但事实证明这有点棘手.
有没有办法实现这一目标?
到目前为止,代码如下所示:
class Program
{
static void Main(string[] args)
{
A a = new A();
a.Go(1);
}
}
public class A
{
internal void Go(int x)
{
B b = new B();
b.Go(4);
}
}
public class B
{
internal void Go(int y)
{
Console.WriteLine(GetStackTrace());
}
public static string GetStackTrace()
{
StringBuilder sb = new StringBuilder();
StackTrace st = new StackTrace(true);
StackFrame[] frames = st.GetFrames();
foreach (StackFrame frame in frames)
{
MethodBase method = …Run Code Online (Sandbox Code Playgroud)