Skip to content

Add interpolated raw string literal example and System.Text.Json cross-links (Fixes #42727) - #56642

Open
Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-42727-raw-string-interpolation
Open

Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-42727-raw-string-interpolation

Conversation

@Manish-1kumar

Copy link
Copy Markdown
Contributor

Summary

This pull request addresses #42727 by adding a concrete code example and explanation for combining raw string literals with string interpolation in C#, along with reciprocal cross-links between the raw string literals documentation and System.Text.Json.

Changes Made

  1. New Executable Code Snippet (docs/csharp/language-reference/tokens/snippets/raw-string-literal.cs):

    • Added snippet demonstrating the use of $$" to produce formatted JSON containing both literal braces ({, }) and interpolated expressions ({{city}}, {{longitude}}, {{latitude}}).
    • Verified that string-interpolation.csproj compiles cleanly targeting
      et8.0 with 0 warnings and executes as expected.
  2. Article Update (docs/csharp/language-reference/tokens/raw-string.md):

    • Referenced the new snippet using :::code language=csharp source=./snippets/raw-string-literal.cs id=InterpolatedRawString:::.
    • Clarified that the number of $ characters determines how many consecutive braces start and end an interpolation expression.
    • Added a [!TIP] directing developers to System.Text.Json for structured data serialization, per maintainer @BillWagner's suggestion.
  3. Reciprocal Link (docs/standard/serialization/system-text-json/overview.md):

    • Added a cross-link under Additional resources directing readers to the raw string literals guide when defining inline JSON literals in code.

Fixes #42727

…s-links

- Add snippet demonstrating combining raw string literals with string interpolation (")
- Add snippet reference and explanation in docs/csharp/language-reference/tokens/raw-string.md
- Add cross-link tip to System.Text.Json overview for structured object serialization
- Add reciprocal cross-link in docs/standard/serialization/system-text-json/overview.md

Fixes dotnet#42727
@dotnetrepoman dotnetrepoman Bot added this to the November 2026 milestone Nov 1, 2026
@Manish-1kumar

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

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.

🟡 Changes recommended

The raw-string example reverses Seattle’s latitude and longitude and uses culture-dependent number formatting, producing invalid coordinates and potentially invalid JSON.

2 open issues
What changed in this PR

Addresses #42727 with a concrete interpolated raw string example and links between the C# language reference and System.Text.Json documentation.

Changes:

  • Adds a JSON snippet that combines literal braces with interpolated expressions.
  • Explains how the number of $ characters controls interpolation delimiters.
  • Adds reciprocal documentation links and recommends System.Text.Json for structured data serialization.
File Description
docs/​standard/​serialization/​system-text-json/​overview.md Links to raw string literals for inline JSON examples.
docs/​csharp/​language-reference/​tokens/​snippets/​raw-string-literal.cs Adds an interpolated raw string JSON example.
docs/​csharp/​language-reference/​tokens/​raw-string.md Includes the snippet, clarifies brace syntax, and adds serialization guidance.

Review effort: Balanced

Comment on lines +35 to +36
var longitude = 47.6062;
var latitude = -122.3321;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Swapped the latitude and longitude initializers to correct Seattle's coordinates in commit b4e89ef.

Comment on lines +39 to +47
var json = $$"""
{
"city": "{{city}}",
"coordinates": {
"longitude": {{longitude}},
"latitude": {{latitude}}
}
}
""";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in commit b4e89ef: wrapped the raw string interpolation with FormattableString.Invariant to format coordinates using decimal point notation across all locales.

…nippet

Swap latitude and longitude initializers and wrap the raw string interpolation with FormattableString.Invariant to emit valid JSON coordinates across all cultures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please provide example for combining raw string literals with interpolated string

2 participants