Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, October 7, 2016

Visual Studio C# statement collapsing

Visual Studio C# statement collapsing


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 statement blocks like one can collapse function blocks. That is to say, it would be great if the minus icon appeared on the code outline for everything enclosed in braces. It seems to appear for functions, classes, regions, namespaces, usings, but not for conditional or iterative blocks. It would be fantastic if I could collapse things like ifs, switches, foreaches, that kind of thing!

Googling into that a bit, I discovered that apparently C++ outlining in VS allows this but C# outlining in VS does not. I don't really get why. Even notepad++ will so these collapses if I select the C# formatting, so I don't get why Visual Studio doesn't.

Does anyone know of a VS2008 add-in that will enable this behavior? Or some sort of hidden setting for it?

Edited to add: inserting regions is of course an option and it did already occur to me, but quite frankly, I shouldn't have to wrap things in a region that are already wrapped in braces... if I was going to edit the existing code, I would just refactor it to have better separation of concern anyway. ("wrapping" with new methods instead of regions ;)

Answer by Kon for Visual Studio C# statement collapsing


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    ...    

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.