After namespace
, class
, struct
, enum
, for
, foreach
, while
, switch
, do
, using
, unchecked
and at the beginning of methods, shouldn't Visual Studio automatically include curly brackets? How to activate this feature?
views:
495answers:
5With Resharper curly closing bracket adds by itself (either right away or after pressing enter). I think it's also the case for non-resharped Visual Studio but not 100% sure about that. Only opening bracket you have to write by yourself.
Currently Resharper 5.0 is free (as long as it's in beta/night build status), you just have to reinstall it every 20-30 days (but you would want to do it anyway since they tend to fix/add things). I can't code without Resharper anymore :-) It's so much time saver! Not sure what i will do when it's no longer beta ;/
Edit:
With Resharper you can even get IDE to use braces or not to use them in some cases (where it's possible). Check out this link about code formatting in Resharper.
For namespace, class, struct, enum and switch, you're right. The syntax forces you to get an opening brace, but I don't think you can force VS to do this (without using an add-in).
In the other cases, an open brace is optional, and some people want NOT to have the brace if they have only one statement afterwards. So, VS could not add a brace automatically even if it could.
The IDE can't be sure if you don't want to create a one liner.
Resharper does make things easier though. If you type "{" and press enter the "}" will automatically be generated.
One option is to use Code Snippets. Visual Studip already comes with snippes for namespace, enum, for, foreach, while, switch, do, using, and unchecked. For instructions on how to use snippets go here.
If you can think of a snippet that makes sense for you for class and struct you can create your own snippet.