How to collapse If, Else, For, Foreach, etc clauses?

C#Visual StudioVisual Studio-ExtensionsClause

C# Problem Overview


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!

C# Solutions


Solution 1 - C#

Try this plugin (C# Outline Extension):

Solution 2 - C#

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.

Solution 3 - C#

I use 2 Extensions:

C# outline 2013

and

Indent Guides

Solution 4 - C#

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 )

Solution 5 - C#

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMoslem Ben DhaouView Question on Stackoverflow
Solution 1 - C#TWTView Answer on Stackoverflow
Solution 2 - C#suregaView Answer on Stackoverflow
Solution 3 - C#Renzo CiotView Answer on Stackoverflow
Solution 4 - C#Hamza_LView Answer on Stackoverflow
Solution 5 - C#JainendraView Answer on Stackoverflow