JetBrains Fleet 1.33 Help

EditorConfig properties for C#: Syntax Style

This page lists custom JetBrains Fleet EditorConfig properties that you can use to configure code syntax style rules.

'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 evident

  • use_explicit_type: Use explicit type

Examples:

use_var

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

use_var_when_evident

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

use_explicit_type

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

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 evident

  • use_explicit_type: Use explicit type

Examples:

use_var

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

use_var_when_evident

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

use_explicit_type

int count = 42; StringBuilder builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

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 evident

  • use_explicit_type: Use explicit type

Examples:

use_var

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

use_var_when_evident

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

use_explicit_type

int count = 42; var builder = new StringBuilder(); int length = builder.Length; Dictionary<string, string> dictionary = new Dictionary<string, string>(); bool hasValue = dictionary.TryGetValue("key", out string value);

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

Examples:

true

void ApplySetting(KeyValuePair<string, object> setting, KeyValuePair<string, object>? optionalSetting) { (var settingName, var value) = setting; // apply if (optionalSetting is (var optionalSettingName, var optionalSettingValue)) { // apply } }

false

void ApplySetting(KeyValuePair<string, object> setting, KeyValuePair<string, object>? optionalSetting) { var (settingName, value) = setting; // apply if (optionalSetting is var (optionalSettingName, optionalSettingValue)) { // apply } }

Use 'var' keyword for discards

Property names:

[resharper_]csharp_prefer_explicit_discard_declaration, [resharper_]prefer_explicit_discard_declaration

Possible values:

true | false

Examples:

true

bool RepresentsInteger(string value) { return int.TryParse(value, out var _); }

false

bool RepresentsInteger(string value) { return int.TryParse(value, out _); }

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

Examples:

none

using System; internal class Person { public Person(string name, int age) { _id = GenerateId(); Name = name; Age = age; AgeChanged += (_, newAge) => Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

field

using System; internal class Person { public Person(string name, int age) { this._id = GenerateId(); Name = name; Age = age; AgeChanged += (_, newAge) => Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

property

using System; internal class Person { public Person(string name, int age) { _id = GenerateId(); this.Name = name; this.Age = age; AgeChanged += (_, newAge) => this.Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

event

using System; internal class Person { public Person(string name, int age) { _id = GenerateId(); Name = name; Age = age; this.AgeChanged += (_, newAge) => Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

method

using System; internal class Person { public Person(string name, int age) { _id = this.GenerateId(); Name = name; Age = age; AgeChanged += (_, newAge) => Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

all

using System; internal class Person { public Person(string name, int age) { this._id = this.GenerateId(); this.Name = name; this.Age = age; this.AgeChanged += (_, newAge) => this.Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

Qualify members declared in

Property names:

[resharper_]csharp_instance_members_qualify_declared_in, [resharper_]instance_members_qualify_declared_in

Possible values:

  • this_class: the same class

  • base_class: the base class

Examples:

this_class

using System; internal class Person { public Person(string name, int age) { _id = GenerateId(); Name = name; Age = age; AgeChanged += (_, newAge) => Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

base_class

using System; internal class Person { public Person(string name, int age) { _id = GenerateId(); Name = name; Age = age; AgeChanged += (_, newAge) => Age = newAge; } private readonly int _id; public string Name { get; } public int Age { get; private set; } public event EventHandler<int> AgeChanged; public int GenerateId() { return 42; } }

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 type

  • declared_type: Declared-in type

Examples:

current_type

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(Name); Console.WriteLine(Version); GotRequest += (_, _) => { }; } public static string Name = GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

declared_type

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(Name); Console.WriteLine(Version); GotRequest += (_, _) => { }; } public static string Name = GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

Members to qualify

Property names:

[resharper_]csharp_static_members_qualify_members, [resharper_]static_members_qualify_members

Possible values:

  • none

  • field

  • property

  • event

  • method

  • all

Examples:

none

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(Name); Console.WriteLine(Version); GotRequest += (_, _) => { }; } public static string Name = GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

field

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(WeatherService.Name); Console.WriteLine(Version); WeatherService.GotRequest += (_, _) => { }; } public static string Name = GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

property

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(Name); Console.WriteLine(WeatherService.Version); GotRequest += (_, _) => { }; } public static string Name = GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

event

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(Name); Console.WriteLine(Version); GotRequest += (_, _) => { }; } public static string Name = GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

method

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(Name); Console.WriteLine(Version); GotRequest += (_, _) => { }; } public static string Name = WeatherService.GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

all

using System; internal class WeatherService { static WeatherService() { Console.WriteLine(WeatherService.Name); Console.WriteLine(WeatherService.Version); WeatherService.GotRequest += (_, _) => { }; } public static string Name = WeatherService.GetString(); public static Version Version => new(1, 2, 3); public static EventHandler GotRequest; public static string GetString() { return "abc"; } }

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: Keyword

  • use_clr_name: CLR type name

Examples:

use_keyword

void SetFont(string fontFamily, int fontSize, byte[] fontData, bool useKerning) { if (string.IsNullOrEmpty(fontFamily)) throw new ArgumentException("Invalid font family ", nameof(fontFamily)); if (int.IsNegative(fontSize)) throw new ArgumentOutOfRangeException(nameof(fontSize)); }

use_clr_name

void SetFont(string fontFamily, int fontSize, byte[] fontData, bool useKerning) { if (string.IsNullOrEmpty(fontFamily)) throw new ArgumentException("Invalid font family ", nameof(fontFamily)); if (int.IsNegative(fontSize)) throw new ArgumentOutOfRangeException(nameof(fontSize)); }

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: Keyword

  • use_clr_name: CLR type name

Examples:

use_keyword

void SetFont(string fontFamily, int fontSize, byte[] fontData, bool useKerning) { if (string.IsNullOrEmpty(fontFamily)) throw new ArgumentException("Invalid font family ", nameof(fontFamily)); if (int.IsNegative(fontSize)) throw new ArgumentOutOfRangeException(nameof(fontSize)); }

use_clr_name

void SetFont(string fontFamily, int fontSize, byte[] fontData, bool useKerning) { if (string.IsNullOrEmpty(fontFamily)) throw new ArgumentException("Invalid font family ", nameof(fontFamily)); if (int.IsNegative(fontSize)) throw new ArgumentOutOfRangeException(nameof(fontSize)); }

Also apply to native-sized integer types

Property names:

[resharper_]csharp_builtin_type_apply_to_native_integer, [resharper_]builtin_type_apply_to_native_integer

Possible values:

true | false

Examples:

true

using System; internal struct Buffer { public IntPtr Pointer; public int SizeInBytes; }

false

using System; internal struct Buffer { public IntPtr Pointer; public int SizeInBytes; }

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: Explicit

  • implicit: Implicit

Examples:

Before formatting

After formatting, explicit

class C { int a; private int b; }
internal class C { private int a; private int b; }

Before formatting

After formatting, implicit

class C { int a; private int b; }
internal class C { int a; int b; }

Prefer explicit/implicit internal modifier for types

Property names:

[resharper_]csharp_default_internal_modifier, [resharper_]default_internal_modifier

Possible values:

  • explicit: Explicit

  • implicit: Implicit

Examples:

Before formatting

After formatting, explicit

namespace N { class C { } internal class D { } }
namespace N; internal class C { } internal class D { }

Before formatting

After formatting, implicit

namespace N { class C { } internal class D { } }
namespace N; class C { } class D { }

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 argument

  • named: Named argument

Examples:

Before formatting

After formatting, positional

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Before formatting

After formatting, named

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(x: 1, d, b: true, "abc", Fx.F1, () => Bar(x: 1)); Bar(x: 1, d, b: true, "abc", Fx.F1, action: () => Bar(x: 1)); Bar(x: 1, d, b: true, "abc", e: Fx.F1, action: () => Bar(x: 1)); Bar(x: 1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(x: 1)); Bar(x: 1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(x: 1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(x: 1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(x: 1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

String literal values

Property names:

[resharper_]csharp_arguments_string_literal, [resharper_]arguments_string_literal

Possible values:

  • positional: Positional argument

  • named: Named argument

Examples:

Before formatting

After formatting, positional

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Before formatting

After formatting, named

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, s: "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, s: "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Named expressions (variables, properties, methods, etc.)

Property names:

[resharper_]csharp_arguments_named, [resharper_]arguments_named

Possible values:

  • positional: Positional argument

  • named: Named argument

Examples:

Before formatting

After formatting, positional

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Before formatting

After formatting, named

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, y: d, true, "abc", e: Fx.F1, () => Bar(1)); Bar(1, y: d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Anonymous methods (delegates and lambdas)

Property names:

[resharper_]csharp_arguments_anonymous_function, [resharper_]arguments_anonymous_function

Possible values:

  • positional: Positional argument

  • named: Named argument

Examples:

Before formatting

After formatting, positional

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Before formatting

After formatting, named

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Other

Property names:

[resharper_]csharp_arguments_other, [resharper_]arguments_other

Possible values:

  • positional: Positional argument

  • named: Named argument

Examples:

Before formatting

After formatting, positional

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Before formatting

After formatting, named

public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }
public class Arguments { public void Style() { Bar(1, d, true, "abc", Fx.F1, () => Bar(1)); Bar(1, d, true, "abc", Fx.F1, action: () => Bar(1)); Bar(1, d, true, "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); Bar(x: 1, y: d, b: true, s: "abc", e: Fx.F1, action: () => Bar(1)); } public void Bar(int x, int y, bool b, string s, Fx e, Action action = null) { } private enum Fx { F1, F2, F3 } }

Parentheses

Remove redundant parentheses

Property names:

[resharper_]csharp_parentheses_redundancy_style, [resharper_]parentheses_redundancy_style

Possible values:

  • remove: Always

  • remove_if_not_clarifies_precedence: If not clarifies precedence

Examples:

Before formatting

After formatting, remove

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; }

Before formatting

After formatting, remove_if_not_clarifies_precedence

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = ((9 >> (12 + x - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = ((9 >> (12 + a - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var c = ((2 | 7) + 1) & b; }

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

  • multiplicative: * / %

  • additive: + -

  • arithmetic: * / % + -

  • shift: << >>

  • relational: < > <= >=

  • equality: == !=

  • bitwise_and: &

  • bitwise_exclusive_or: ^

  • bitwise_inclusive_or: |

  • bitwise: & ^ |

  • conditional_and: &&

  • conditional_or: ||

  • conditional: && ||

  • null_coalescing: ??

  • range: ..

Examples:

Before formatting

After formatting, none

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, multiplicative

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - (3 % 4) * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - (3 % 4) * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, additive

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - (3 % 4 * 12); var y = 9 >> (12 + x) - 1 << 2 + 1 & (6 + (4 * 12)) - 1; var z = (2 | 7) + 1 & y; var a = 12 - (3 % 4 * 12); var b = 9 >> (12 + a) - 1 << 2 + 1 & (6 + (4 * 12)) - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, arithmetic

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - ((3 % 4) * 12); var y = 9 >> (12 + x) - 1 << 2 + 1 & (6 + (4 * 12)) - 1; var z = (2 | 7) + 1 & y; var a = 12 - ((3 % 4) * 12); var b = 9 >> (12 + a) - 1 << 2 + 1 & (6 + (4 * 12)) - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, shift

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = (9 >> (12 + x - 1)) << (2 + 1) & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = (9 >> (12 + a - 1)) << (2 + 1) & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, relational

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, equality

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, bitwise_and

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = (9 >> 12 + x - 1 << 2 + 1) & (6 + 4 * 12 - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = (9 >> 12 + a - 1 << 2 + 1) & (6 + 4 * 12 - 1); var c = ((2 | 7) + 1) & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, bitwise_exclusive_or

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, bitwise_inclusive_or

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, bitwise

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = (9 >> 12 + x - 1 << 2 + 1) & (6 + 4 * 12 - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = (9 >> 12 + a - 1 << 2 + 1) & (6 + 4 * 12 - 1); var c = ((2 | 7) + 1) & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, conditional_and

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = ((x > 5) && (y < 6)) || z == 7; }

Before formatting

After formatting, conditional_or

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || (z == 7); }

Before formatting

After formatting, conditional

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = ((x > 5) && (y < 6)) || (z == 7); }

Before formatting

After formatting, null_coalescing

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

Before formatting

After formatting, range

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = 9 >> 12 + x - 1 << 2 + 1 & 6 + 4 * 12 - 1; var z = (2 | 7) + 1 & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = (x > 5 && y < 6) || z == 7; }

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

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = ((9 >> (12 + x - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = ((9 >> (12 + a - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var c = ((2 | 7) + 1) & b; var d = x > 5 && y < 6 || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }

Before formatting

After formatting, arithmetic

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }
internal void Calculate() { var x = 12 - (3 % 4 * 12); var y = ((9 >> (12 + x - 1)) << (2 + 1)) & (6 + (4 * 12) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - (3 % 4 * 12); var b = ((9 >> (12 + a - 1)) << (2 + 1)) & (6 + (4 * 12) - 1); var c = ((2 | 7) + 1) & b; var d = x > 5 && y < 6 || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }

Before formatting

After formatting, relational

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = ((9 >> (12 + x - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = ((9 >> (12 + a - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var c = ((2 | 7) + 1) & b; var d = x > 5 && y < 6 || z == 7; var e = (x > 6) != (y > 6) && x != null == (y != null); }

Before formatting

After formatting, conditional

void Calculate() { var x = 12 - ((3 % 4) * 12); var y = ((9 >> ((12 + x) - 1)) << (2 + 1)) & ((6 + (4 * 12)) - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = 9 >> 12 + a - 1 << 2 + 1 & 6 + 4 * 12 - 1; var c = (2 | 7) + 1 & b; var d = x > 5 && y < 6 || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }
internal void Calculate() { var x = 12 - 3 % 4 * 12; var y = ((9 >> (12 + x - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var z = ((2 | 7) + 1) & y; var a = 12 - 3 % 4 * 12; var b = ((9 >> (12 + a - 1)) << (2 + 1)) & (6 + 4 * 12 - 1); var c = ((2 | 7) + 1) & b; var d = (x > 5 && y < 6) || z == 7; var e = x > 6 != y > 6 && x != null == (y != null); }

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

internal void Calculate() { var x = 5 + 3 - 2 * 3 / 4; var e = x != null == (y != null); }

false

internal void Calculate() { var x = 5 + 3 - 2 * 3 / 4; var e = x != null == (y != null); }

Braces

In 'if' statement

Property names:

[resharper_]csharp_braces_for_ifelse, [resharper_]braces_for_ifelse

Possible values:

  • not_required: Do not enforce

  • not_required_for_both: Enforce if any part requires braces

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) c = a + b; else { c = a / b; } }
public void Preview(int a, int b) { int c; if (a > b) c = a * b; else if (a == b) c = a + b; else c = a / b; }

Before formatting

After formatting, not_required_for_both

public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) c = a + b; else { c = a / b; } }
public void Preview(int a, int b) { int c; if (a > b) c = a * b; else if (a == b) c = a + b; else c = a / b; }

Before formatting

After formatting, required

public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) c = a + b; else { c = a / b; } }
public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) { c = a + b; } else { c = a / b; } }

Before formatting

After formatting, required_for_multiline

public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) c = a + b; else { c = a / b; } }
public void Preview(int a, int b) { int c; if (a > b) c = a * b; else if (a == b) c = a + b; else c = a / b; }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) c = a + b; else { c = a / b; } }
public void Preview(int a, int b) { int c; if (a > b) { c = a * b; } else if (a == b) { c = a + b; } else { c = a / b; } }

In 'for' statement

Property names:

[resharper_]csharp_braces_for_for, [resharper_]braces_for_for

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) c += System.Linq.Enumerable.Range(i, a + b).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) c += System.Linq.Enumerable.Range(i, a + b).Sum(); for (var i = a; i < b; i++) c += System.Linq.Enumerable .Range(i, a + b) .Sum(); }

Before formatting

After formatting, required

public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) c += System.Linq.Enumerable.Range(i, a + b).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) { c += System.Linq.Enumerable.Range(i, a + b).Sum(); } for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }

Before formatting

After formatting, required_for_multiline

public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) c += System.Linq.Enumerable.Range(i, a + b).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) c += System.Linq.Enumerable.Range(i, a + b).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) c += System.Linq.Enumerable.Range(i, a + b).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; for (var i = a; i < b; i++) { c += System.Linq.Enumerable.Range(i, a + b).Sum(); } for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(i, a + b) .Sum(); } }

In 'foreach' statement

Property names:

[resharper_]csharp_braces_for_foreach, [resharper_]braces_for_foreach

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable.Range(a, b).Sum(); foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable.Range(a, b).Sum(); foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable .Range(a, b) .Sum(); }

Before formatting

After formatting, required

public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable.Range(a, b).Sum(); foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable.Range(a, b).Sum(); } foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }

Before formatting

After formatting, required_for_multiline

public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable.Range(a, b).Sum(); foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable.Range(a, b).Sum(); foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) c += System.Linq.Enumerable.Range(a, b).Sum(); foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { var c = 0; foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable.Range(a, b).Sum(); } foreach (var num in System.Linq.Enumerable.Range(a, b)) { c += System.Linq.Enumerable .Range(a, b) .Sum(); } }

In 'while' statement

Property names:

[resharper_]csharp_braces_for_while, [resharper_]braces_for_while

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(int a, int b) { while (a > b) b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { while (a > b) b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b) b += System.Linq.Enumerable .Range(a, b) .Sum(); }

Before formatting

After formatting, required

public void Preview(int a, int b) { while (a > b) b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { while (a > b) { b += System.Linq.Enumerable.Range(a, b).Sum(); } while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }

Before formatting

After formatting, required_for_multiline

public void Preview(int a, int b) { while (a > b) b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { while (a > b) b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(int a, int b) { while (a > b) b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }
public void Preview(int a, int b) { while (a > b) { b += System.Linq.Enumerable.Range(a, b).Sum(); } while (a > b) { b += System.Linq.Enumerable .Range(a, b) .Sum(); } }

In 'do-while' statement

Property names:

[resharper_]csharp_braces_for_dowhile, [resharper_]braces_for_dowhile

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(int a, int b) { do b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }
public void Preview(int a, int b) { do b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b); do b += System.Linq.Enumerable .Range(a, b) .Sum(); while (a > b); }

Before formatting

After formatting, required

public void Preview(int a, int b) { do b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }
public void Preview(int a, int b) { do { b += System.Linq.Enumerable.Range(a, b).Sum(); } while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }

Before formatting

After formatting, required_for_multiline

public void Preview(int a, int b) { do b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }
public void Preview(int a, int b) { do b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(int a, int b) { do b += System.Linq.Enumerable.Range(a, b).Sum(); while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }
public void Preview(int a, int b) { do { b += System.Linq.Enumerable.Range(a, b).Sum(); } while (a > b); do { b += System.Linq.Enumerable .Range(a, b) .Sum(); } while (a > b); }

In 'using' statement

Property names:

[resharper_]csharp_braces_for_using, [resharper_]braces_for_using

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) c += System.Linq.Enumerable.Range(1, 42).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) c += System.Linq.Enumerable.Range(1, 42).Sum(); for (var i = a; i < b; i++) c += System.Linq.Enumerable .Range(1, 42) .Sum(); }

Before formatting

After formatting, required

public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) c += System.Linq.Enumerable.Range(1, 42).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) { c += System.Linq.Enumerable.Range(1, 42).Sum(); } for (var i = a; i < b; i++) c += System.Linq.Enumerable .Range(1, 42) .Sum(); }

