16

This seems like it should be really simple to do but I just can't figure it out. I want to allow Visual Studio to keep auto formatting my code as it is, except for this part:

public SomeClass : BaseClass {
    public SomeClass() 
        : base()
    {

    }
}

Why can't I have it look like this instead:

public SomeClass : BaseClass {
    public SomeClass() : base() {

    }
}

I looked through Tools -> Options -> Text Editor -> C# -> New Lines and can't find it. Is there a way I can change it to allow auto formatting and my second example?

Kredns
  • 36,461
  • 52
  • 152
  • 203
  • I'm guessing is does that so that when you have a wide class definition the call to the base constructor is not hidden 'off screen' – Mitch Wheat Jun 21 '09 at 02:39

3 Answers3

5

AFAIK there is no way to prevent Visual Studio from doing this.

xian
  • 4,657
  • 5
  • 34
  • 38
4

Are you sure that unchecking:

Options -> Text Editor -> C# -> Formatting -> New Lines -> Place Open Brace on new line for types

doesn't do what you want?

and also uncheck

Place open brace on newline for methods.

(nvrmind.. I see what you are getting at... It is annoying)

GrendleM
  • 350
  • 2
  • 9
  • 2
    Those don't do it for me in VS2013. I've tried a bunch of those settings but no luck as yet. See here: http://stackoverflow.com/a/17477948/1061602 – Adam Marshall Jun 11 '14 at 14:55
0

You purchase ReSharper and use that for all of your formatting, you can set it up exactly how you want it =)

Jon Erickson
  • 112,242
  • 44
  • 136
  • 174
  • 1
    +1 Why the down votes? That is an excellent answer, seeing as M$ VS insists on formatting your code one way or another, rather than allowing Your Code to be left exactly in the format that you (as it's User god Master Overlord, infintely superior Being) proceeded to write it down. – Reversed Engineer Nov 13 '15 at 10:35
  • 1
    yup, set the tooling to do the formatting just the way you want it, share the format rules with the team and no formatting issues. – Jon Erickson Nov 14 '15 at 01:36
  • 2
    Gets down voted because the answer is solved by "throwing money" at the problem. ReSharper is not free and not all IT departments have the budget to buy every little tool that might be useful. The price tag is very hefty. Starting at $300 per year! http://www.jetbrains.com/resharper/buy/#edition=commercial – Paul Gorbas Jan 22 '18 at 22:28
  • 1
    you mean the same IT department that purchased everyone Visual Studio / MSDN licenses? my first job wouldn't purchase me a license as well, i ended up buying a personal license because my sanity was that valuable. – Jon Erickson Jan 23 '18 at 17:34