Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Indent chained method calls so they all start at the same position below each other

Consider the following code formatting, taken from this answer.

var query = grades.GroupBy(student => student.Name)
                  .Select(group => 
                        new { Name = group.Key,
                              Students = group.OrderByDescending(x => x.Grade) })
                  .OrderBy(group => group.Students.First().Grade);

Note how the calls to GroupBy, Select and OrderBy all start exactly at the same position / are directly aligned below each other. How can I automatically format my code like this with either Visual Studio directly or using Resharper?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In ReSharper, under Code Editing -> C# -> Formatting Style -> Tabs, Indents, Alignment -> Align multiline constructs, check the Chained method calls box. It takes a bit of time but your really ought to have a thorough look through that Options dialogue.

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading