Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to easily move whole method blocks around in Visual Studio 2010

I have a program with several methods, however, as I have added new methods, some of them are not in a logical order in their source code files. I was wondering:

  • Is there a way to easily reorder the functions in a file without having to highlight the whole method, and cut-and-paste it into the proper order? For instance, is there some way to see all the methods in a list and just drag the items in the list into a new order?
  • Is there a tool that will analyze my source code and automatically suggest what it thinks is the most logical order for my methods and then will reorder them for me?

I have done done some research on this and the only answer I can find is to use:

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.vclinkertool.functionorder%28v=vs.80%29.aspx

But this tool uses a text document to put the methods in the desired order. Is there any easier way of doing this?

like image 845
StarLordBlair Avatar asked Jul 10 '12 10:07

StarLordBlair


People also ask

How do I minimize all methods in visual studio?

CTRL + M + O will collapse all.

How do I move a block of code up and down in Visual Studio?

Press the shortcut keys to move the line under the cursor up or down or select a block of text and press the shortcut keys to move the entire block up or down. The default shortcut keys are as follows: Alt + ↑ (Up Arrow) – Moves a line up. Alt + ↓ (Down Arrow) – Moves a line down.

How do I move a lineup in Visual Studio?

This keyboard shortcut is new in Visual Studio 2013. If you put the cursor on a line of code and use the Alt+Up Arrow keys, the line of code you've selected moves up.


2 Answers

I am using Resharper for Visual Studio 2015, it moves entire methods up and down with a keyboard shortcut.

ctrl + alt + shift + (up-arrow or down-arrow)

like image 79
nano2nd Avatar answered Oct 13 '22 06:10

nano2nd


If you are just looking for a simple way to cut and paste/drag whole methods in the code editor window, you can do so with the code outlining feature in visual studio.

  1. Select the Edit > Outlining > Collapse to Definitions option in the menu. This will cause all the methods and properties to be displayed as single lines in the editor window.
  2. You can then easily see the order and cut and paste them into the correct order. You can also use the mouse select the whole method line and drag it to a new location in the file.

I've never used ReSharper before, so I can't speak to the actual functionality, but upon searching the web real quick for a better solution than the source code outlining option, I found that ReSharper may support this using their "File Structure" dialog:

http://www.jetbrains.com/resharper/features/navigation_search.html#File_Structure

like image 39
Steven Doggart Avatar answered Oct 13 '22 06:10

Steven Doggart