Skip to content

Add CompositeFormat class reference to composite formatting docs#53686

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/add-composite-format-class-reference
Draft

Add CompositeFormat class reference to composite formatting docs#53686
Copilot wants to merge 3 commits into
mainfrom
copilot/add-composite-format-class-reference

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

The composite formatting article was missing any mention of System.Text.CompositeFormat (.NET 8+), which pre-parses format strings to eliminate repeated runtime parsing overhead in hot paths.

Changes

  • New section — "Improve performance with CompositeFormat" added before See also, covering:
    • How CompositeFormat.Parse() works and why caching the result as a static readonly/Shared ReadOnly field matters
    • Step-by-step usage with String.Format and StringBuilder.AppendFormat
    • Link to the CA1863 analyzer rule that flags optimization opportunities
  • Code snippets — C# and VB examples added to the existing snippet files demonstrating CompositeFormat usage
  • See also — Added <xref:System.Text.CompositeFormat> and CA1863 rule link

Example (C#)

// Parse once, cache as static readonly
CompositeFormat format = CompositeFormat.Parse("Name = {0}, hours = {1:hh}");

// Pass null for IFormatProvider to use the current culture.
// Use the pre-parsed format to avoid reparsing on every call.
string result = string.Format(null, format, "Fred", DateTime.Now);

Copilot AI self-assigned this May 12, 2026
Copilot AI review requested due to automatic review settings May 12, 2026 17:03
Copilot AI review requested due to automatic review settings May 12, 2026 17:03
Copilot AI requested review from Copilot and removed request for Copilot May 12, 2026 17:07
… passive voice

Agent-Logs-Url: https://github.com/dotnet/docs/sessions/dd16e561-6b82-4867-8a98-20e6d2548480

Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 12, 2026 17:08
Copilot AI changed the title [WIP] Update documentation to mention CompositeFormat class Add CompositeFormat class reference to composite formatting docs May 12, 2026
Copilot finished work on behalf of adegeo May 12, 2026 17:09
Copilot AI requested a review from adegeo May 12, 2026 17:09
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.

Documentation on composite formatting should mention the newer CompositeFormat class

2 participants