How to stop ReSharper removing spaces in object initializer

独自空忆成欢 提交于 2019-11-29 10:36:49

问题


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?


回答1:


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




回答2:


On Resharper 2019.1

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

And adjust this to your liking:

Preserve Existing Formatting | Extra spaces inside

Also, be sure to use this command shortcut:

ReSharper.ReSharper_ReformatCode, not this Edit.FormatDocument



来源:https://stackoverflow.com/questions/3280361/how-to-stop-resharper-removing-spaces-in-object-initializer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!