Before formatting

After formatting, required_for_multiline

public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) c += System.Linq.Enumerable.Range(1, 42).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) c += System.Linq.Enumerable.Range(1, 42).Sum(); for (var i = a; i < b; i++) c += System.Linq.Enumerable .Range(1, 42) .Sum(); }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) c += System.Linq.Enumerable.Range(1, 42).Sum(); for (var i = a; i < b; i++) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(System.IDisposable disposable) { var c = 0; using (disposable) { c += System.Linq.Enumerable.Range(1, 42).Sum(); } for (var i = a; i < b; i++) c += System.Linq.Enumerable .Range(1, 42) .Sum(); }

In 'lock' statement

Property names:

[resharper_]csharp_braces_for_lock, [resharper_]braces_for_lock

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public void Preview(object lockObject) { var c = 0; lock (lockObject) c += System.Linq.Enumerable.Range(1, 42).Sum(); lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(object lockObject) { var c = 0; lock (lockObject) c += System.Linq.Enumerable.Range(1, 42).Sum(); lock (lockObject) c += System.Linq.Enumerable .Range(1, 42) .Sum(); }

Before formatting

After formatting, required

public void Preview(object lockObject) { var c = 0; lock (lockObject) c += System.Linq.Enumerable.Range(1, 42).Sum(); lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(object lockObject) { var c = 0; lock (lockObject) { c += System.Linq.Enumerable.Range(1, 42).Sum(); } lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }

Before formatting

After formatting, required_for_multiline

public void Preview(object lockObject) { var c = 0; lock (lockObject) c += System.Linq.Enumerable.Range(1, 42).Sum(); lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(object lockObject) { var c = 0; lock (lockObject) c += System.Linq.Enumerable.Range(1, 42).Sum(); lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }

Before formatting

After formatting, required_for_multiline_statement

public void Preview(object lockObject) { var c = 0; lock (lockObject) c += System.Linq.Enumerable.Range(1, 42).Sum(); lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }
public void Preview(object lockObject) { var c = 0; lock (lockObject) { c += System.Linq.Enumerable.Range(1, 42).Sum(); } lock (lockObject) { c += System.Linq.Enumerable .Range(1, 42) .Sum(); } }

In 'fixed' statement

Property names:

[resharper_]csharp_braces_for_fixed, [resharper_]braces_for_fixed

Possible values:

  • not_required: Do not enforce

  • required: Enforce always

  • required_for_multiline: Enforce if body is multi-line

  • required_for_multiline_statement: Enforce if statement is multi-line

Examples:

Before formatting

After formatting, not_required

public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) p[42] = 'c'; fixed (char* p = str) { p[42] = 'c'; } }
public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) p[42] = 'c'; fixed (char* p = str) p[42] = 'c'; }

