Quickest way to move folder of files to a new namespace?

From a client, I have a large VB project (600+) files, in a single .NET namespace. Groups of related files are in separate folders in the Visual Studio / Solution pane.

Goal: For each folder, move the classes into a namespace with that folder name; E.g. if the main namespace is MyApp, and the folder is Forms, I want all the form classes to be in MyApp.Forms.

I can move the classes one at a time, by opening each file, selecting class name declaration line at top, right-click, Move, enter "MyApp.Forms" as the target, click Next.

Q: Is there any way to speed this up?

Ideally, be able to select multiple classes at same time, then do the Move.

Or some kind of macro, so once I've selected class name, I can hit a key or button to do the Move.

Or a script I can edit, to put the name I'm going to "MyApp.Forms".



NOTE: I did at least figure out to make a single-key keyboard shortcut for Move, and to have the new namespace name in the copy buffer (clipboard), so I can hit ctrl-V. I've got it down now to:

click on name, ctrl-M, ctrl-V, Enter .. and wait
repeat per file



If you'd like to make the namespace structure follow the folder structure,
then there's a helper for that in R#. The "wrong" namespace name has an underline
on it, and a yellow lightbulb that fixes the namespace to match the folder
layout. This refactoring does not asks for the new namespace name. However,
it's still per-file.

It is possible to automate the process by writing a script to execute the
refactoring for each of the classes, but that requires some knowledge of
the R# API.

Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


And you might not be willing to just post such a script? It definitivly is a must have!



Please sign in to leave a comment.