CA2227: Expand "How to fix violations" with read-only and concurrent collection options#52764
Merged
Merged
Conversation
…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
gewarren
approved these changes
Mar 30, 2026
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
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.dateand addedai-usage: ai-assistedfrontmatter metadata. - Refined wording across the rule description and examples for clarity and consistency.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
auto-merge was automatically disabled
March 31, 2026 16:09
Pull request was closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ReadOnlyCollection<T>) when callers shouldn't modify the collectionConcurrentBag<T>) when multiple threads need to modify the collection concurrentlyms.dateto03/30/2026ai-usage: ai-assistedto frontmatterInternal previews