7

I'm looking for a tool which will split a file containing multiple C# classes, so that each class is in its own file. Does such a tool exist?

2
  • Can't find any, but such a tool is not difficult to build by yourself...
    – Bolu
    Oct 22, 2010 at 16:15
  • True, I am considering doing this, but I thought it worth asking as it seems like something that should already be out there. Oct 24, 2010 at 22:36

3 Answers 3

4

In case you are a Resharper (or DevExpress IDE Productivity Tools) user, it has a refactoring that does this. Not sure whether you can have it process the full file as one command, but it's just a couple of keyboard strokes per class, so it can be done manually (unless we are talking hundreds of classes).

3
  • 2
    There is Move Type Into Matching Files available in Resharper as project refactoring which do explicitly @haymansfield asks. Here help: Move Types Into Matching Files bit.ly/c3xCKE Oct 22, 2010 at 16:37
  • @Nick this is one of the most used features of resharper for me. It's hard for me to remember developing without it. Oct 22, 2010 at 17:00
  • @Nick +1, but alas I've plumped for CodeRush! Oct 24, 2010 at 22:38
0

Resharper does this. CodeRush also does this. CodeRush also gives you options to rename the file to match the type, etc.

1
  • I've been using this in Coderush on a singular basis, but does it do it for an entire multiclass file in 1 hit? Oct 24, 2010 at 22:37
-1

Why not cut and paste the classes? Resharper and other tools (possibly even vs2010) can do a Refactor...Move Class, but it that would probably take longer than:

  • Create new file
  • Cut class from original file
  • Paste to new file
5
  • 1
    you could use ctrl+m+o to collapse everything, making the cutting easier :) Oct 22, 2010 at 17:35
  • 4
    I doubt the author of this post is not aware of copy paste. Feb 25, 2011 at 15:33
  • in my case, it's because I'm looking at a generated file that if 5MB big and it would be nice to have a tool which can reliably refactor the code repeatedly. May 8, 2015 at 8:08
  • Ctrl+M+O is great but only collapses contents on classes. Use Ctrl+M+L (twice if required) to toggle collapsing EVERYTHING. Ctrl+M+M will collapse/expand whatever is in focus.
    – Ian
    Oct 12, 2015 at 13:53
  • Anyway, I guess a tool would be preferred as I expect it would repair all broken references
    – Ian
    Oct 12, 2015 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.