Before formatting

After formatting, required

public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) p[42] = 'c'; fixed (char* p = str) { p[42] = 'c'; } }
public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) { p[42] = 'c'; } fixed (char* p = str) { p[42] = 'c'; } }

Before formatting

After formatting, required_for_multiline

public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) p[42] = 'c'; fixed (char* p = str) { p[42] = 'c'; } }
public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) p[42] = 'c'; fixed (char* p = str) { p[42] = 'c'; } }

Before formatting

After formatting, required_for_multiline_statement

public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) p[42] = 'c'; fixed (char* p = str) { p[42] = 'c'; } }
public unsafe void Preview(string str) { var c = 0; fixed (char* p = str) { p[42] = 'c'; } fixed (char* p = str) { p[42] = 'c'; } }

Remove redundant braces

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 body

  • block_body: Block body

Examples:

Before formatting

After formatting, expression_body

class Preview { int Add(int a, int b) { return a + b; } void SideEffect(DB db) { Drop(db); } static bool operator true(Preview p) { return false; } }
internal class Preview { private int Add(int a, int b) => a + b; private void SideEffect(DB db) { Drop(db); } static bool operator true(Preview p) => false; }

Before formatting

After formatting, block_body

class Preview { int Add(int a, int b) { return a + b; } void SideEffect(DB db) { Drop(db); } static bool operator true(Preview p) { return false; } }
internal class Preview { private int Add(int a, int b) { return a + b; } private void SideEffect(DB db) { Drop(db); } static bool operator true(Preview p) { return false; } }

