Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Cleanup - tool to move all using statements inside namespace in all cs files in my solution?

After writing a whole bunch of code - i am finally waking up to adding CA and StyleCop to my solution.

By default all files (a lot of them) in my solution have using statements at the top of the file before the namespace.

I have resharper 6.0 and powertools in visual studio. Is there a way using these or any other tool that will go through all my CS file in the solution and put the using statements inside the namespace for each file.

like image 666
MoXplod Avatar asked Nov 17 '11 00:11

MoXplod


People also ask

What does code clean up do?

Code cleanup refers to the act of writing code so that it cleans up leftover data structures and other unwanted materials from memory and the filesystem. It is sometimes treated as a synonym of refactoring code, which involves making the source code itself easier to understand, maintain, and modify.

How do you code cleanup?

You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

How to run ReSharper code cleanup?

Select ReSharper | Options from the main menu or press Alt+R O . Go to the cleanup profiles settings page: Code Editing | Code Cleanup | Profiles. Select which Code Cleanup profile should be applied on save and click Set as default (the default profile is also used for silent cleanup).


2 Answers

With Resharper it can be done in two steps.

  1. Set the checkbox "Add 'using' directive to the deepest scope" in Code EditingC#Code StyleReference qualification. Options v9

  2. In the context menu of the solution choose "Cleanup Code...". SLN context menu

You might want to create a custom cleanup pofile that suits your needs before performing the cleanup.

In ReSharper before v9 the setting is located somewhere else: Options v8

like image 131
Gebb Avatar answered Oct 06 '22 01:10

Gebb


In ReSharper 10 you can find it in: enter image description here

like image 21
Diomedes Domínguez Avatar answered Oct 06 '22 00:10

Diomedes Domínguez