Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically Refactor Access Modifiers

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!

like image 785
CaffGeek Avatar asked Dec 07 '09 18:12

CaffGeek


People also ask

What are the 3 types of access modifiers?

Simply put, there are four access modifiers: public, private, protected and default (no keyword).

What is AC access modifier?

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.

What is the purpose of access modifiers?

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.

Are access modifiers necessary?

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.


1 Answers

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.

like image 169
Tommy Carlier Avatar answered Sep 21 '22 10:09

Tommy Carlier