Local functions

Property names:

[resharper_]csharp_local_function_body, [resharper_]local_function_body

Possible values:

  • expression_body: Expression body

  • block_body: Block body

Examples:

Before formatting

After formatting, expression_body

class Demo { public void Preview() { int CalculateTheAnswer() { return 42; } int answer = CalculateTheAnswer(); Output(answer); } }
internal class Demo { public void Preview() { int CalculateTheAnswer() => 42; int answer = CalculateTheAnswer(); Output(answer); } }

Before formatting

After formatting, block_body

class Demo { public void Preview() { int CalculateTheAnswer() { return 42; } int answer = CalculateTheAnswer(); Output(answer); } }
internal class Demo { public void Preview() { int CalculateTheAnswer() { return 42; } int answer = CalculateTheAnswer(); Output(answer); } }

Constructors and destructors

Property names:

[resharper_]csharp_constructor_or_destructor_body, [resharper_]constructor_or_destructor_body

Possible values:

  • expression_body: Expression body

  • block_body: Block body

Examples:

Before formatting

After formatting, expression_body

class Preview { public Preview(string message) { Message = message; } ~Preview() { throw new Exception(); } }
internal class Preview { public Preview(string message) => Message = message; ~Preview() => throw new Exception(); }

Before formatting

After formatting, block_body

