Skip to content

Update to support default interface members - #4034

Merged
sharwell merged 4 commits into
DotNetAnalyzers:masterfrom
sharwell:default-interface-members
Nov 30, 2025
Merged

sharwell merged 4 commits into
DotNetAnalyzers:masterfrom
sharwell:default-interface-members

Conversation

@sharwell

Copy link
Copy Markdown
Member

Fixes #3551
Fixes #3682
Fixes #3717

Closes #3002

@codecov

codecov Bot commented Nov 26, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.23372% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.40%. Comparing base (b72b3f7) to head (59e5c5c).
⚠️ Report is 52 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4034      +/-   ##
==========================================
- Coverage   97.40%   97.40%   -0.01%     
==========================================
  Files         957      959       +2     
  Lines      112852   113104     +252     
  Branches     3389     3405      +16     
==========================================
+ Hits       109929   110167     +238     
- Misses       1933     1942       +9     
- Partials      990      995       +5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread documentation/SA1202.md
Comment on lines +45 to +47
Default interface members (including members with implementations and static interface members) follow the same access
ordering as class members. Within an interface, `public` members should appear before `internal`, `protected internal`,
`protected`, `private protected`, and `private` members.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interface member ordering is not mere style, but is significant when the interface is used as a COM interface.
Should accessibility modifiers and member type sorting rules automatically be disabled when an interface is annotated with attributes typically associated with COM?

@sharwell sharwell Nov 30, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Would a COM interface ever have members with varying accessibility? In the past, this was not an issue because it wasn't possible for a COM interface to break the ordering rules (except perhaps a property? either way, never had a bug for this.).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point. Accessibility modifiers should never be required on a COM interface anyway.

As for properties before methods, yes that requirement would definitely be an issue for COM interfaces, but that's irrelevant to this particular PR.

Comment thread documentation/SA1400.md

This rule requires an access modifier to be explicitly defined for every element. This removes the need for the reader to make assumptions about the code, improving the readability of the code.

Members declared in an `interface` are implicitly `public` and do not need an explicit access modifier. This includes default interface members introduced in C# 8 (instance members with default implementations, static interface members, and nested interface members such as delegates). SA1400 does not report diagnostics for these interface members.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with this point.
I wonder if we should have a rule to discourage adding redundant public access modifiers on interface members when they are all public. I've seen some of these crop up already, and IMO it is more confusing and maybe mis-educating other developers who read it into thinking it's important.

@sharwell sharwell Nov 30, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

➡️ Would be good to file this as a separate request. It may already exist in the IDE/SDK code style rules.

@sharwell
sharwell merged commit f4e1e0c into DotNetAnalyzers:master Nov 30, 2025
@sharwell
sharwell deleted the default-interface-members branch November 30, 2025 22:26
@sharwell sharwell added this to the 1.2-beta.next milestone Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants