Visual Studio C# statement collapsing

前端 未结 12 1898
闹比i
闹比i 2020-11-30 17:23

When editing really long code blocks (which should definitely be refactored anyway, but that\'s beyond the scope of this question), I often long for the ability to collapse

相关标签:
12条回答
  • 2020-11-30 18:03

    Starting with Visual Studio 2017, statement collapsing is built-in.

    There are several extensions that perform this task for pre-2017 versions of VS, starting with VS 2010 version:

    • C# outline
    • C# outline 2012 (@MSDN)
    • C# outline 2013 (@MSDN)
    • C# outline 2015 (@MSDN)
    • Visual Basic and C# Outliner

    The last extension supports only VS 2015 and VS 2017, but it's the most powerful one.
    It supports syntax coloring inside collapsed blocks, it is more fault-tolerant and optimized.

    If the extension doesn't seem to install after you used a browser to download it, try using the built-in Visual Studio extension manager.

    0 讨论(0)
  • 2020-11-30 18:05

    In Visual Studio 2019, if you want to collapse braces in catch & finally, collapse switch, case, default, collapse multiple lines of comments, etc.

    Try to use C# outline 2019

    0 讨论(0)
  • 2020-11-30 18:07

    # region ,#endregion is the smart option.

    0 讨论(0)
  • 2020-11-30 18:10

    You can collapse specific blocks of text within visual studio, but you have to turn off automatic outlining.

    Right click in your code window and select (Outlining | Stop Outlining)

    Then, select some text, right click and select (Outlining | Hide Selection)

    When you turn on automatic outlining again, your custom "Regions" will no longer collapse.

    0 讨论(0)
  • 2020-11-30 18:12

    Visual Studio 2008 supports regions inside of functions as long as you keep them in the same code hierarchical level

    #region Won't work
    for(int i = 0; i<Count; i++)
    {
    //do something
    #endregion
    }
    
    for(int i=0; i<Count; i++)
    {
    #region Works fine
    //do lots of stuff
    #endregion
    }
    
    0 讨论(0)
  • 2020-11-30 18:12

    Let me say something different: press(ctrl+m,ctrl+h) or in edit>outlining>hide selection its so useful.

    0 讨论(0)
提交回复
热议问题