45

I like my object initializers to look like this:

new Point { Label = g.Key.Name, Claims = g };

When hit the semicolon key, they get reformatted like this:

new Point {Label = g.Key.Name, Claims = g};

Where is the option to stop my padding from being removed?

Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
  • I don't care which way mine look, but StyleCop punches me in the teeth if they don't look the first way. **Hates StyleCop** – Keith Pinson Jun 12 '13 at 12:37
  • This also worked for the removing spaces R# adds after casting. This was causing a lot of churn in code files where R# code cleanup and VS Reformat Document were being used. – StingyJack Feb 23 '16 at 19:45

2 Answers2

82

For R# 7, I can get this to vary by going to1

ReSharper | Options | Code Editing | C# | Formatting Style | Spaces

and toggling

Other | Within single-line initializer braces

the example for which is

int[] x = new int[] {0, 1, 2};

versus

int[] x = new int[] { 0, 1, 2 };

Although the example is of array initialization, it also appears to control object initialization.


1In R# 5, "Code Editing" was "Languages".

AakashM
  • 62,551
  • 17
  • 151
  • 186
  • Thanks freakin god, this was driving me insane.. resharper kept removing spaces from my CSS formatting.. Edit: nvm cant find the right option – Camathon Sep 09 '14 at 14:17
  • 7
    Seems this option has been moved from 'Other' to 'Around Braces' – Gaute Løken Mar 27 '18 at 14:39
  • 2
    Seems this option has been renamed: `Spaces | Around braces | Within single-line expression braces` Or add it directly to the .DotSettings file: `False` – pschlz Jul 15 '22 at 08:52
7

If you are using an .editorconfig file, you can control this behaviour by adding:

space_within_single_line_array_initializer_braces = true

See also the official resharper documentation on supported .editorconfig entries. These typically let you customize everything you could customize from the formatting styles menu for all of Jetbrains' IDEs.

Felk
  • 7,720
  • 2
  • 35
  • 65