C# - Syntax Style
Last modified: 21 July 2022This page lists custom ReSharper EditorConfig properties that you can use for configuring code syntax style rules. Note that some properties apply to one language while others apply to several languages at once. However, for each multi-language property there is a property that can override it for a specific language, for example, default_private_modifier
and . csharp_default_private_modifier
.
tip
ReSharper also supports most frequently used .NET-coding-convention EditorConfig properties.
'var' usage in declarations
For built-in types
Property names:
[resharper_]csharp_for_built_in_types
, [resharper_]for_built_in_types
Possible values:
use_var
: Use 'var'use_var_when_evident
: Use 'var' when evidentuse_explicit_type
: Use explicit type
For simple types
Property names:
[resharper_]csharp_for_simple_types
, [resharper_]for_simple_types
Possible values:
use_var
: Use 'var'use_var_when_evident
: Use 'var' when evidentuse_explicit_type
: Use explicit type
Elsewhere
Property names:
[resharper_]csharp_for_other_types
, [resharper_]for_other_types
Possible values:
use_var
: Use 'var'use_var_when_evident
: Use 'var' when evidentuse_explicit_type
: Use explicit type
Prefer Roslyn (Visual Studio) logic for type evidence
Property names:
[resharper_]csharp_use_roslyn_logic_for_evident_types
, [resharper_]use_roslyn_logic_for_evident_types
Possible values:
true | false
Prefer separate declarations for deconstructed variables
Property names:
[resharper_]csharp_prefer_separate_deconstructed_variables_declaration
, [resharper_]prefer_separate_deconstructed_variables_declaration
Possible values:
true | false
Use 'var' keyword for discards
Property names:
[resharper_]csharp_prefer_explicit_discard_declaration
, [resharper_]prefer_explicit_discard_declaration
Possible values:
true | false
Instance members qualification
Use "this." qualifier for
Property names:
[resharper_]csharp_instance_members_qualify_members
, [resharper_]instance_members_qualify_members
Possible values:
none
field
property
event
method
all
Qualify members declared in
Property names:
[resharper_]csharp_instance_members_qualify_declared_in
, [resharper_]instance_members_qualify_declared_in
Possible values:
this_class
: same classbase_class
: base class
Static members qualification
Qualify with the name of
Property names:
[resharper_]csharp_static_members_qualify_with
, [resharper_]static_members_qualify_with
Possible values:
current_type
: Current typedeclared_type
: Declared-in type
Members to qualify
Property names:
[resharper_]csharp_static_members_qualify_members
, [resharper_]static_members_qualify_members
Possible values:
none
field
property
event
method
all
Built-in types
In locals, members and parameters, prefer
Property names:
[resharper_]csharp_builtin_type_reference_style
, [resharper_]builtin_type_reference_style
Possible values:
use_keyword
: Keyworduse_clr_name
: CLR type name
In member access expressions, prefer
Property names:
[resharper_]csharp_builtin_type_reference_for_member_access_style
, [resharper_]builtin_type_reference_for_member_access_style
Possible values:
use_keyword
: Keyworduse_clr_name
: CLR type name
Reference qualification and 'using' directives
Prefer fully qualified references
Property names:
[resharper_]csharp_prefer_qualified_reference
, [resharper_]prefer_qualified_reference
Possible values:
true | false
Add 'using' directive to deepest scope
Property names:
[resharper_]csharp_add_imports_to_deepest_scope
, [resharper_]add_imports_to_deepest_scope
Possible values:
true | false
Place 'System.*' and 'Windows.*' namespaces first when sorting 'using' directives
Property names:
dotnet_sort_system_directives_first
, [resharper_]csharp_sort_usings_with_system_first
, [resharper_]sort_usings_with_system_first
Possible values:
true | false
Prefer fully qualified using name at nested scope
Property names:
[resharper_]csharp_qualified_using_at_nested_scope
, [resharper_]qualified_using_at_nested_scope
Possible values:
true | false
Use using alias directive to resolve conflicts
Property names:
[resharper_]csharp_allow_alias
, [resharper_]allow_alias
Possible values:
true | false
Allow 'global::' prefix use
Property names:
[resharper_]csharp_can_use_global_alias
, [resharper_]can_use_global_alias
Possible values:
true | false
Modifiers
Prefer explicit/implicit private modifier for type members
Property names:
[resharper_]csharp_default_private_modifier
, [resharper_]default_private_modifier
Possible values:
explicit
: Explicitimplicit
: Implicit
Examples:
Before formatting | After formatting, explicit |
---|---|
|
|
Before formatting | After formatting, implicit |
---|---|
|
|
Prefer explicit/implicit internal modifier for types
Property names:
[resharper_]csharp_default_internal_modifier
, [resharper_]default_internal_modifier
Possible values:
explicit
: Explicitimplicit
: Implicit
Examples:
Before formatting | After formatting, explicit |
---|---|
|
|
Before formatting | After formatting, implicit |
---|---|
|
|
Modifiers order
Property names:
[resharper_]csharp_modifiers_order
, [resharper_]modifiers_order
Arguments
Skip single arguments
Property names:
[resharper_]csharp_arguments_skip_single
, [resharper_]arguments_skip_single
Possible values:
true | false
Literal values
Property names:
[resharper_]csharp_arguments_literal
, [resharper_]arguments_literal
Possible values:
positional
: Positional argumentnamed
: Named argument
Examples:
Before formatting | After formatting, positional |
---|---|
|
|
Before formatting | After formatting, named |
---|---|
|
|
String literal values
Property names:
[resharper_]csharp_arguments_string_literal
, [resharper_]arguments_string_literal
Possible values:
positional
: Positional argumentnamed
: Named argument
Examples:
Before formatting | After formatting, positional |
---|---|
|
|
Before formatting | After formatting, named |
---|---|
|
|
Named expressions (variables, properties, methods, etc.)
Property names:
[resharper_]csharp_arguments_named
, [resharper_]arguments_named
Possible values:
positional
: Positional argumentnamed
: Named argument
Examples:
Before formatting | After formatting, positional |
---|---|
|
|
Before formatting | After formatting, named |
---|---|
|
|
Anonymous methods (delegates and lambdas)
Property names:
[resharper_]csharp_arguments_anonymous_function
, [resharper_]arguments_anonymous_function
Possible values:
positional
: Positional argumentnamed
: Named argument
Examples:
Before formatting | After formatting, positional |
---|---|
|
|
Before formatting | After formatting, named |
---|---|
|
|
Other
Property names:
[resharper_]csharp_arguments_other
, [resharper_]arguments_other
Possible values:
positional
: Positional argumentnamed
: Named argument
Examples:
Before formatting | After formatting, positional |
---|---|
|
|
Before formatting | After formatting, named |
---|---|
|
|
Parentheses
Remove redundant parentheses
Property names:
[resharper_]csharp_parentheses_redundancy_style
, [resharper_]parentheses_redundancy_style
Possible values:
remove
: Alwaysremove_if_not_clarifies_precedence
: If not clarifies precedence
Examples:
Before formatting | After formatting, remove |
---|---|
|
|
Before formatting | After formatting, remove_if_not_clarifies_precedence |
---|---|
|
|
Add parenthesis to avoid non-obvious precedence
Around operands of the following operations
Property names:
[resharper_]csharp_parentheses_non_obvious_operations
, [resharper_]parentheses_non_obvious_operations
Possible values:
none
null_coalescing
: ??conditional
: && ||conditional_or
: ||conditional_and
: &&bitwise
: & ^ |bitwise_inclusive_or
: |range
: ..bitwise_exclusive_or
: ^equality
: == !=relational
: < > <= >=shift
: << >>arithmetic
: * / % + -additive
: + -multiplicative
: * / %bitwise_and
: &
Examples:
Before formatting | After formatting, none |
---|---|
|
|
Before formatting | After formatting, null_coalescing |
---|---|
|
|
Before formatting | After formatting, conditional |
---|---|
|
|
Before formatting | After formatting, conditional_or |
---|---|
|
|
Before formatting | After formatting, conditional_and |
---|---|
|
|
Before formatting | After formatting, bitwise |
---|---|
|
|
Before formatting | After formatting, bitwise_inclusive_or |
---|---|
|
|
Before formatting | After formatting, range |
---|---|
|
|
Before formatting | After formatting, bitwise_exclusive_or |
---|---|
|
|
Before formatting | After formatting, equality |
---|---|
|
|
Before formatting | After formatting, relational |
---|---|
|
|
Before formatting | After formatting, shift |
---|---|
|
|
Before formatting | After formatting, arithmetic |
---|---|
|
|
Before formatting | After formatting, additive |
---|---|
|
|
Before formatting | After formatting, multiplicative |
---|---|
|
|
Before formatting | After formatting, bitwise_and |
---|---|
|
|
When the operations from the following groups are nested
Property names:
[resharper_]csharp_parentheses_group_non_obvious_operations
, [resharper_]parentheses_group_non_obvious_operations
Possible values:
none
arithmetic
: * / % + - << >> & ^ |relational
: < > <= >= == !=conditional
: && || ??
Examples:
Before formatting | After formatting, none |
---|---|
|
|
Before formatting | After formatting, arithmetic |
---|---|
|
|
Before formatting | After formatting, relational |
---|---|
|
|
Before formatting | After formatting, conditional |
---|---|
|
|
Even when operations of the same type are nested
Property names:
[resharper_]csharp_parentheses_same_type_operations
, [resharper_]parentheses_same_type_operations
Possible values:
true | false
Examples:
true |
---|
|
false |
---|
|
Braces
In "if" statement
Property names:
[resharper_]csharp_braces_for_ifelse
, [resharper_]braces_for_ifelse
Possible values:
not_required
: Do not enforcenot_required_for_both
: Enforce if any part requires bracesrequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, not_required_for_both |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "for" statement
Property names:
[resharper_]csharp_braces_for_for
, [resharper_]braces_for_for
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "foreach" statement
Property names:
[resharper_]csharp_braces_for_foreach
, [resharper_]braces_for_foreach
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "while" statement
Property names:
[resharper_]csharp_braces_for_while
, [resharper_]braces_for_while
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "do-while" statement
Property names:
[resharper_]csharp_braces_for_dowhile
, [resharper_]braces_for_dowhile
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "using" statement
Property names:
[resharper_]csharp_braces_for_using
, [resharper_]braces_for_using
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "lock" statement
Property names:
[resharper_]csharp_braces_for_lock
, [resharper_]braces_for_lock
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
In "fixed" statement
Property names:
[resharper_]csharp_braces_for_fixed
, [resharper_]braces_for_fixed
Possible values:
not_required
: Do not enforcerequired
: Enforce alwaysrequired_for_multiline
: Enforce if body is multi-linerequired_for_multiline_statement
: Enforce if statement is multi-line
Examples:
Before formatting | After formatting, not_required |
---|---|
|
|
Before formatting | After formatting, required |
---|---|
|
|
Before formatting | After formatting, required_for_multiline |
---|---|
|
|
Before formatting | After formatting, required_for_multiline_statement |
---|---|
|
|
Remove redundant
Property names:
[resharper_]csharp_braces_redundant
, [resharper_]braces_redundant
Possible values:
true | false
Code body
Methods and operators
Property names:
[resharper_]csharp_method_or_operator_body
, [resharper_]method_or_operator_body
Possible values:
expression_body
: Expression bodyblock_body
: Block body
Examples:
Before formatting | After formatting, expression_body |
---|---|
|
|
Before formatting | After formatting, block_body |
---|---|
|
|
Local functions
Property names:
[resharper_]csharp_local_function_body
, [resharper_]local_function_body
Possible values:
expression_body
: Expression bodyblock_body
: Block body
Examples:
Before formatting | After formatting, expression_body |
---|---|
|
|
Before formatting | After formatting, block_body |
---|---|
|
|
Constructors and destructors
Property names:
[resharper_]csharp_constructor_or_destructor_body
, [resharper_]constructor_or_destructor_body
Possible values:
expression_body
: Expression bodyblock_body
: Block body
Examples:
Before formatting | After formatting, expression_body |
---|---|
|
|
Before formatting | After formatting, block_body |
---|---|
|
|
Properties, indexers and events
Property names:
[resharper_]csharp_accessor_owner_body
, [resharper_]accessor_owner_body
Possible values:
expression_body
: Expression bodyaccessors_with_expression_body
: Accessors with expression bodyaccessors_with_block_body
: Accessors with block body
Examples:
Before formatting | After formatting, expression_body |
---|---|
|
|
Before formatting | After formatting, accessors_with_expression_body |
---|---|
|
|
Before formatting | After formatting, accessors_with_block_body |
---|---|
|
|
Namespaces
Property names:
[resharper_]csharp_namespace_body
, [resharper_]namespace_body
Possible values:
file_scoped
: File-scopedblock_scoped
: Block-scoped
Examples:
Before formatting | After formatting, file_scoped |
---|---|
|
|
Before formatting | After formatting, block_scoped |
---|---|
|
|
Apply style heuristics
Property names:
[resharper_]csharp_use_heuristics_for_body_style
, [resharper_]use_heuristics_for_body_style
Possible values:
true | false
Examples:
Before formatting | After formatting, true |
---|---|
|
|
Before formatting | After formatting, false |
---|---|
|
|
Attributes
Join or separate attributes in section
Property names:
[resharper_]csharp_force_attribute_style
, [resharper_]force_attribute_style
Possible values:
join
: Joinseparate
: Separate
Examples:
Before formatting | After formatting, join |
---|---|
|
|
Before formatting | After formatting, separate |
---|---|
|
|
Trailing comma
Before a new line in multiline lists
Property names:
[resharper_]csharp_trailing_comma_in_multiline_lists
, [resharper_]trailing_comma_in_multiline_lists
Possible values:
true | false
Examples:
true |
---|
|
false |
---|
|
When the last element is not followed by a new line
Property names:
[resharper_]csharp_trailing_comma_in_singleline_lists
, [resharper_]trailing_comma_in_singleline_lists
Possible values:
true | false
Examples:
true |
---|
|
false |
---|
|
Object creation
When created type is evident from usage
Property names:
[resharper_]csharp_object_creation_when_type_evident
, [resharper_]object_creation_when_type_evident
Possible values:
target_typed
: Omit type: 'new()'explicitly_typed
: Specify type: 'new T()'
When created type is not evident from usage
Property names:
[resharper_]csharp_object_creation_when_type_not_evident
, [resharper_]object_creation_when_type_not_evident
Possible values:
target_typed
: Omit type: 'new()'explicitly_typed
: Specify type: 'new T()'
Default value
When type is evident from usage
Property names:
[resharper_]csharp_default_value_when_type_evident
, [resharper_]default_value_when_type_evident
Possible values:
default_literal
: Omit type: 'default'default_expression
: Specify type: 'default(T)'
When type is not evident from usage
Property names:
[resharper_]csharp_default_value_when_type_not_evident
, [resharper_]default_value_when_type_not_evident
Possible values:
default_literal
: Omit type: 'default'default_expression
: Specify type: 'default(T)'