質問

I have found other duplicates of this question, but they are very old and the solutions are not applicable to R#8, because the settings have changed.

When I do anonymous type or object initialization (any kind of curly brace indentation with content), I want it to be BSD style:

var test = new CustomType
{
    Prop1 = value1,
    Prop2 = value2,
};

...and I set R# Options / Code Editing / C# / Formatting Style / Braces Layout / Array and object initializer to "At next line (BSD style)". However, when I hit enter after adding a new curly brace, I still end up with this:

var test = new CustomType
           {
               Prop1 = value1,
               Prop2 = value2,
           };

...which I believe is Whitesmiths style.

What do I need to do to get R# 8 to not indent braces for initializers?

役に立ちましたか?

解決

There are two settings that together govern this:

  • Array, object and collection initializers: false

Option1

  • Array and Object Initializer: BSD Style

Option2

Update from OP

These settings may have to be set for "This Computer", not just for personal or team-shared options.

他のヒント

In my case, I followed the instructions in the accepted answer, and ReSharper was still not formatting the object initializers the way I expected (or the way the answer said it would). After much experimentation, I found that the settings from the StyleCop Extension were driving the formatting instead of those in the team-shared settings file. I had to disable the StyleCop Extension settings layer in order for the desired formatting to occur.

Here's a screenshot from the ReSharper --> Manage Options menu: ReSharper Settings Layers

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top