Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic way to put all classes in separate files [duplicate]

I've started to refactor/clean up big project. Some of files contains few small classes or few enums (yeah, it is very messy;/ ).
Is there some method or tool to automatically divide files with few enums/classes and create separate files for each of them?

As Fredrik Mörk said - Resharper is very good tool and has possibility to do what I need. But of course as almost all good tools it costs (for one it is cheap, for another not:) ).

Maybe there is some free tool for such simple refactoring? (my boss will not pay for Resharper - he told me that I need 'hammer' not a whole workshop:) )

like image 689
Marek Kwiendacz Avatar asked Mar 01 '11 12:03

Marek Kwiendacz


People also ask

Can you create separate classes as separate files?

Of course you can separate out 2 classes and still they will work fine. Just make sure you import one class in another using import statement. All you need to do is move AnotherClass class into a separate source file named with name same as class name ie "AnotherClass.

Can you have multiple classes in a CS file?

As Paolo said,there is no benefit keeping many classes in a single file. Putting them in separate files will help you and any other programmer to find the cs file for a class quickly. By all that is right in the world, yes, it is correct!


2 Answers

Resharper has a refactoring that moves a type to a separate file. Might be that it can be applied on a higher level (as project); don't have it installed on this machine to verify though.

Edit: noticed in the online help that there is a refactoring called Move Types Into Matching Files that does exactly what you are asking for.

like image 76
Fredrik Mörk Avatar answered Sep 28 '22 08:09

Fredrik Mörk


CodeRush xpress (free) also supports Moving a type into a matching file

enter image description here

like image 28
Eduardo Molteni Avatar answered Sep 28 '22 09:09

Eduardo Molteni