The pattern book
Wrapping
Maximum line length
Section titled “Maximum line length”max_line_length = 160Sets the target line width used by auto layout preferences.
- Values:
positive integeroff - Default:
160 - Applies to: File representation or shared layout settings.
- Guarantee: The configured value is applied by its owning formatter stage.
- Shown with:
dress_arguments_layout = auto
Call(firstArgument, secondArgument, thirdArgument);Code unchanged.
Call(firstArgument, secondArgument, thirdArgument);Call( firstArgument, secondArgument, thirdArgument);Code unchanged.
Code unchanged.
Arguments layout
Section titled “Arguments layout”dress_arguments_layout = autoControls Arguments. Only whitespace owned by syntax wrapping changes. Auto puts each item in a multiline list on its own line and keeps fitting single-line lists compact.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: Arguments.
- Guarantee: Only whitespace owned by syntax wrapping changes.
Call(firstArgument, secondArgument, thirdArgument);Code unchanged.
Code unchanged.
Call(firstArgument, secondArgument, thirdArgument);Call( firstArgument, secondArgument, thirdArgument);Parameters layout
Section titled “Parameters layout”dress_parameters_layout = autoControls Parameters. Only whitespace owned by syntax wrapping changes. Auto puts each item in a multiline list on its own line and keeps fitting single-line lists compact.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: Parameters.
- Guarantee: Only whitespace owned by syntax wrapping changes.
class Example { void Run(int first, int second, int third) { } }Code unchanged.
Code unchanged.
class Example { void Run(int first, int second, int third) { } }class Example { void Run( int first, int second, int third) { } }Type arguments layout
Section titled “Type arguments layout”dress_type_arguments_layout = autoControls TypeArguments. Only whitespace owned by syntax wrapping changes. The closing bracket stays attached to the last type argument when the list wraps. Auto keeps the first argument on the opening line when the text before the bracket is no wider than the continuation indent, since breaking there would gain no room.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: TypeArguments.
- Guarantee: Only whitespace owned by syntax wrapping changes.
class Example { Dictionary<string, List<int>> Values { get; set; } }Code unchanged.
Code unchanged.
class Example { Dictionary<string, List<int>> Values { get; set; } }class Example { Dictionary< string, List< int>> Values { get; set; } }Collection expressions layout
Section titled “Collection expressions layout”dress_collection_expressions_layout = autoControls CollectionExpressions. Only whitespace owned by syntax wrapping changes. Auto puts each item in a multiline list on its own line and keeps fitting single-line lists compact.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: CollectionExpressions.
- Guarantee: Only whitespace owned by syntax wrapping changes.
int[] values = [1, 2, 3];Code unchanged.
Code unchanged.
int[] values = [1, 2, 3];int[] values = [ 1, 2, 3];Base type lists layout
Section titled “Base type lists layout”dress_base_type_lists_layout = autoControls BaseTypeLists. Only whitespace owned by syntax wrapping changes.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: BaseTypeLists.
- Guarantee: Only whitespace owned by syntax wrapping changes.
class Example : Base, IFirst, ISecond { }Code unchanged.
Code unchanged.
class Example : Base, IFirst, ISecond { }class Example : Base, IFirst, ISecond { }Constraint clauses layout
Section titled “Constraint clauses layout”dress_constraint_clauses_layout = autoControls ConstraintClauses. Only whitespace owned by syntax wrapping changes.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: ConstraintClauses.
- Guarantee: Only whitespace owned by syntax wrapping changes.
class Example<T, U> where T : class where U : new() { }Code unchanged.
Code unchanged.
class Example<T, U> where T : class where U : new() { }class Example<T, U> where T : class where U : new() { }Attributes layout
Section titled “Attributes layout”dress_attributes_layout = autoControls Attributes. Only whitespace owned by syntax wrapping changes. Square brackets stay attached to the first and last attributes when the list wraps.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: Attributes.
- Guarantee: Only whitespace owned by syntax wrapping changes.
[First, Second, Third] class Example { }Code unchanged.
Code unchanged.
[First, Second, Third] class Example { }[First, Second, Third] class Example { }Closing delimiters
Section titled “Closing delimiters”Arguments closing delimiter position
Section titled “Arguments closing delimiter position”dress_arguments_closing_delimiter_position = after_last_itemPlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
after_last_item - Applies to: The closing boundary of multiline Arguments.
- Guarantee: Single-line lists and item layout are unchanged.
Call( first, second);Code unchanged.
Call( first, second); second);Parameters closing delimiter position
Section titled “Parameters closing delimiter position”dress_parameters_closing_delimiter_position = own_linePlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
own_line - Applies to: The closing boundary of multiline Parameters.
- Guarantee: Single-line lists and item layout are unchanged.
class Example( int value){}class Example( int value) int value){}Code unchanged.
Object initializer closing delimiter position
Section titled “Object initializer closing delimiter position”dress_object_initializer_closing_delimiter_position = unsetPlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
unset(the rule makes no change unless you set it) - Applies to: The closing boundary of multiline ObjectInitializers.
- Guarantee: Single-line lists and item layout are unchanged.
var value = new Example{ First = 1};var value = new Example{ First = 1}; First = 1 };Code unchanged.
Collection initializer closing delimiter position
Section titled “Collection initializer closing delimiter position”dress_collection_initializer_closing_delimiter_position = unsetPlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
unset(the rule makes no change unless you set it) - Applies to: The closing boundary of multiline CollectionInitializers.
- Guarantee: Single-line lists and item layout are unchanged.
var values = new List<int>{ 1, 2};var values = new List<int>{ 1, 2}; 1, 2 };Code unchanged.
Array initializer closing delimiter position
Section titled “Array initializer closing delimiter position”dress_array_initializer_closing_delimiter_position = unsetPlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
unset(the rule makes no change unless you set it) - Applies to: The closing boundary of multiline ArrayInitializers.
- Guarantee: Single-line lists and item layout are unchanged.
var values = new[]{ 1, 2};var values = new[]{ 1, 2}; 1, 2 };Code unchanged.
With initializer closing delimiter position
Section titled “With initializer closing delimiter position”dress_with_initializer_closing_delimiter_position = unsetPlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
unset(the rule makes no change unless you set it) - Applies to: The closing boundary of multiline WithInitializers.
- Guarantee: Single-line lists and item layout are unchanged.
var value = original with{ First = 1};var value = original with{ First = 1}; First = 1 };Code unchanged.
Collection expression closing delimiter position
Section titled “Collection expression closing delimiter position”dress_collection_expression_closing_delimiter_position = unsetPlaces a multiline list’s closing delimiter after the last item or on its own line, aligned with the opening line. Single-line lists are unchanged. Comments retain required line breaks.
- Values:
after_last_itemown_line - Default:
unset(the rule makes no change unless you set it) - Applies to: The closing boundary of multiline CollectionExpressions.
- Guarantee: Single-line lists and item layout are unchanged.
int[] values = [ 1, 2];int[] values = [ 1, 2]; 1, 2];Code unchanged.
Initializers
Section titled “Initializers”Object initializer layout
Section titled “Object initializer layout”dress_object_initializer_layout = autoControls ObjectInitializers. Only whitespace owned by syntax wrapping changes.
- Values:
compactautoexpanded - Default:
auto - Applies to: ObjectInitializers.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var value = new Example { First = 1, Second = 2 };Code unchanged.
Code unchanged.
var value = new Example { First = 1, Second = 2 };var value = new Example{ First = 1, Second = 2};Collection initializer layout
Section titled “Collection initializer layout”dress_collection_initializer_layout = autoControls CollectionInitializers. Only whitespace owned by syntax wrapping changes. The { key, value } elements of the initializer are laid out the same way, with their braces spaced like its own.
- Values:
compactautoexpanded - Default:
auto - Applies to: CollectionInitializers.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var values = new List<int> { 1, 2, 3 };Code unchanged.
Code unchanged.
var values = new List<int> { 1, 2, 3 };var values = new List<int>{ 1, 2, 3};Array initializer layout
Section titled “Array initializer layout”dress_array_initializer_layout = autoControls ArrayInitializers. Only whitespace owned by syntax wrapping changes.
- Values:
compactautoexpanded - Default:
auto - Applies to: ArrayInitializers.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var values = new[] { 1, 2, 3 };Code unchanged.
Code unchanged.
var values = new[] { 1, 2, 3 };var values = new[]{ 1, 2, 3};With initializer layout
Section titled “With initializer layout”dress_with_initializer_layout = autoControls WithInitializers. Only whitespace owned by syntax wrapping changes.
- Values:
compactautoexpanded - Default:
auto - Applies to: WithInitializers.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var value = original with { First = 1, Second = 2 };Code unchanged.
Code unchanged.
var value = original with { First = 1, Second = 2 };var value = original with{ First = 1, Second = 2};Expressions
Section titled “Expressions”Member access chains layout
Section titled “Member access chains layout”dress_member_access_chains_layout = autoControls MemberAccessChains. Only whitespace owned by syntax wrapping changes. A wrapped chain keeps its first call with a receiver no wider than the continuation indent, since breaking there would gain no room.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: MemberAccessChains.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var value = source.Where(predicate).Select(selector).ToList();Code unchanged.
Code unchanged.
var value = source.Where(predicate).Select(selector).ToList();var value = source .Where(predicate) .Select(selector) .ToList();Binary expressions layout
Section titled “Binary expressions layout”dress_binary_expressions_layout = autoControls BinaryExpressions. Only whitespace owned by syntax wrapping changes.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: BinaryExpressions.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var value = first + second + third;Code unchanged.
Code unchanged.
var value = first + second + third;var value = first + second + third;Binary expression indentation
Section titled “Binary expression indentation”dress_binary_expression_indentation = precedenceControls whether wrapped higher-precedence binary groups align with the outer expression or indent one additional level per precedence group. Does not introduce wrapping.
- Values:
flatprecedence - Default:
precedence - Applies to: Wrapped binary expression indentation.
- Guarantee: Only whitespace changes.
var result = first || second && third;Code unchanged.
var result = first || second && third; && third;Conditional expressions layout
Section titled “Conditional expressions layout”dress_conditional_expressions_layout = autoControls ConditionalExpressions. Only whitespace owned by syntax wrapping changes. Wrapped branches indent one level beyond the deepest formatted line of a multiline condition.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: ConditionalExpressions.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var value = condition ? first : second;Code unchanged.
Code unchanged.
var value = condition ? first : second;var value = condition ? first : second;Nested ternary style
Section titled “Nested ternary style”dress_nested_conditional_style = decision_ladderShapes wrapped nested ternaries. Decision ladders flatten false-branch chains; multiline conditions or branches fall back to staircase. Does not force single-line expressions to wrap.
- Values:
flatstaircasedecision_ladder - Default:
decision_ladder - Applies to: Nested conditional expression whitespace.
- Guarantee: Only whitespace changes.
var result = first ? one : second ? two : three;var result = first ? one : second ? two : three;var result = first ? one : second ? two : three;var result = first ? one : second ? two : three; ? two : three;Code unchanged.
Operator position
Section titled “Operator position”dotnet_style_operator_placement_when_wrapping = beginning_of_linePlaces wrapped binary and ternary operators at the beginning or end of the line. Does not introduce wrapping in single-line expressions. Commented operator boundaries are preserved.
- Values:
beginning_of_lineend_of_line - Default:
beginning_of_line - Applies to: Binary and conditional operator whitespace.
- Guarantee: Only whitespace changes.
var result = first + second + third;Code unchanged.
var result = first + second + third;var result = first + second + third;Query clauses layout
Section titled “Query clauses layout”dress_query_clauses_layout = autoControls QueryClauses. Only whitespace owned by syntax wrapping changes.
- Values:
always_singleautoalways_multi - Default:
auto - Applies to: QueryClauses.
- Guarantee: Only whitespace owned by syntax wrapping changes.
var result = from item in items where item.Active select item.Name;Code unchanged.
Code unchanged.
var result = from item in items where item.Active select item.Name;var result = from item in items where item.Active select item.Name;