Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: Collapse Methods, but not Comments (Summary etc.)

is there a way (settings? "macro"? extension?) that I can simply toggle outlining so that only the using section and my methods collapse to their signature line, but my comments (summary and double slash comments) and classes stay expanded?

Examples:

1) Uncollapsed

using System;
using MachineGun;

namespace Animals
{

    /// <summary>
    /// Angry animal
    /// Pretty Fast, too
    /// </summary>
    public partial class Lion
    {
        //
        // Dead or Alive
        public Boolean Alive;

        /// <summary>
        /// Bad bite
        /// </summary>
        public PieceOfAnimal Bite(Animal animalToBite)
        {
              return animalToBite.Shoulder;
        }

        /// <summary>
        /// Fatal bite
        /// </summary>
        public PieceOfAnimal Kill(Animal animalToKill)
        {
              return animalToKill.Head;
        }
     }
}

2) Collapsed (the following is my desired result):

using[...]

namespace Animals
{

    /// <summary>
    /// Angry animal
    /// Pretty Fast, too
    /// </summary>
    public partial class Lion
    {
        //
        // Dead or Alive
        public Boolean Alive;

        /// <summary>
        /// Bad bite
        /// </summary>
        public PieceOfAnimal Bite(Animal animalToBite)[...]

        /// <summary>
        /// Fatal bite
        /// </summary>
        public PieceOfAnimal Kill(Animal animalToKill)[...]
     }
}

This is how I prefer seeing my class files (the collapsed form). I've been doing the collapsing by hand a million times by now and I think there should be a way to automate/customize/extend VS to do it the way I want?

Every time I debug/hit a breakpoint, it uncollapses and messes up things. If I collapse via the context menu's collapse to outline etc. it also collapses my comments which isn't desired.

Appreciate your help!

like image 396
Alex Avatar asked Aug 09 '09 04:08

Alex


People also ask

How do I Collapse All Methods in Visual Studio?

(Ctrl+M, Ctrl+U) - Removes the outlining information for the currently selected user-defined region. Not available in Visual Basic. (Ctrl+M, Ctrl+O) - Collapses the members of all types.

How do you collapse a method in Visual Studio code?

How to Collapse All Source Code in VS Code? To fold all top-level and child elements of your code: Enter the command >fold and hit Enter.

How do I minimize all functions in Visual Studio?

CTRL + M + O will collapse all. CTRL + M + P will expand all and disable outlining. CTRL + M + M will collapse/expand the current section.


2 Answers

Ctrl M, Ctrl O

Collapses to definitions.

From this point a macro might not be too hard to write.

Something like find /// <summary> ... and toggle outlining. Then lather, rinse, repeat.

like image 115
Daniel Elliott Avatar answered Nov 16 '22 04:11

Daniel Elliott


Although this question is old and answered, I was looking for the same thing as question but I think this is the simpler way than writing macro:

Tools > Options > Text Editor > C# > Advanced > Outlining > Uncheck "Show outlining for comments and preprocessor regions" checkbox

If you do that and than use CTRL+M and CTRL+O shortcut, methods will collapse but summaries and regions will remain uncollapsed.

like image 28
Bilal Çam Avatar answered Nov 16 '22 03:11

Bilal Çam