1

I'm trying to improve consistency within my team's codebase and to do this I'm putting together a team-shared R# configuration. However, I find that this codebase prefers this sort of style for embedding lambdas:

services.AddAuthorization(options =>
{
    options.AddPolicy("Foo", policy =>
        policy.Requirements.Add(new Bar()));
});

Whereas ReSharper reformats this code like:

services.AddAuthorization(
    options =>
    {
        options.AddPolicy("Foo", policy =>
            policy.Requirements.Add(new Bar()));
    });

Is there a way I can configure R# to enforce the original style?

Edit

Environment:

  • Visual Studio 2017 (v15.9.10)
  • ReSharper Ultimate 2018.3.4
Tagc
  • 8,736
  • 7
  • 61
  • 114
  • Are you looking for this [option](https://stackoverflow.com/a/13846524/2451726) ? – Arulkumar Mar 29 '19 at 10:17
  • @Arulkumar I saw that earlier, but I think that answer is outdated (my R# only has "revert to old formatting engine" under "Other"). One of the comments under it mentions "Anonymous Method Body" but this option is already unchecked, and it makes no difference if I check it. – Tagc Mar 29 '19 at 10:38
  • Please mention your R# and Visual Studio version in the post. – Arulkumar Mar 29 '19 at 10:51

1 Answers1

0

I believe the option you are trying to find is under:
R# > Options > Code Editing > C# > Formatting Style > Line Breaks and Wrapping > Arrangement of Expression Bodied Members

Nekeniehl
  • 1,633
  • 18
  • 35
  • Thanks, I'll give this a shot tomorrow. – Tagc Mar 31 '19 at 10:41
  • I don’t see any options in that category that seem to help unfortunately – Tagc Apr 01 '19 at 11:52
  • Then I see there is no option to do it. However there is still one option under the same place you should try, which is `Arrangement of Embedded Blocks` – Nekeniehl Apr 01 '19 at 13:25
  • Nothing there either, it even carries on reformatting the code to the style I don’t want after selecting the “keep existing arrangement” option. I’ll probably have to raise a ticket with them. – Tagc Apr 01 '19 at 13:29
  • If that doesn't help maybe an option would be tell to your team by a custom pattern in Code Inspection to change it accordinly to what you want. -> https://www.jetbrains.com/help/resharper/Enforcing_Code_Formatting_Rules.html – Nekeniehl Apr 01 '19 at 13:49