简体   繁体   中英

How to get Visual Studio 2017 editor to support a different coding style?

The coding style that my employer uses states that the brace { should go on the same line, not the next one. Example:

class bar {
  private void foo() {
      if (1) {
        Console.WriteLine("great");
      } else {
        Console.WriteLine("also great");
      }
  }
}

Visual Studio's default is to place braces on their own line.
How can I get Visual Studio to respect this coding style?

(I don't have 2017, but this is what I see in 2015, so it may be similar.)

Under Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines, there are several options for "Place open brace on new line for <X>" (where X may be "types" or "methods", etc), as well as "Place <X> on new line", where X is "else" or "catch" or "members in anonymous types".

You can check and uncheck these boxes as required to match the style your company sets up.

I believe it is called K&R style. I use JetBrains ReSharper , but it is not free.

在此处输入图片说明

In VS 2017 you can use the following Option; TextEditor -> C# -> Code Style -> Formating -> New Lines:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM