Automatically Create a .cs file from a class in Visual Studio 2010

Viewed 13260

I often code in such way that I put several classes in one cs file to get my code going and then at some point, I want to move every class to a seperate .cs file within my C# project but I have to do this manually by creating a file for every class and cut and paste the class to the new file and then resolve the required namespace one by one for each file. No Fun!

Is there a way to just click right on the class and make visual studio to automatically move the class to a new file under the project tree? I mean, would you please provide such Macro/Snippet(or whatever it is called :) ) and instructions on how to add it to Visual Studio 2010?

4 Answers

Visual Studio 2017 now has Code Refactoring that includes Moving a class into its own file.

  • For example you can either right click on the class "Foo" and select "Quick Actions and Refactorings" (or the shortcut Ctrl +)
  • Then select "Move type into foo.cs"
Related