class Preview { public Preview(string message) { Message = message; } ~Preview() { throw new Exception(); } }
internal class Preview { public Preview(string message) { Message = message; } ~Preview() { throw new Exception(); } }

Properties, indexers, and events

Property names:

[resharper_]csharp_accessor_owner_body, [resharper_]accessor_owner_body

Possible values:

  • expression_body: Expression body

  • accessors_with_expression_body: Accessors with expression body

  • accessors_with_block_body: Accessors with block body

Examples:

Before formatting

After formatting, expression_body

class Preview { int PropertyA { get { return field; } set { field = value; } } int PropertyB => field; int this[int i] { get { return array[i]; } set { array[i] = value; } } event EventHandler MissionComplete { add { action += value; } remove { action -= value; } } }
internal class Preview { private int PropertyA { get => field; set => field = value; } private int PropertyB => field; private int this[int i] { get => array[i]; set => array[i] = value; } private event EventHandler MissionComplete { add => action += value; remove => action -= value; } }

Before formatting

After formatting, accessors_with_expression_body

class Preview { int PropertyA { get { return field; } set { field = value; } } int PropertyB => field; int this[int i] { get { return array[i]; } set { array[i] = value; } } event EventHandler MissionComplete { add { action += value; } remove { action -= value; } } }
internal class Preview { private int PropertyA { get => field; set => field = value; } private int PropertyB { get => field; } private int this[int i] { get => array[i]; set => array[i] = value; } private event EventHandler MissionComplete { add => action += value; remove => action -= value; } }

