简体   繁体   中英

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 (ie 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?

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM