Search code examples
c#resharper

Using ReSharper to format conditional operators in C#


I have been looking at the ReSharper Code Cleanup rules and I seem to have changed how it formats conditional operators and have no idea how to change it back to how it worked before I edited my settings.

What is different is how far it indents the two elements of the conditional operator. Before it used a standard tab indent (i.e. 4 spaces) but now it is indenting the conditional lines much further in.

This is how I want the Code Cleanup to format my conditional operator:

var customerDetails = new CustomerDetails
{
    OrderNo = orderNo,
    Name = user.UseSalutation
-->      ? user.Salutation + " " + user.Surname
-->      : user.Forename,
    Email = user.Email
};

But this is what ReSharper is doing now:

var customerDetails = new CustomerDetails
{
    OrderNo = orderNo,
    Name = user.UseSalutation
--------->      ? user.Salutation + " " + user.Surname
--------->      : user.Forename,
    Email = user.Email
};

What setting do I need to change to tell ReSharper I only want conditional operators to be indented one tab stop?


Solution

  • I've found the option; it's in ReSharper > Options > Code Editing > C# > Formatting Style > Other > Align Multiline Constructs > Expression

    enter image description here