次の方法で共有


Evaluate expressions

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Expressions are created from strings passed down from the Autos, Watch, QuickWatch, or Immediate windows. When an expression is evaluated, it generates a printable string that contains the name and type of variable or argument and its value. This string is displayed in the corresponding IDE window.

Implementation

Expressions are evaluated when a program has stopped at a breakpoint. The expression itself is represented by an IDebugExpression2 interface, which represents a parsed expression that's ready for binding and evaluation within the given expression evaluation context. The stack frame determines the expression evaluation context, which the debug engine (DE) supplies by implementing the IDebugExpressionContext2 interface.

Given a user string and an IDebugExpressionContext2 interface, a debug engine (DE) can obtain an IDebugExpression2 interface by passing the user string to the IDebugExpressionContext2::ParseText method. The IDebugExpression2 interface that's returned contains the parsed expression ready for evaluation.

With the IDebugExpression2 interface, the DE can get the value of the expression through synchronous or asynchronous expression evaluation, using IDebugExpression2::EvaluateSync or IDebugExpression2::EvaluateAsync. This value, along with the name and type of the variable or argument, is sent to the IDE for display. The value, name, and type are represented by an IDebugProperty2 interface.

To enable expression evaluation, a DE must implement the IDebugExpression2 and IDebugExpressionContext2 interfaces. Both synchronous and asynchronous evaluation require the implementation of the IDebugProperty2::GetPropertyInfo method.

See also