-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Members of internal types should not be public #13436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Autofix GU0073: Member of non-public type should be internal. https://github.com/GuOrg/Gu.Analyzers/blob/master/documentation/GU0073.md
|
From #13425 (comment): Generally I personally prefer public methods on internal and private classes; a class/object has a public API and private methods, internal implies a secondary API and muddies thinking around the cohesion and contract around a class. More than that, keeping members However, in PowerShell there is a consideration that once you have an object, any public member on it is visible to PowerShell (even if the class itself is internal), which drives a lot of the other classes that have internal members on everything. So there is an externally appreciable difference between an internal type with public members and an internal type with internal members. While we don't consider an internal change like that to be breaking, it's still a change that could affect users. |
If you say about reflection it is never public contract. |
Agreed. My question is that there's a change being made, but for what benefit? It's not a public contract, but it may still complicate things for users. I would want to see a positive effect in exchange for that. |
|
This PR will require more effort before it can be built successfully. I think the only benefit is in code review (easy to verify a method is not public API), so if this change could affect users I think it may not bring value. I wonder what other maintainers think. Once we have made a decision we could consider documenting in our coding guidelines. |
|
In my opinion, it is better to follow the principle of minimum visibility. |
|
Echoing @rjmholt's point, I see a lot of members "accidently" surfaced to PowerShell like this. Say you have an API like this: public abstract class Food { }
internal class Apple : Food
{
public int SeedCount { get; set; }
}
public static class Store
{
public static Food GetFood()
{
return new Apple();
}
}If you call I took a quick glance over some of the changes and pretty quickly found one example of this, the formatting objects like |
PR Summary
Autofix GU0073: Member of non-public type should be internal.
https://github.com/GuOrg/Gu.Analyzers/blob/master/documentation/GU0073.md
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.