Analyzer proposal: Don't use 'public' on members of internal types
See original GitHub issueOr more generally: “Avoid visibility modifiers that exceed their effect”
Internal types may contain public
members if those members implement interfaces.
Aside from that case, public
members in an internal or private type are in fact not public at all, but internal.
During code reviews seeing an added or changed public
member can set off alarm bells to reviewers who are keen to watch the evolution of a library’s public API. It’s an extra load on them to see public
on a new member only to later realize that the container itself is internal
or private
and thus not worth an API review.
An analyzer should prevent liberal use of public
where internal
would be equivalent.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:15 (9 by maintainers)
Top Results From Across the Web
Analyzer Proposal: Seal internal/private types · Issue #49944
From personal experience actually having implemented an analyzer to warn if classes with no new virtual members and no inheritors aren't sealed ...
Read more >Recruiting Internally and Externally
Employee recruiting is the activity of identifying and soliciting individuals—either from within or outside an organization—to fill job vacancies or staff ...
Read more >Recommended Informed Consent Language for Data Sharing
Language to Avoid. Promises in the informed consent can appear to limit an investigator's ability to share data with the research community.
Read more >Default interface methods - C# 8.0 draft feature specifications
Access modifiers may be used on interface members of all kinds of members that are permitted. The access level public is the default...
Read more >AS 2605: Consideration of the Internal Audit Function
This section provides the auditor with guidance on considering the work of internal auditors and on using internal auditors to provide direct assistance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m concerned the interface implementation limitation would be sufficiently impactful as to undermine the intent of the rule. Other approaches, including but not limited to PublicApiAnalyzer, are superior for tracking changes to the public API surface.
For teams that implement public APIs first as internal types and then move to public types after review, the use of public methods to designate eventual public APIs of the types could be beneficial.
On the other hand, projects that have no public API by design, this has the interesting side effect of becoming a rule that simply reveals interface implementations.
Design questions:
protected
types nested in aninternal
type would have a maximum accessibility ofprivate protected
, which impacts members declaredpublic
,internal
, andprotected
.@AArnott wrote it like this: https://github.com/GuOrg/Gu.Analyzers/pull/217 We can move it here if it is decided that there will be a cop rule for it.