在调试/代码跟踪时,是否可以使用C#在Visual Studio中进行对象/类浏览?

时间:2019-03-06 04:02:55

标签: c# visual-studio visual-studio-debugging objectbrowser

所以我的想法是我想查看在调试/跟踪时对象的成员或属性将返回/更改什么。有对象浏览器,但仅用于显示对象的树列表。

例如,说

var cacheDir = cotext.CacheDir;

但是我想在调试时将.CacheDir更改为.ExternalCacheDir,以查看将向变量返回什么值。

var cacheDir = context.ExternalCacheDir;

否则,我必须在编辑模式下进行更改,然后重新启动整个调试过程。我认为我们可以在浏览器开发人员控制台或Jupyter笔记本(如CLI环境)中执行类似的操作。

3 个答案:

答案 0 :(得分:4)

使用C#键盘设置,您可以按 Ctrl + Alt + I -立即窗口。或通过“命令”窗口键入Immed。

在立即窗口中,您可以执行临时命令。

因此,在调试器IDE中,您将跳过代码行:

var cacheDir = cotext.CacheDir;

现在您要对其进行调整一次关闭 Ctrl + Alt + I

然后粘贴:

cacheDir = cotext.ExternalCacheDir;

然后按Enter。您随时可以在即时窗口中还原,例如:

cacheDir = cotext.CacheDir;

如果只想查看变量的值,可以执行 cacheDir来查看值。快去吧:)

答案 1 :(得分:1)

在调试时,可以使用“监视”窗口监视变量和表达式。

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

答案 2 :(得分:1)

有很多方法可以在VS中查看变量值。您可以使用监视窗口,可以将变量悬停并查看数据提示,可以使用即时窗口。您还可以检查OzCode,它提供了一个HUD,无需打开任何窗口即可显示变量值,并提供了一种不错的方式来选择您要显示的属性,并提供了类似于google的搜索变量名和值的方法。 在下一版本的OzCode(您可以下载它的预览版)中,您可以使用OzCode Predict,它也支持VS Edit&Continue。