Can you get a list of variables on the stack in C#

2020-06-06 04:02发布

All, just wondering if it's possible in .NET/C# to get a list of variables on the stack and their values? I am creating an exception handler for my app and beyond a standard stack trace I'd also like to see the names and values for any variables that are on the stack. Any idea if this can be done?

1条回答
Melony?
2楼-- · 2020-06-06 04:48

Yes, the StackFrame class can help you with that.

Linkage

Something along these lines

var currentStackFrame = new StackFrame(1);
var props = currentStackFrame.GetMethod().GetParameters(); 
查看更多
登录 后发表回答