Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to force resharper to align chained method calls in a specific way

Lets say I have the following code in C#

        var stringList = GetListOfStrings();
        var firstString = stringList.Where(s => true)
                                    .Where(s => true)
                                    .Where(s => true)
                                    .FirstOrDefault();

It doesn't do very much, but it's formatted in the way I like by ReSharper and by Resharpers Code Cleanup feature.

Now lets say I rewrite that code to just call the method GetListOfStrings without assigning it to a variable first. In this situation Resharper formats it as follows:

            var firstString = GetListOfStrings()
                .Where(s => true)
                .Where(s => true)
                .Where(s => true)
                .FirstOrDefault();

Is there anyway to change this so ReSharper formats it as below instead?

            var firstString = GetListOfStrings().Where(s => true)
                                                .Where(s => true)
                                                .Where(s => true)
                                                .FirstOrDefault();

I'm using the ReSharper 8 Beta and VS 2013 preview if it makes any difference.

like image 971
Jamie Wroe Avatar asked Jul 09 '13 19:07

Jamie Wroe


2 Answers

I think you're looking for the "Chained Method Calls" option under the "Align Multiline Constructs" header here:

enter image description here

like image 97
jessehouwing Avatar answered Sep 28 '22 10:09

jessehouwing


With Resharper, you can use the following options:

Code Editing->C#->Formatting Style->Line Breaks and Wrapping->Line Wrapping->Wrap chained method calls to Chop always

and

enable Code Editing->C#->Formatting Style->Other->Align Multiline Constructs->Chained method calls

like image 37
Piers Myers Avatar answered Sep 28 '22 08:09

Piers Myers