简体   繁体   中英

Visual Studio/ReSharper code formatting - C#

When creating a new type using the object initialiser syntax, Visual Studio automatically moves the braces to align with the type after the new keyword.

Like this

MyType myType = new MyType
                    {

                    };

However, I would prefer it not to do this and instead leave it like so

MyType myType = new MyType
{

};

Any ideas how to do this - I've been through all the Visual Studio formatting options and can't find one that is appropriate

Any ideas?

From my most popular answer here:

  1. In Braces Layout , set Array and object initializer to At Next line (BSD Style) .
  2. In Other , make sure that Continuous line indent multiplier is set to 1 .
  3. In Other , make sure that Indent array, object and collection initializer block is unchecked .

You will have the style that you want!

You will find this in Resharper options. Go to ReSharper -> Options -> C# -> Formatting Style -> Braces Layout -> "Array And Object Initialization" . But I am not sure if ReSharper allows such formatting.

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