Skip to content

Modernize System.Text.Json product code#130976

Open
eiriktsarpalis wants to merge 2 commits into
dotnet:mainfrom
eiriktsarpalis:eiriktsarpalis-modernize-stj-product
Open

Modernize System.Text.Json product code#130976
eiriktsarpalis wants to merge 2 commits into
dotnet:mainfrom
eiriktsarpalis:eiriktsarpalis-modernize-stj-product

Conversation

@eiriktsarpalis

@eiriktsarpalis eiriktsarpalis commented Jul 17, 2026

Copy link
Copy Markdown
Member

Adopts modern C# syntax in System.Text.Json product sources without changing behavior or public API.

  • Replaces 33 single-use private backing fields with C# 14 field-backed properties while preserving validation and side effects.
  • Converts six single-expression methods to expression-bodied members.
  • Replaces 415 built-in null comparisons with is null or is not null.
  • Replaces 32 stable constant and range comparisons with equivalent or, not, and relational patterns.

The pattern audit deliberately retains 56 null comparisons that bind to user-defined reflection equality operators and 19 compound checks whose conversion would reduce property or mutable-field reads. Project configuration and tests are unchanged. I also audited escaped literals and formatting calls, but retained the existing forms where raw strings or interpolation would not improve readability or would bypass localized resource formatting.

Validation

  • build.cmd clr+libs -rc release
  • System.Text.Json.csproj across net462, netstandard2.0, net10.0, and net11.0
  • dotnet build /t:test for the main System.Text.Json tests and all four Roslyn 3.11/4.4 source-generation test projects
  • 129,884 tests: 129,867 passed, 17 skipped, 0 failed

Note

This pull request was prepared by GitHub Copilot.

Use C# 14 field-backed properties for private state used only by accessors, and expression-bodied members for single-expression methods.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 69ae6b80-f573-41bd-8cf9-e0f858510bbe
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates System.Text.Json product sources to use newer C# syntax in a behavior-preserving way, primarily by replacing single-use private backing fields with field-backed properties and by converting a handful of trivial methods to expression-bodied members.

Changes:

  • Converted several properties from explicit private backing fields to C# field-backed properties (using field) while keeping existing validation/side effects in setters.
  • Converted multiple single-expression helper methods/wrappers to expression-bodied members.
  • Kept the changes scoped to implementation details (no new members introduced in the reviewed diffs).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs Converts simple type-kind predicates to expression-bodied methods.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs Migrates several callback/configuration properties to field-backed properties while preserving validation in setters.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs Migrates several configuration properties to field-backed properties while preserving VerifyMutable() and validation logic.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPolymorphismOptions.cs Converts configuration properties (including defaulting behavior) to field-backed properties.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs Converts ConverterStrategy to a field-backed init-only property while retaining side-effect initialization in init.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConfigurationList.cs Converts thin wrappers over _list to expression-bodied members.
src/libraries/System.Text.Json/src/System/Text/Json/Schema/JsonSchema.cs Converts many schema keyword properties to field-backed properties, keeping VerifyMutable() enforcement and initial values.
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs Converts CaptureState to an expression-bodied method without changing the captured values.

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@eiriktsarpalis
eiriktsarpalis enabled auto-merge (squash) July 17, 2026 16:22
Replace built-in null comparisons and stable compound comparisons with equivalent C# patterns. Retain reflection comparisons that bind user-defined equality operators.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 69ae6b80-f573-41bd-8cf9-e0f858510bbe
Copilot AI review requested due to automatic review settings July 17, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 114 out of 114 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants