2.7.10 Debugging and Tracing Property Accessors

Video: Debugging Properties (5:18)
Debugging and Tracing Property Accessors

Trace the TrainingArea property to see the getter, calculation, and setter as separate events. The setter can reject a value even when the assignment statement completes normally.

Break on the accessors

Use the complete validated TrainingArea definition below.

  1. Build and create a fresh area. Put a breakpoint on the setter condition and one on the getter return statement.
  2. Call IncreaseTemperature from an existing caller method. If construction stops in the setter first, inspect value as 20.0, then continue.
  3. During the action, inspect the getter result, then follow the setter receiving 20.5.
  4. Step over the condition and accepted assignment. Continue and read the resulting temperature.
Distinguish next work from completed work
Expected first increase
Moment Backing field Relevant value
Getter before arithmetic 20.0 Getter returns 20.0
Setter condition before assignment 20.0 value is 20.5
After accepted assignment 20.5 Stored state is updated

If paused on the assignment, the new value has not necessarily been stored yet. Step over before claiming that it has changed. Inspect the backing field directly in Locals when possible; inspecting a property in debugger tools can itself evaluate a getter.

Trace a refused proposal

From a fresh area, call IncreaseTemperature ten times to reach 25.0. On the next call, the setter sees 25.5. The condition is false, its assignment is skipped, and the field stays 25.0.

Apply the idea
Check your understanding