Automatically Create a .cs file from a class in Visual Studio 2010
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?
If anyone is looking for a lightweight solution to this problem I found a free Move Type To File extension specifically for this purpose.
http://visualstudiogallery.msdn.microsoft.com/5746c6ea-1f92-43f0-8bab-ec6f8573cd6a
I think Resharper has the functionality you want (plus so much more).
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"
- Ctrl M + M to Collapse the structure you are in (class/interface)
- Ctrl X , cut the collapsed structure
- Shift + Alt + C , make new CS (class file, but also you can use it for interfaces the same)
- Type the name of the Class/Interfaces files into the box
- Copy over the empty class , page Down , shift up arrow , select the class , ctrl V
6.Change the name space if you want ( optional )
This also works with previous and current version (2012) of VS.
精彩评论