Repository navigation
Add interpolated raw string literal example and System.Text.Json cross-links (Fixes #42727) - #56642
Manish-1kumar wants to merge 2 commits into
Conversation
…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
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
🟡 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
| var longitude = 47.6062; | ||
| var latitude = -122.3321; |
There was a problem hiding this comment.
Good catch! Swapped the latitude and longitude initializers to correct Seattle's coordinates in commit b4e89ef.
| var json = $$""" | ||
| { | ||
| "city": "{{city}}", | ||
| "coordinates": { | ||
| "longitude": {{longitude}}, | ||
| "latitude": {{latitude}} | ||
| } | ||
| } | ||
| """; |
There was a problem hiding this comment.
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.

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
New Executable Code Snippet (docs/csharp/language-reference/tokens/snippets/raw-string-literal.cs):
et8.0 with 0 warnings and executes as expected.
Article Update (docs/csharp/language-reference/tokens/raw-string.md):
Reciprocal Link (docs/standard/serialization/system-text-json/overview.md):
Fixes #42727