Is there object/class browsing in Visual Studio with C# while debugging/code tracing?

584 Views Asked by At

So my idea is I want to see what an object's members or properties would return/change while I am debugging/tracing. There is Object Browser but it is only to show tree list of an object.

For example, let's say

var cacheDir = cotext.CacheDir;

But I want to change .CacheDir to .ExternalCacheDir while debugging to see what value would be returned to the variable.

var cacheDir = context.ExternalCacheDir;

Otherwise, I have to change it in editing mode and restart the whole debugging process. I think that we can do something like this in browser developer console or Jupyter notebook like CLI environment.

3

There are 3 best solutions below

0
On

There are many ways to see variables values in VS. You can use the Watch Window, You can hover a variable and see a Data Tip, you can use the Immediate Window. You can also check OzCode that provides a HUD that shows the variable values without the need to open any Window, and provide a nice way to choose the properties that you like to present, and provides a google like search for variable name and values. In the next version of OzCode (you can download a preview version of it) you can use OzCode Predict that also support VS Edit&Continue.

1
On

With C# Keyboard settings you press Ctrl+Alt+I - the immediate window. Or via the Command window type Immed.

In the Immediate Window you can do ad-hoc commands.

So in the debugger IDE you'd step over the line of code:

var cacheDir = cotext.CacheDir;

And now you want to tweak it just a once off, Ctrl+Alt+I

Then paste:

cacheDir = cotext.ExternalCacheDir;

And press enter. You can always revert back in the immediate window, eg:

cacheDir = cotext.CacheDir;

If you just want to see the value of a variable you can do a ? cacheDir to see the values. Give it a go :)

0
On

While you're debugging, you can use Watch windows to watch variables and expressions.

Open a Watch window by selecting Debug > Windows > Watch > Watch 1, 
or pressing Ctrl+Alt+W > 1.

In the Watch window, select an empty row, and type variable or Expression

Continue debugging by selecting Debug > Step Into or pressing F11 as needed to advance.
The variable values in the Watch window change as you iterate through the for loop.

Reference