Rider Help

Code Style. C#

File | Settings | Editor | Code Style | C# for Windows and Linux
Rider | Preferences | Editor | Code Style | C# for macOS
Ctrl+Alt+S /help/img/rider/2017.1/settings.png


On this page of Rider settings, you can configure various aspects of code style in C#. Code style preferences are grouped in the following tabs:

Tabs and Indents

On this tab, you can specify how Rider should format indents in your code when you type or when you reformat existing code.

Naming

On this tab, you can configure symbol naming rules for C#.

Rider helps you define, control, and apply naming style for symbols in your code. Naming style is implemented as a set of rules, each of which targets specific identifiers with the set of constraints (e.g. a rule can target static private readonly fields). Each rule can have one or more associated styles that define suffixes, prefixes, capitalization of compound words, etc.

These rules are taken into account when Rider suggests symbol names in code completion, generates new members, applies code templates and performs refactorings. Rider also helps you detect and fix violations of naming rules. If necessary, the automatic checkup of naming rules can be configured or disabled.

Code Style

Preferences configurable on this tab affect the behaviour of specific Code Style and Cleanup features. The preferences are taken into account when Rider applies refactorings, code templates or produces generated code. They can also be applied to the existing code by using code cleanup with the corresponding settings.

The preferences with the Notify with selector have corresponding code inspections that notify you if this aspect of the code style in the inspected scope differs from the the preferred style. Using the selectors, you can configure severity levels of the inspections.

ItemDescription
'var' usage in declarations Preferences in this section define how the implicitly typed local variables (also known as var keyword) should be used. You can set different preferences of using 'var' or explicit type for different types:
  • For built-in types - applies to C# built-in types.
  • For simple types - applies to types without generic parameters.
  • Elsewhere - applies to generic types.
For each of these preferences you can opt for using 'var', explicit type, or 'var' when evident, which means that 'var' should be only used for variables initialized as creation of objects, arrays, and literals or explicit casts. For more information, see Code Syntax Style: Implicit/Explicit Typing.
Instance members qualification Preferences in this section define how to use 'this' qualifier. For more information, see Code Syntax Style: Optional Member Qualifiers.
Static members qualification Preferences in this section define how to qualify static members. For more information, see Code Syntax Style: Optional Member Qualifiers.
Built-in type naming The preference in this section defines how to reference C# built-in types: you can either use C# keywords or CLR type names. For more information, see Code Syntax Style: Built-In Type References.
Reference qualification Preferences in this section define the style of namespace imports:
  • Prefer fully qualified references - select this check box if you prefer use fully qualified names rather than namespace import directives for imported types.
  • Add 'using' directive to the deepest scope - if this check box is selected, namespace import directives are added inside the namespace where the imported types are used; otherwise the import directives are added in the top of the file.
  • Prefer fully qualified using name at nested scope - if this check box is selected, fully qualified names for imported types are preferred in nested types and namespaces.
  • Allow using alias directive - selecting this check box allows using aliases in namespace import directives, as opposed to fully qualified namespace names.
  • Allow the 'global::' prefix - if this check box is selected, the global:: prefix are not removed, as in global::System.String. For more information, see How to: Use the Global Namespace Alias.

A number of other options related to namespace imports can be configured on the Code Editing | C# | Namespace Imports page of Rider options.

Modifiers Preferences in this section define how to arrange modifiers of types and members. For more information, see Code Syntax Style: Modifiers.
Arguments Preferences in this section let you define how named or positional arguments should be enforced for specific types of parameters. For more information, see Code Syntax Style: Named/Positional Arguments.
Parentheses Preferences in this section let you define when optional parentheses should be removed or added if they help you clarify precedence of operations. For more information, see Code Syntax Style: Optional Parentheses.
Braces Preferences in this section let you define which statements require braces for single nested statements. For more information, see Code Syntax Style: Braces for Single Nested Statements.
Code body Preferences in this section let you define which kinds of members should be declared with the expression body and which with the block body. For more information, see Code Syntax Style: Bodies of Function Members.
Attributes Preference in this section defines how to arrange multiple attributes. For more information, see Code Syntax Style: Multiple Attributes.

Braces Layout

Use this tab to adjust the way Rider arranges braces when it generates and reformats your code; in particular, there are several ways to position braces after if or for operators.

For every item, there is a preview pane in the bottom part of the page where you can observe changes after tweaking specific preferences.

Blank Lines

This tab lets you configure whether Rider should increase or decrease the number of blank lines around namespaces, members, regions and groups of import directives. You can adjust the values and check the preview pane at the bottom of the page to see how your preferences affect the code.

Options in the Preserve Existing Formatting section are only applied when Rider reformats existing code whereas the Blank Lines section contains options that also take effect when you type new code.

Line Breaks and Wrapping

Use this tab to configure how Rider should add or remove line breaks before/after specific language constructions and whether to wrap long lines exceeding the length specified by the Right margin (columns). Options in the Preserve Existing Formatting section are only applied when Rider reformats existing code while the remaining sections contain options that also take effect when you type new code. You can adjust the values and check the preview pane at the bottom of the page to see how your preferences affect the code.

Spaces

This tab is used to configure automatic insertion/deletion of spaces in certain positions of your source code. You can adjust the values and check the preview pane at the bottom of the page to see how your preferences affect the code.

Other

This tab helps configure a number of additional settings that control how Rider treats new code and reformats existing code. You can adjust the values and check the preview pane at the bottom of the page to see how your preferences affect the code.

Last modified: 11 October 2017