Before formatting

After formatting, accessors_with_block_body

class Preview { int PropertyA { get { return field; } set { field = value; } } int PropertyB => field; int this[int i] { get { return array[i]; } set { array[i] = value; } } event EventHandler MissionComplete { add { action += value; } remove { action -= value; } } }
internal class Preview { private int PropertyA { get { return field; } set { field = value; } } private int PropertyB { get { return field; } } private int this[int i] { get { return array[i]; } set { array[i] = value; } } private event EventHandler MissionComplete { add { action += value; } remove { action -= value; } } }

Namespaces

Property names:

[resharper_]csharp_namespace_body, [resharper_]namespace_body

Possible values:

  • file_scoped: File-scoped

  • block_scoped: Block-scoped

Examples:

Before formatting

After formatting, file_scoped

namespace PreviewNamespace { public class C { } }
namespace PreviewNamespace; public class C { }

Before formatting

After formatting, block_scoped

namespace PreviewNamespace { public class C { } }
namespace PreviewNamespace { public class C { } }

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

class Preview { void VoidReturningMethod(DB db) { Drop(db); } int Assignment(int value) { return Property = value; } Action ReturnStatementBodiedLambda() { return () => { Foo(); }; } }
internal class Preview { private void VoidReturningMethod(DB db) { Drop(db); } private int Assignment(int value) { return Property = value; } private Action ReturnStatementBodiedLambda() { return () => { Foo(); }; } }

