Modernize System.Text.Json product code#130976
Open
eiriktsarpalis wants to merge 2 commits into
Open
Conversation
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: 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. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
Contributor
There was a problem hiding this comment.
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. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adopts modern C# syntax in
System.Text.Jsonproduct sources without changing behavior or public API.is nulloris not null.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 releaseSystem.Text.Json.csprojacrossnet462,netstandard2.0,net10.0, andnet11.0dotnet build /t:testfor the mainSystem.Text.Jsontests and all four Roslyn 3.11/4.4 source-generation test projectsNote
This pull request was prepared by GitHub Copilot.