Repository navigation
Update to support default interface members - #4034
Conversation
Codecov Report❌ Patch coverage is 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:
|
| 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.).
There was a problem hiding this comment.
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.
|
|
||
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
➡️ Would be good to file this as a separate request. It may already exist in the IDE/SDK code style rules.
Fixes #3551
Fixes #3682
Fixes #3717
Closes #3002