Skip to content

Add side-effect free debugger display to ValueStringBuilder.#122265

Merged
ViveliDuCh merged 3 commits intodotnet:mainfrom
teo-tsirpanis:vsb-debuggerdisplay
Jan 14, 2026
Merged

Add side-effect free debugger display to ValueStringBuilder.#122265
ViveliDuCh merged 3 commits intodotnet:mainfrom
teo-tsirpanis:vsb-debuggerdisplay

Conversation

@teo-tsirpanis
Copy link
Contributor

Calling ToString() clears the builder, which can cause surprises when debugging.

Calling `ToString()` clears the builder, which can cause surprises when debugging.
Copilot AI review requested due to automatic review settings December 6, 2025 20:25
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 6, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 6, 2025
@teo-tsirpanis teo-tsirpanis added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 6, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a side-effect free debugger display to both versions of ValueStringBuilder to address the problematic behavior where calling ToString() clears the builder, which causes unexpected issues during debugging.

Key changes:

  • Added [DebuggerDisplay] attribute to both ValueStringBuilder and ValueStringBuilder<TChar> structs
  • Created side-effect free DebuggerDisplay properties that display the builder's content without clearing it
  • Refactored ValueStringBuilder<TChar>.ToString() to extract string generation logic into a separate GetString() method

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/Common/src/System/Text/ValueStringBuilder.cs Added [DebuggerDisplay] attribute and DebuggerDisplay property that uses AsSpan().ToString() for side-effect free debugging
src/libraries/Common/src/System/Text/ValueStringBuilder_1.cs Added [DebuggerDisplay] attribute, extracted GetString() method for reuse, and added DebuggerDisplay property that calls GetString() for side-effect free debugging

@ViveliDuCh ViveliDuCh merged commit 3cf3599 into dotnet:main Jan 14, 2026
89 checks passed
@teo-tsirpanis teo-tsirpanis deleted the vsb-debuggerdisplay branch January 14, 2026 22:28
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants