C# code style - closing parentheses at method declaration
Given a code like this:
public async Task<ActionResult<CreateNewResponse>> Post(
[FromBody] CreateNewRequest query,
CancellationToken cancellationToken
)
{
var response = await Mediator.Send(query, cancellationToken);
return Ok(response);
}I want it to be formatted like this, the closing parentheses for the method parameters at the end of line:
public async Task<ActionResult<CreateNewResponse>> Post(
[FromBody] CreateNewRequest query,
CancellationToken cancellationToken)
{
var response = await Mediator.Send(query, cancellationToken);
return Ok(response);
}Where is this set in the Code Style setting?
Please sign in to leave a comment.
Hi Farid,
Try with the below settings. In
Settings | Code Style | C# | Line Breaks and WrappingIn
Arrangement and Method Signaturesection:Prefer to wrap after '(' declarationPrefer to wrap before ')' declarationKeep existing arrangement of parenthesis in declarationIn
Generalsection:Keep existing line breaksselected.Press
Ctrl + Alt + Fto format code, you should be able to see the expected changes now.Regards,
Tao
Thanks Tao, that works! Is there similar setting for angle brackets too ("<" and “>”)?
In my team, there's people that came from TS background, so they use this out of habit:
public class SomeHandler: IRequestHandler<SomeRequest,List<SomeResponse>>{}When it's more natural for C# people to write it this way (notice the closing angle bracket):
public class SomeHandler: IRequestHandler<SomeRequest,List<SomeResponse>>{}Is there a setting for this?
Hello Farid,
The setting for angle brackets you mentioned are not part of Rider's C# Code Styles.
When formatting the code, angle brackets will not be rearranged. You might want to check if your teammates are using .editorconfig to manage IDE preferences and ensure EditorConfig support is enabled in Rider.
You can raise a new feature request on YouTrack regarding this missing feature. While there are several ways to introduce feature requests, I believe your best option would be to use our tracker here. On the tracker, others can view your request and add their votes if they find such a feature useful. This provides valuable feedback to our team, helping us understand which features our users most desire. This approach offers the best visibility for your request.
Please let me know if there's anything else I can assist you with.
Regards,
Tao