Background
I'm writing a Visual Studio Extension in C# that executes code in the Immediate Window while debugging another application. The expression returns a value that can be a int, a string literal, a class, etc. The application that I'm debugging is written in C++.
The code
To execute the Immediate Window commands I use this line of code:
var expression = dte.Debugger.GetExpression("funcname()");
And to retrieve the result I use:
string val = expression.Value;
and:
var children = expression.DataMembers;
Here is myFunc() in the application I'm debugging:
std::vector<int> myFunc()
{
return { 1, 2, 3, 4, 5 };
}
The problem
When I manually run the expression in the Immediate Window, the returned object is dumped as I see it in the Watch Window (see here). I managed to find all the children names, but the values are missing (see here).
What I want is to achieve the DisplayString ({ size=5 }
), but I haven't found anything useful yet.
How can I get the DisplayString field from Debugger.GetExpression?
EDIT: I don’t have to use this API. If you know another way that can return this sting, please suggest it. One idea could be retrieving the full output string of the Immediate Window (see the right side), and then parsing it.
I found out what the problem was: I wasn't passing the
UseAutoExpandRules
(defaulted to false) inGetExpression
. Now my code works as expected!Thanks to @Mia Wu-MSFT who put
dte.Debugger.GetExpression("tempC", true, 1)
in her code and made me discover theUseAutoExpandRules
argument