Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract all classes into separate file?

I'm using the Resharper trial and VS2008. Is it possible to extract all classes from one file into a separate file? I'm able to do this using Resharper but it only seems to work for individual classes. This is to be used on a file that was auto-generated that is 65,000 lines long.

like image 313
Mike Avatar asked Jul 29 '10 19:07

Mike


People also ask

How do you split a class into multiple files in Python?

Probably the most common approach to spreading a class's code over multiple files is to use subclassing, with the base class in one module, and the (or each) subclass, in its own separate module.

Should each class be in a separate file?

It is good practice to do so. You can easily find the class if you name the file after the class.

How can we make a class extract?

Press Ctrl+Shift+R and then choose Extract Class. Right-click and choose Refactor | Extract Class from the context menu. Choose ReSharper | Refactor | Extract | Extract Class… from the main menu.

Can you have multiple classes in a CS file?

Unlike Java, C# allows you to write multiple classes in a single source file.


1 Answers

In addition to Scott's solution, there's a free refactoring tool in Visual Studio Marketplace called Move Type to File.

It can bulk move types to their own separate files, like so:

It also provides a quick shortcut to move a type highlighted by the cursor (default Ctrl + Shift + F1).

Saved me a LOT of manual work...

like image 157
fhcimolin Avatar answered Oct 03 '22 02:10

fhcimolin