Hi @MypkaXD ,
To iterate through the variables in the Watch List and retrieve their names and values using DTE (Development Tools Environment) in Visual Studio, you can access the Debug
object. The Watch
window contains expressions, and you can retrieve these through the Expression
objects available via Debugger3
.
EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)m_DTE_dte;
EnvDTE80.Debugger3 debugger = (EnvDTE80.Debugger3)dte2.Debugger;
EnvDTE.Expression watchExpression;
var watchWindow = dte2.Windows.Item("{90243340-BD7A-11D0-93EF-00A0C90F2734}");
watchWindow.Visible = true;
var watchExpressions = debugger.Watchers;
foreach (EnvDTE.Expression exp in watchExpressions)
{
// Access the name and value of each expression
string variableName = exp.Name;
string variableValue = exp.Value;
Console.WriteLine($"Variable Name: {variableName}, Value: {variableValue}");
}
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.