Skip to content

CA2227: Expand "How to fix violations" with read-only and concurrent collection options#52764

Merged
BillWagner merged 5 commits into
mainfrom
copilot/ca2227-update-how-to-fix-it
Mar 31, 2026
Merged

CA2227: Expand "How to fix violations" with read-only and concurrent collection options#52764
BillWagner merged 5 commits into
mainfrom
copilot/ca2227-update-how-to-fix-it

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

The CA2227 rule doc only offered one fix (remove the setter), leaving developers without guidance when the design legitimately needs a mutable or thread-safe collection.

Changes

  • Expanded "How to fix violations" from a single sentence into three distinct, labeled approaches:
    1. Make the property read-only or init-only (original, refined)
    2. Use a read-only collection type (ReadOnlyCollection<T>) when callers shouldn't modify the collection
    3. Use a concurrent collection type (ConcurrentBag<T>) when multiple threads need to modify the collection concurrently
  • Updated ms.date to 03/30/2026
  • Added ai-usage: ai-assisted to frontmatter

Internal previews

📄 File 🔗 Preview link
docs/fundamentals/code-analysis/quality-rules/ca2227.md CA2227: Collection properties should be read only

Copilot AI linked an issue Mar 30, 2026 that may be closed by this pull request
…ent collection options

Agent-Logs-Url: https://github.com/dotnet/docs/sessions/64abbaf4-9979-4cf4-ac24-1e4138a9f3bb

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/docs/sessions/64abbaf4-9979-4cf4-ac24-1e4138a9f3bb

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copilot AI changed the title [WIP] Update how to fix violations for collection properties CA2227: Expand "How to fix violations" with read-only and concurrent collection options Mar 30, 2026
Copilot AI requested a review from BillWagner March 30, 2026 13:12
Comment thread docs/fundamentals/code-analysis/quality-rules/ca2227.md Outdated
Comment thread docs/fundamentals/code-analysis/quality-rules/ca2227.md Outdated
Comment thread docs/fundamentals/code-analysis/quality-rules/ca2227.md Outdated
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Copy link
Copy Markdown
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This is ready to merge.

@BillWagner BillWagner marked this pull request as ready for review March 31, 2026 15:09
@BillWagner BillWagner requested a review from a team as a code owner March 31, 2026 15:09
Copilot AI review requested due to automatic review settings March 31, 2026 15:09
Copy link
Copy Markdown
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 PR expands the CA2227 documentation so developers have multiple, scenario-based options for resolving warnings beyond simply removing the setter, including guidance for read-only wrappers and concurrent collection scenarios.

Changes:

  • Expanded How to fix violations into three distinct approaches (read-only/init-only, read-only wrapper types, and concurrent collection types).
  • Updated ms.date and added ai-usage: ai-assisted frontmatter metadata.
  • Refined wording across the rule description and examples for clarity and consistency.

Comment thread docs/fundamentals/code-analysis/quality-rules/ca2227.md Outdated
Comment thread docs/fundamentals/code-analysis/quality-rules/ca2227.md Outdated
Comment thread docs/fundamentals/code-analysis/quality-rules/ca2227.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@BillWagner BillWagner enabled auto-merge (squash) March 31, 2026 15:54
@BillWagner BillWagner closed this Mar 31, 2026
auto-merge was automatically disabled March 31, 2026 16:09

Pull request was closed

@BillWagner BillWagner reopened this Mar 31, 2026
@BillWagner BillWagner enabled auto-merge (squash) March 31, 2026 16:09
@BillWagner BillWagner merged commit 748a917 into main Mar 31, 2026
17 of 18 checks passed
@BillWagner BillWagner deleted the copilot/ca2227-update-how-to-fix-it branch March 31, 2026 16:14
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.

[CA2227] Update how to fix it

4 participants