My code has a lot of try, catch, finally blocks. Unlike methods when I am in VS2010 I can't expand or contract these areas to hide the contents while developing except by adding regions.
try {
vm.R...
vm.Qu..
vm.T...
vm.D...
vm.Fil..
vm.Type..
vm.St..
} catch (Exception e) {
log(e);
return Content(ExceptionExtensions.GetFormattedErrorMessage(e));
}
Is there a technique that programmers use to tidy up code within try blocks or do I just have to live with these larger blocks of code.
Fold All (Ctrl+K Ctrl+0) folds all regions in the editor. Unfold All (Ctrl+K Ctrl+J) unfolds all regions in the editor. Fold Level X (Ctrl+K Ctrl+2 for level 2) folds all regions of level X, except the region at the current cursor position.
Expand / Close All Where you see braces or regions in code, you can collapse or expand them with the keyboard shortcut Ctrl + M, P to expand or Ctrl + M, O to collapse.
CTRL + M + O will collapse all. CTRL + M + P will expand all and disable outlining. CTRL + M + M will collapse/expand the current section.
Not available in Visual Basic. (Ctrl+M, Ctrl+M) - Reverses the current hidden or expanded state of the innermost outlining section when the cursor lies in a nested collapsed section. (Ctrl+M, Ctrl+L) - Sets all regions to the same collapsed or expanded state.
Without actually modifying the code, the only thing I know of is to use outlining. You can "hide" a selection which basically creates an outline section that you can expand and collapse just like a class, namespace, method, #if block, etc. To do this:
The selection is now collapsed and you can expand it and re-collapse it any time you want just like a method. (e.g. with +/- glyph at the left or with Ctrl+M,M)
For really clean code, try Extracting Methods, so that your blocks are smaller. And, if it's really necessary, you'll get the automatic code folding from Visual Studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With