Home > Mobile >  VS "format document" setting to respect author's newline choices?
VS "format document" setting to respect author's newline choices?

Time:01-04

Normally my properties look like this ("Version 1"):

    public string Foo {get; set;}

I am fine with this. But sometimes my names get long, and it's not so good ("Version 2"):

    public TypeWithALongName<AnotherLongNameInAngleBrackets> ThePropertyHasALongNameTooAndItsTooWideForTheScreen {get; set;}

When the name gets so long that the line isn't visible on the screen, it's not so good. I'd like to mitigate this by inserting a newline ("Version 3"):

    public TypeWithALongName<AnotherLongNameInAngleBrackets> 
       ThePropertyHasALongNameTooAndItsTooWideForTheScreen {get; set;}

Now I can read it again! I like this. But VS does not. Format Document (control-K, control-D) now changes it to this ("Version 4"):

       public TypeWithALongName<AnotherLongNameInAngleBrackets> 
       ThePropertyHasALongNameTooAndItsTooWideForTheScreen 
    {get; set;}

I want a way to ask VS to respect my newline choices in this area! If I use any of versions 1-4, Format Document should leave it alone. Is that possible?

CodePudding user response:

If you want that behaviour. You can change the following setting. Go to Tools->Options. In the Options List. Navigate to Text Editor -> C# -> Code Style -> Formatting -> New Lines

Uncheck the box for "Place open brace for properties, indexers, and events".

This will give you the behaviour you want.

Checkout editorconfig if you want your styles to be shared with the dev team. EditorConfig in VS 2022

  •  Tags:  
  • Related