The pattern book
Spacing
Space after cast
Section titled “Space after cast”csharp_space_after_cast = falseControls cast expressions. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Cast expressions.
- Guarantee: Only same-line whitespace changes.
var value = (int)number;Code unchanged.
var value = (int)number;var value = (int) number;Space after keywords in control flow statements
Section titled “Space after keywords in control flow statements”csharp_space_after_keywords_in_control_flow_statements = trueControls control-flow keywords. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Control-flow keywords.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } void Run() { if (true) Add(1,2); }}Code unchanged.
Space between parentheses
Section titled “Space between parentheses”csharp_space_between_parentheses = falseControls parenthesized syntax. Only same-line whitespace changes.
- Values:
control_flow_statementsexpressionstype_castsfalse— any comma-separated selection. - Default:
false - Applies to: Parenthesized syntax.
- Guarantee: Only same-line whitespace changes.
if (ready) total = (int)(count * 2);Code unchanged.
if (ready) total = (int)(count * 2);if ( ready ) total = (int)(count * 2);if (ready) total = (int)(count * 2);if (ready) total = (int)( count * 2 );if (ready) total = (int)(count * 2);if (ready) total = ( int )(count * 2);Space before colon in inheritance clause
Section titled “Space before colon in inheritance clause”csharp_space_before_colon_in_inheritance_clause = trueControls base-list colons. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Base-list colons.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Baseclass Example: Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Space after colon in inheritance clause
Section titled “Space after colon in inheritance clause”csharp_space_after_colon_in_inheritance_clause = trueControls base-list colons. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Base-list colons.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Baseclass Example :Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Space around binary operators
Section titled “Space around binary operators”csharp_space_around_binary_operators = before_and_afterControls binary and assignment operators. Only same-line whitespace changes.
- Values:
before_and_afterignorenone - Default:
before_and_after - Applies to: Binary and assignment operators.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}class Example : Base{ int Add(int left,int right) => left+right; int Add(int left,int right) => left + right; void Run() { if(true) Add(1,2); }}Code unchanged.
Code unchanged.
Space after comma
Section titled “Space after comma”csharp_space_after_comma = trueControls comma separators. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Comma separators.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } int Add(int left, int right) => left+right; void Run() { if(true) Add(1, 2); }}Code unchanged.
Space before comma
Section titled “Space before comma”csharp_space_before_comma = falseControls comma separators. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Comma separators.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } int Add(int left ,int right) => left+right; void Run() { if(true) Add(1 ,2); }}Space after dot
Section titled “Space after dot”csharp_space_after_dot = falseControls member-access dots. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Member-access dots.
- Guarantee: Only same-line whitespace changes.
var value = item.Name;Code unchanged.
var value = item.Name;var value = item. Name;Space before dot
Section titled “Space before dot”csharp_space_before_dot = falseControls member-access dots. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Member-access dots.
- Guarantee: Only same-line whitespace changes.
var value = item.Name;Code unchanged.
var value = item.Name;var value = item .Name;Space after semicolon in for statement
Section titled “Space after semicolon in for statement”csharp_space_after_semicolon_in_for_statement = trueControls for-statement semicolons. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: For-statement semicolons.
- Guarantee: Only same-line whitespace changes.
for (int i = 0;i < 10;i++) { Work(); }for (int i = 0;i < 10;i++) { Work(); }for (int i = 0; i < 10; i++) { Work(); }Code unchanged.
Space before semicolon in for statement
Section titled “Space before semicolon in for statement”csharp_space_before_semicolon_in_for_statement = falseControls for-statement semicolons. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: For-statement semicolons.
- Guarantee: Only same-line whitespace changes.
for (int i = 0;i < 10;i++) { Work(); }Code unchanged.
for (int i = 0;i < 10;i++) { Work(); }for (int i = 0 ;i < 10 ;i++) { Work(); }Space around declaration statements
Section titled “Space around declaration statements”csharp_space_around_declaration_statements = falseControls declaration equals tokens. Only same-line whitespace changes.
- Values:
falseignore - Default:
false - Applies to: Declaration equals tokens.
- Guarantee: Only same-line whitespace changes.
int value=1;int value=1;int value = 1;Code unchanged.
Space before open square brackets
Section titled “Space before open square brackets”csharp_space_before_open_square_brackets = falseControls array and element-access brackets. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Array and element-access brackets.
- Guarantee: Only same-line whitespace changes.
var value = items[0];Code unchanged.
var value = items[0];var value = items [0];Space between empty square brackets
Section titled “Space between empty square brackets”csharp_space_between_empty_square_brackets = falseControls array and element-access brackets. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Array and element-access brackets.
- Guarantee: Only same-line whitespace changes.
int[] values;Code unchanged.
int[] values;int[ ] values;Space between square brackets
Section titled “Space between square brackets”csharp_space_between_square_brackets = falseControls array and element-access brackets. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Array and element-access brackets.
- Guarantee: Only same-line whitespace changes.
var value = items[0];Code unchanged.
var value = items[0];var value = items[ 0 ];Method declarations
Section titled “Method declarations”Space between method declaration parameter list parentheses
Section titled “Space between method declaration parameter list parentheses”csharp_space_between_method_declaration_parameter_list_parentheses = falseControls method declaration parameter lists. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Method declaration parameter lists.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Base{ int Add(int left,int right) => left+right; int Add( int left,int right ) => left+right; void Run() { if(true) Add(1,2); }}Space between method declaration empty parameter list parentheses
Section titled “Space between method declaration empty parameter list parentheses”csharp_space_between_method_declaration_empty_parameter_list_parentheses = falseControls method declaration parameter lists. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Method declaration parameter lists.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } void Run( ) { if(true) Add(1,2); }}Space between method declaration name and open parenthesis
Section titled “Space between method declaration name and open parenthesis”csharp_space_between_method_declaration_name_and_open_parenthesis = falseControls method declaration parameter lists. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Method declaration parameter lists.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } int Add (int left,int right) => left+right; void Run () { if(true) Add(1,2); }}Method calls
Section titled “Method calls”Space between method call parameter list parentheses
Section titled “Space between method call parameter list parentheses”csharp_space_between_method_call_parameter_list_parentheses = falseControls invocation argument lists. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Invocation argument lists.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } void Run() { if(true) Add( 1,2 ); }}Space between method call empty parameter list parentheses
Section titled “Space between method call empty parameter list parentheses”csharp_space_between_method_call_empty_parameter_list_parentheses = falseControls invocation argument lists. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Invocation argument lists.
- Guarantee: Only same-line whitespace changes.
Work();Code unchanged.
Work();Work( );Space between method call name and opening parenthesis
Section titled “Space between method call name and opening parenthesis”csharp_space_between_method_call_name_and_opening_parenthesis = falseControls invocation argument lists. Only same-line whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Invocation argument lists.
- Guarantee: Only same-line whitespace changes.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); }}Code unchanged.
class Example : Base{ int Add(int left,int right) => left+right; void Run() { if(true) Add(1,2); } void Run() { if(true) Add (1,2); }}Collection expressions
Section titled “Collection expressions”Space after collection spread operator
Section titled “Space after collection spread operator”dress_space_after_collection_spread_operator = trueControls spacing after collection-expression spread operators. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Spacing after collection-expression spread operators.
- Guarantee: Only same-line whitespace changes.
class Example{ int[] Copy(int[] values) => [.. values];}Code unchanged.
class Example{ int[] Copy(int[] values) => [.. values]; int[] Copy(int[] values) => [..values];}Attributes
Section titled “Attributes”Space after attribute target colon
Section titled “Space after attribute target colon”dress_space_after_attribute_target_colon = trueControls spacing after attribute target colons, such as assembly, module, and return. Only same-line whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Spacing after attribute target colons, such as assembly, module, and return.
- Guarantee: Only same-line whitespace changes.
[assembly: System.CLSCompliant(true)]Code unchanged.
[assembly: System.CLSCompliant(true)][assembly:System.CLSCompliant(true)]