23

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?

danludwig
  • 46,965
  • 25
  • 159
  • 237

2 Answers2

40

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.

danludwig
  • 46,965
  • 25
  • 159
  • 237
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Those are the settings I have, but they were set in the team-shared and personal settings. Turns out I also needed to change it for "This Computer". Is that to be expected? I thought team-shared were supposed to override computer settings? – danludwig Nov 27 '13 at 17:04
  • Some settings, when at their default setting, are not detected by Resharper as Overwritten, you might have been caught by that 'bug'. In most cases, the most specific settings win (solution, team, personal), but it all depends on the order of the settings files found under "Manage Settings" – jessehouwing Nov 27 '13 at 22:09
  • You know I never knew there was an order to these. I see it now, but my Move up and Move down buttons are disabled for it. – danludwig Nov 27 '13 at 22:32
0

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

Pflugs
  • 772
  • 1
  • 10
  • 18