70

I get stuck sometimes with very long clauses and I am looking for a way that allows me to collapse them, same way as I can collapse classes, methods and namespaces by default.

Is there a Visual Studio extension that does that? neither ReSharper nor JustCode does allow it.

Thank you!

Makyen
  • 31,849
  • 12
  • 86
  • 121
Moslem Ben Dhaou
  • 6,897
  • 8
  • 62
  • 93

5 Answers5

131

Try this plugin (C# Outline Extension):

TWT
  • 2,511
  • 1
  • 23
  • 37
45

Visual studio IDE gives an option to outline the if, for, foreach, while, switch case etc.

Just go to Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > View and set Outline Statement Blocks to true.

In Visual Studio 2012+, the path is Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > Formatting.

Moslem Ben Dhaou
  • 6,897
  • 8
  • 62
  • 93
surega
  • 707
  • 7
  • 15
22

I use 2 Extensions:

C# outline 2013

and

Indent Guides

Renzo Ciot
  • 3,746
  • 2
  • 25
  • 29
17

select the code you want to collapse and then press ctrl+M,ctrl+H. to disable it, press ctrl+M,ctrl+U, you can also right click on the selection, and there "Plan Mode" ( I'm not sure my VS is french )

Hamza_L
  • 644
  • 4
  • 18
1

You can use #region for collapsing if, else, for and other similar clauses.
Example:

#region foreach
foreach(/*conditions*/) 
{
    statement 1;
    statement 2;
    ..
    statement n;
}
#endregion

Now for collapse all use the shortcut ctrl+M,ctrl+O.

Jainendra
  • 24,713
  • 30
  • 122
  • 169
  • 3
    I don't think this a nice option, regions are there because code is hard to manage and move around, and since they don't make code look good enough I use this extension: [I Hate #Regions](https://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca) – mkb Jun 13 '16 at 12:07