Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Resharper breaking line after method opening brace and how to prevent it?

Tags:

c#

resharper

I've been using Resharper 2016 with Visual Studio 2015, and I had code formatted like this:

list.Add(new SomeClass
{
    Value = 1,
    Name = "some name"
});

And life was beautiful...

But after updating to Visual Studio 2017, and to Resharper 2018, suddenly after hitting ctrl + E + C, and performing built-in R# option "Reformat code", I got this:

list.Add(
    new SomeClass
    {
        Value = 1,
        Name = "some name"
    });

Which is terrible, because I usually want indentation only after {. The only exception being single line statement like 1-liner if, where I sometimes skip the curly brace but still have indentation.

I've tried to switch all possible R# options to "simple wrap" but it didn't help. I've tried to set different values, where it made sense for me, but still no success.

Only after switching "revert to old formatting engine" it helped, but it also break other things, so that is not a viable solution for me.

like image 258
Lech Osiński Avatar asked Oct 17 '22 17:10

Lech Osiński


1 Answers

If you select code and invoke with Alt+Enter "Format selection -> Configure", you'll see list of settings which affect formatting of this selection. If you still have problems, you can reset settings in menu "ReSharper->Manage Options" p.s. try uncheck "Line breacks and wrapping -> Arrangement of initializers -> prefer wrap after ( in invocation"

like image 157
WinnieThePoooh Avatar answered Oct 20 '22 12:10

WinnieThePoooh