Skip to content

Address tutorial feedback#51518

Open
BillWagner wants to merge 1 commit intodotnet:mainfrom
BillWagner:interpolated-string-handler-fixes
Open

Address tutorial feedback#51518
BillWagner wants to merge 1 commit intodotnet:mainfrom
BillWagner:interpolated-string-handler-fixes

Conversation

@BillWagner
Copy link
Member

@BillWagner BillWagner commented Feb 4, 2026

Fixes #51310

Address all the comments in this issue.


Internal previews

📄 File 🔗 Preview link
docs/csharp/advanced-topics/performance/interpolated-string-handler.md Tutorial: Write a custom string interpolation handler

Fixes dotnet#51310

Address all the comments in this issue.
@BillWagner BillWagner requested a review from a team as a code owner February 4, 2026 22:02
Copilot AI review requested due to automatic review settings February 4, 2026 22:02
@dotnetrepoman dotnetrepoman bot added this to the February 2026 milestone Feb 4, 2026
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 pull request addresses all feedback points from issue #51310 regarding the C# interpolated string handler tutorial. The changes improve the tutorial by adding missing implementation details, clarifying behaviors, and simplifying examples.

Changes:

  • Added implementation for AppendFormatted with alignment and format parameters
  • Replaced custom GetFormattedText() method with standard ToString() override in all logger versions
  • Added documentation notes about constant interpolated strings and empty InterpolatedStringHandlerArgumentAttribute behavior
  • Simplified the side-effects demonstration from 5 increments to 1 increment per loop iteration
  • Updated target framework from net8.0 to net10.0

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
logger-v4.cs Added AppendFormatted overload with alignment parameter and replaced GetFormattedText with ToString override
logger-v3.cs Replaced GetFormattedText with ToString override
Logger-v2.cs Replaced GetFormattedText with ToString override
Version_4_Examples.cs Simplified side-effects example to use single increment instead of five
interpolated-string-handler.md Added two notes explaining constant interpolated string behavior and empty attribute behavior; updated expected output
interpolated-string-handler.csproj Updated TargetFramework from net8.0 to net10.0

:::code language="csharp" source="./snippets/interpolated-string-handler/Logger-v2.cs" id="CoreInterpolatedStringHandler":::

> [!NOTE]
> When the interpolated string expression is a compile-time constant (that is, it contains no placeholders), the compiler uses the target type `string` instead of invoking a custom interpolated string handler. This means constant interpolated strings bypass custom handlers entirely.
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

According to the markdown writing style guidelines, use contractions for better readability. Change "it contains no placeholders" to "it doesn't contain placeholders" or rephrase to use a contraction.

Copilot generated this review using guidance from repository custom instructions.
:::code language="csharp" source="./snippets/interpolated-string-handler/Logger-v2.cs" id="CoreInterpolatedStringHandler":::

> [!NOTE]
> When the interpolated string expression is a compile-time constant (that is, it contains no placeholders), the compiler uses the target type `string` instead of invoking a custom interpolated string handler. This means constant interpolated strings bypass custom handlers entirely.
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The note should use contractions according to the markdown writing style guidelines. Change "it contains no placeholders" to "it doesn't contain placeholders" or "it has no placeholders".

Copilot generated this review using guidance from repository custom instructions.
:::code language="csharp" source="./snippets/interpolated-string-handler/Version_4_Examples.cs" id="TestSideEffects":::

You can see the `index` variable is incremented five times each iteration of the loop. Because the placeholders are evaluated only for `Critical`, `Error` and `Warning` levels, not for `Information` and `Trace`, the final value of `index` doesn't match the expectation:
You can see the `index` variable is incremented each iteration of the loop. Because the placeholders are evaluated only for `Critical`, `Error` and `Warning` levels, not for `Information` and `Trace`, the final value of `index` doesn't match the expectation:
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

This sentence is missing an Oxford comma. Change "evaluated only for Critical, Error and Warning levels" to "evaluated only for Critical, Error, and Warning levels".

Copilot generated this review using guidance from repository custom instructions.
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.

Feedback on the tutorial "Write a custom string interpolation handler"

1 participant