Search code examples
c#riderbraces

Rider auto-insert braces like Java


I'm a real Java guy so C# isn't far from my comfort zone, but what really is is the way Rider auto-completes my curly braces. In java I've always learned the convention to be the following:

public void thisIsAnExample() {
}

Rider, however, inserts braces like this:

public void thisIsAnotherExample()
{
}

What setting should I change for this? I already dug through the Jetbrains Rider documentation but it doesn't seem to say what I'm looking for.


Solution

  • Whilst I suggest you embrace the C# style for C#, as it will help you differentiate between C# and java/javascript, the way to manage these types of behaviors universally between IDEs is with EditorConfig

    @RetiredNinja posted a direct reference to the Rider EditorConfig docs

     # Java style braces on the same line
     [resharper_]csharp_brace_style = end_of_line
     [resharper_]csharp_type_declaration_braces = end_of_line
     [resharper_]csharp_empty_block_style = together_same_line
     [resharper_]type_declaration_braces = end_of_line
     [resharper_]brace_style = end_of_line
     [resharper_]empty_block_style = together_same_line
     
    

    If you choose not to use the EditorConfig file, then you can edit the Rider IDE settings directly

    Settings Menu > Editor > Code Style > C#

    The power of EditorConfig is two-fold:

    1. You can define global default code styles for your workstation across all languages that you use, in all IDEs.
    2. You can define Solution/Project/Folder level defaults within your code and check that file into your source code repository to keep the style in sync for all members of your team, you can set this to override any local workstation or IDE settings and this will prevent the needless code diffs caused by different style rules.