Visual Studio C# statement collapsing

前端 未结 12 1896
闹比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 17:47

    I will add here that in VS 2010 Microsoft has added WPF adorner capabilities using Managed Extensibility Framework (MEF), this will allow us to extend the source code editor to organize them in a much better way to make it more readable and accessible.

    For instance the Summary Comments visualizer that Scott Gu demoed at PDC 2008.

    So look forward to a better tomorrow for developers :)

    0 讨论(0)
  • 2020-11-30 17:54

    I have found this for Visual Studio 2013 and found it very helpful. It works even if you put simple braces around your code with { ..... }

    After sharing I found somebody else also mentioned this link. My vote is for this tool also.

    C# Outlining Tool for Visual Studio 2013

    0 讨论(0)
  • 2020-11-30 17:57

    I'm not aware of add-ins, but you mentioned regions and I see nothing wrong with doing something like this...

    foreach (Item i in Items)
    {
      #region something big happening here
      ...
      #endregion
    
      #region something big happening here too
      ...
      #endregion
    
      #region something big happening here also
      ...
      #endregion
    }
    

    EDIT: In response to the question's EDIT: You're right, sticking a bunch of regions everywhere isn't ideal and refactoring is probably the way to go. But it seems that you're looking for something magical that will "organize" the code for you, and I don't think that exists.

    0 讨论(0)
  • 2020-11-30 17:58

    In VS2017 you can highlight a section of code, right-click, Outlining > Hide selection. This will collapse the code and provide a toggle to the section highlighted.

    0 讨论(0)
  • 2020-11-30 17:59

    Coderush will outline all code blocks for you. Not sure if it allows you to expand/collapse the blocks, but outlining is the next best thing. I use resharper instead of coderush which as far as I know doesn't provide block collapsing either :(

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

    This feature has been added to Visual Studio 2010's C# editor. I can't find the source verifying it was actually put in, but I remember seeing it on one of the Dev 10 team member blogs talking about changes since Beta 1 or something. As a consolation, here's one Microsoft comment suggesting they wanted to add it.

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