Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1035 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Visual Studio C# statement collapsing

#1
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 ;)
Reply

#2
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
}
Reply

#3
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.
Reply

#4
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][1].

So look forward to a better tomorrow for developers :)

[1]:

[To see links please register here]

Reply

#5
# region ,#endregion is the smart option.
Reply

#6
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.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through