Is there a way to check stack variables at runtime in C #?

Is there a way to flush the contents of the stack at runtime?

I am interested in how information about parent functions (name, parameters, string), which, as I know, I can get using the StackTrace and StackFrame classes. However, I would also like to get the variables on the stack (local variables declared in the method that called the one that is currently running). Since the Visual Studio debugger can do this, I think there may be a way to do this at runtime. Is there such a way?

+4
source share
1 answer

I guess there are two ways to achieve this.

Your first option is to use the AOP structure to enter the toolkit code as a stage of subsequent compilation. This can be precisely targeted and allows you to do almost anything you want, but works best when you can isolate the desired additional behavior from the rest of the code. PostSharp is a leading competitor in this area, but I'm sure there are others.

The second option is to connect to the profiler API, which makes TypeMock Isolator and Microsoft in-house. This basically gives you the means to intercept everything, but it is quite software invasive and, of course, not a trivial task to implement. In fact, I would not recommend this approach to anyone except to mention it for completeness.

+1
source

All Articles