Repository navigation
Require documentation for C# 14 extension members (extension blocks no longer treated as private) - #4163
Merged
Conversation
Members of an extension block are exposed through the containing static class, but the block has no modifiers and was treated as a private nested type. As a result, SA1600 and the other documentation rules treated every extension member as private and never required documentation for them. Part of #4046 (checklist item #4023).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4163 +/- ##
=======================================
Coverage 97.39% 97.39%
=======================================
Files 1073 1074 +1
Lines 122990 123037 +47
Branches 4173 4174 +1
=======================================
+ Hits 119781 119828 +47
Misses 2108 2108
Partials 1101 1101 🚀 New features to boost your workflow:
|
AArnott
marked this pull request as ready for review
October 8, 2026 06:01
This was referenced Nov 11, 2026
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/aspnetcore-webhooks-sample#436
Open
Closed
Open
This was referenced Nov 23, 2026
Open
[DPDBT] Bump Microsoft.CodeAnalysis.Analyzers and 6 others
sergey-rybalkin/CommandLine.Generators#63
Open
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.
Part of #4046 (C# 14 audit), checklist item #4023 (extension members). Independent master-based PR.
Bug:
AccessLevelHelper.GetDeclaredAccessibility(BaseTypeDeclarationSyntax)treated a C# 14extension(...) { }block like a nested type with no modifiers, i.e. private. So every member of an extension block had an effective accessibility of private, and SA1600 and the other documentation rules that useNeedsCommentnever required documentation on public extension members such aspublic int Length => source.Length;in apublic static class.Fix: an extension block now reports
Accessibility.Publicas its declared accessibility. The block doesn't restrict its members, so their effective accessibility is their own modifier combined with the containing static class's accessibility. The extension block itself still doesn't need documentation, because SA1600 doesn't register forExtensionBlockDeclaration. That matches @bjornhellander's fork (bjornhellander/NewStyleCopAnalyzers#30) testTestExtensionBlockDeclarationAsync. Only the documentation rules call these helpers. SA1202 uses its ownMemberOrderHelperaccess levels and is unaffected.Behavior change (please review)
documentInternalElements/documentPrivateElementsas usual). Before this, they were silently treated as private.NeedsComment(for example SA1611/SA1615/SA1618 when documentation is required) now treat extension members as exposed.Tests
C# 14 (
[WorkItem(4023)]): in a public static class, public, static and internal extension members are reported and private ones aren't. In an internal static class, a public member is reported (internal effective accessibility, defaultdocumentInternalElements: true).Local: all DocumentationRules tests pass on C# 14 apart from the known Linux CRLF code-fix failures.
Not in this PR (decision for Andrew): ordering rules (SA1201/SA1202/SA1204) still don't look inside extension blocks, e.g. private before public members, or instance before static extension members.