Is there a tool that can run through a visual studio solution and adjust access modifiers to anything not being called in the solution is converted to private or internal where applicable?
I suppose I could just change everything to private, and then use the compiler messages and do it by hand...but that could take a while, if there was something automatic, that would be fantastic!
Simply put, there are four access modifiers: public, private, protected and default (no keyword).
Access modifiers in C# are used to specify the scope of accessibility of a member of a class or type of the class itself. For example, a public class is accessible to everyone without any restrictions, while an internal class may be accessible to the assembly only.
Access modifiers are object-oriented programming that is used to set the accessibility of classes, constructors, methods, and other members of Java. Using the access modifiers we can set the scope or accessibility of these classes, methods, constructors, and other members.
You need the access modifiers in order to control the accessibility of the methods/members. The moral is you should limit the accessibility to private as possible but still you cannot make all of them private.
With NDepend you can analyze your code for stuff like this. It has a SQL-like query language where you can select all the members that are public and could be internal or private, like this:
SELECT METHODS WHERE CouldBeInternal
SELECT METHODS WHERE CouldBePrivate
EDIT: See this blog post about Optimal Encapsulation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With