2

I'd like to configure the auto formatting brace styles to my preference. I've looked through all the option and can't quite get it how I like it.

Here is a sample of my preferred format:

if (condition
 && anothercondition
   )
{
  DoStuff();
} else {
  DoOtherStuff();
}

try
{
   DoBadstuff();
} catch (System.Exception ex) {
   FixBadStuff();
} finally {
   CleanUp();
}

So basically the opening brace should be on a newline (which I can do). But the close brace, and any subsequent but related statement, and it's opening brace should all be on a single line. i.e.

} else {

Now I can get this last part - but only if I put the initial opening brace on the same line as well.

Does anyone know any ways to achieve this?

I'm not so bothered about the formatting of && and || within the if - things like this are generally rare enough that it doesn't bother me.

DJL
  • 2,060
  • 3
  • 20
  • 39
  • Resharper (http://www.jetbrains.com/resharper/) has a lot of style formating options, but it's paid tho... – jerone Sep 06 '12 at 10:07
  • 14
    This is a _very_ inconsistent style (sometimes the braces are at the end of the line, sometimes on a new line). I don't believe you can automate this easily with current existing tools. – Oded Sep 06 '12 at 10:11
  • I always prefer my curly braces to be indented from the if/try commands, with the internal code in line with the braces, personal choice of course :) – Paul Talbot Sep 06 '12 at 10:33
  • 6
    HOLY COW that is hard to read. I am sorry but that had to be one of the worst preferences for code style I have EVER seen, I would rather have inline code, then even look at that. I just hope you work alone..... – Security Hound Sep 06 '12 at 11:37

1 Answers1

2

You can't do this... (and personally you shouldn't it's horribly inconsistent)

VS2012 will let you change brace behaviour for entire groups of keywords. (e.g. all control block keywords) but not individual words (i.e. make Try behave differently from catch)

VS2012 Options

Eoin Campbell
  • 43,500
  • 17
  • 101
  • 157