[Rider C# Code Style] - Single argument lambda expressions

My current Code Style formats the code as below:

 

When the method invocation takes a single argument lambda expression, I would like to have my Code Style configured to format the code like below:

 

Is this currently possible in Rider (2020.3 EAP 10), and if so, which Code Style settings do I have to change to achieve this outcome?

2
3 comments

Hi Nillerr

Please, try to play with File | Settings | Editor | Code Style | C# | Braces Layout | Lambda and delegate (anonymous method declaration) setting. I hope this helps! Let me know if you have any other questions. 

0

Hi Alexandra Guk

Thank you for responding to my inquiry. I should have specified that I have already played around with any and all Code Style settings I could find which change the formatting of these invocations, including the one you mentioned, and only after reaching the conclusion that achieving formatting such as what I presented in the second screenshot is impossible (while retaining other preferences for other invocations that do not match this criteria) with current options available in Rider, I went ahead and made this post, albeit I did leave it rather sparse of details.

I also forgot to mention that what I am specifically looking for is to have this kind of Code Style apply exclusively to method invocations with a single argument in the form of a multi-line lambda expression.

This Code Style specific to single-lambda-expression-argument method invocations is prevalent in Microsoft's documentation for ASP.NET Core (e.g. Add and configure Swagger middleware and App startup in ASP.NET Core)

Update

I have determined that the settings Prefer wrap after "(" in invocation and Prefer wrap before ")" in invocation under FIle | Settings | Editor | Code Style | C# | Line Breaks and Wrapping | Arrangement of invocations are what ends up controlling this behavior, and disabling those settings produces the desired result, but prevents me from having a different style applied to invocations which have multiple arguments expanding beyond my configured 120 character Hard wrap at setting, for which I prefer to have both of the aforementioned settings enabled.

1

Hi Nillerr

Unfortunately, this is not possible now. We have a feature request for such setting: RSRP-467905. You can upvote it and follow to be notified about updates. 

Thanks! Should you have other questions, let us know. 

1

Please sign in to leave a comment.