Before formatting

After formatting, false

class Preview { void VoidReturningMethod(DB db) { Drop(db); } int Assignment(int value) { return Property = value; } Action ReturnStatementBodiedLambda() { return () => { Foo(); }; } }
internal class Preview { private void VoidReturningMethod(DB db) { Drop(db); } private int Assignment(int value) { return Property = value; } private Action ReturnStatementBodiedLambda() { return () => { Foo(); }; } }

Attributes

Join or separate attributes in section

Property names:

[resharper_]csharp_force_attribute_style, [resharper_]force_attribute_style

Possible values:

  • join: Join

  • separate: Separate

Examples:

Before formatting

After formatting, join

namespace N { [Attr1, Attr2] [Attr3] class C { } }
namespace N; [Attr1, Attr2, Attr3] internal class C { }

Before formatting

After formatting, separate

namespace N { [Attr1, Attr2] [Attr3] class C { } }
namespace N; [Attr1] [Attr2] [Attr3] internal class C { }

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

var myArray = new[] { item1, item2, };

false

var myArray = new[] { item1, item2 };

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

var myArray = new[] { item1, item2, };

false

var myArray = new[] { item1, item2 };

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()'

Examples:

target_typed

using System; internal class MyService : ServiceBase { public override Version Version => new Version(1, 2, 3); }

explicitly_typed

using System; internal class MyService : ServiceBase { public override Version Version => new Version(1, 2, 3); }

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()'

Examples:

target_typed

using System; Version GetVersion() { // many lines of code // ... return new Version(1, 2, 3); }

explicitly_typed

using System; Version GetVersion() { // many lines of code // ... return new Version(1, 2, 3); }

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)'

Examples:

default_literal

using System; internal class MyService : ServiceBase { public override Guid Guid => default(Guid); }

default_expression

using System; internal class MyService : ServiceBase { public override Guid Guid => default(Guid); }

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)'

Examples:

default_literal

using System; Guid GetGuid() { // many lines of code // ... return default(Guid); }

default_expression

using System; Guid GetGuid() { // many lines of code // ... return default(Guid); }

Patterns

Null checking pattern style

Property names:

[resharper_]csharp_null_checking_pattern_style, [resharper_]null_checking_pattern_style

Possible values:

  • empty_recursive_pattern: '{ }' pattern

  • not_null_pattern: 'not null' pattern

Examples:

empty_recursive_pattern

public void Log(string? text) { if (text is not null) Console.WriteLine(text); }

not_null_pattern

public void Log(string? text) { if (text is not null) Console.WriteLine(text); }
Last modified: 15 April 2024