Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop ReSharper removing spaces in object initializer

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?

like image 579
Nathan Ridley Avatar asked Jul 19 '10 10:07

Nathan Ridley


2 Answers

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".

like image 136
AakashM Avatar answered Oct 22 '22 23:10

AakashM


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.

like image 33
Felk Avatar answered Oct 23 '22 00:10

Felk