Alphamacaroon
Alphamacaroon

Reputation:

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

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?

Upvotes: 3

Views: 5097

Answers (1)

BFree
BFree

Reputation: 103740

Yes, the StackFrame class can help you with that.

Linkage

Something along these lines

var currentStackFrame = new StackFrame(1);
var props = currentStackFrame.GetMethod().GetParameters(); 

Upvotes: 3

Related Questions