EditorConfig 属性用于 C#: 换行
此页面列出了自定义 ReSharper EditorConfig 属性 ,您可以使用这些属性配置 C# 中的格式化首选项,具体来说,ReSharper 应如何在特定语言结构之前/之后添加或删除换行符,以及是否换行超过 硬换行于 首选项指定长度的长行。
常规
保留现有换行符
属性名称:
[resharper_]csharp_keep_user_linebreaks, [resharper_]csharp_keep_existing_arrangement, [resharper_]csharp_keep_existing_linebreaks, [resharper_]keep_user_linebreaks, [resharper_]keep_existing_arrangement, [resharper_]keep_existing_linebreaks
可能的值:
true | false
示例:
格式化前 | 格式化后,true |
|---|---|
int var = condition
? SomeFunc1()
: SomeFunc2();
| int var = condition
? SomeFunc1()
: SomeFunc2();
|
格式化前 | 格式化后,false |
|---|---|
int var = condition
? SomeFunc1()
: SomeFunc2();
| int var = condition ? SomeFunc1() : SomeFunc2();
|
硬换行于
属性名称:
max_line_length, [resharper_]csharp_max_line_length
可能的值:
一个整数
首选在 ',' 前换行
属性名称:
[resharper_]csharp_wrap_before_comma, [resharper_]wrap_before_comma
可能的值:
true | false
示例:
true |
|---|
CallMethod(arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7);
|
false |
|---|
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7);
|
首选在 '=' 前换行
属性名称:
[resharper_]csharp_wrap_before_eq, [resharper_]wrap_before_eq
可能的值:
true | false
示例:
true |
|---|
myObject.ImportantField
+= someRatherLongExpression;
|
false |
|---|
myObject.ImportantField +=
someRatherLongExpression;
|
特殊的 'else if' 处理
属性名称:
[resharper_]csharp_special_else_if_treatment, [resharper_]special_else_if_treatment
可能的值:
true | false
示例:
true |
|---|
if (condition)
{
foo();
}
else if (condition)
{
}
|
false |
|---|
if (condition)
{
foo();
}
else
if (condition)
{
}
|
在文件末尾换行
属性名称:
insert_final_newline, [resharper_]csharp_insert_final_newline
可能的值:
true | false
示例:
true |
|---|
class A
{
}
|
false |
|---|
class A
{
}
|
属性的排列
长度大于此值时将特性部分列表置于单独的行中
属性名称:
[resharper_]csharp_max_attribute_length_for_same_line, [resharper_]max_attribute_length_for_same_line
可能的值:
一个整数
保留特性的现有排列
属性名称:
[resharper_]csharp_keep_existing_attribute_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_attribute_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
[Attribute]
class C {}
[Attribute] class C1 {}
| [Attribute]
class C { }
[Attribute] class C1 { }
|
格式化前 | 格式化后,false |
|---|---|
[Attribute]
class C {}
[Attribute] class C1 {}
| [Attribute]
class C { }
[Attribute]
class C1 { }
|
将类型特性置于同一行中
属性名称:
[resharper_]csharp_place_type_attribute_on_same_line, [resharper_]csharp_place_attribute_on_same_line, [resharper_]place_type_attribute_on_same_line, [resharper_]place_attribute_on_same_line
可能的值:
false:从不从不:从不如果所有者在单行中:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
[Attribute]
class C { }
[Attribute]
class C1
{
// comment
}
|
从不 |
|---|
[Attribute]
class C { }
[Attribute]
class C1
{
// comment
}
|
如果所有者是单行 |
|---|
[Attribute] class C { }
[Attribute]
class C1
{
// comment
}
|
true |
|---|
[Attribute] class C { }
[Attribute] class C1
{
// comment
}
|
始终 |
|---|
[Attribute] class C { }
[Attribute] class C1
{
// comment
}
|
将方法特性置于同一行中
属性名称:
[resharper_]csharp_place_method_attribute_on_same_line, [resharper_]csharp_place_attribute_on_same_line, [resharper_]place_method_attribute_on_same_line, [resharper_]place_attribute_on_same_line
可能的值:
false:从不从不:从不如果所有者在单行中:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
interface I
{
[Attribute]
void foo();
}
class C
{
[Attribute]
void foo()
{
// comment
}
}
|
从未 |
|---|
interface I
{
[Attribute]
void foo();
}
class C
{
[Attribute]
void foo()
{
// comment
}
}
|
如果所有者是单行 |
|---|
interface I
{
[Attribute] void foo();
}
class C
{
[Attribute]
void foo()
{
// comment
}
}
|
true |
|---|
interface I
{
[Attribute] void foo();
}
class C
{
[Attribute] void foo()
{
// comment
}
}
|
始终 |
|---|
interface I
{
[Attribute] void foo();
}
class C
{
[Attribute] void foo()
{
// comment
}
}
|
将属性/索引器/事件特性置于同一行中
属性名称:
[resharper_]csharp_place_accessorholder_attribute_on_same_line, [resharper_]csharp_place_attribute_on_same_line, [resharper_]place_accessorholder_attribute_on_same_line, [resharper_]place_attribute_on_same_line
可能的值:
false:从不从不:从不如果所属元素为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
interface I
{
[Attribute]
int Property { get; }
}
class C
{
[Attribute]
int Property
{
get
{
// comment
return x;
}
}
}
|
从未 |
|---|
interface I
{
[Attribute]
int Property { get; }
}
class C
{
[Attribute]
int Property
{
get
{
// comment
return x;
}
}
}
|
如果所有者是单行 |
|---|
interface I
{
[Attribute] int Property { get; }
}
class C
{
[Attribute]
int Property
{
get
{
// comment
return x;
}
}
}
|
true |
|---|
interface I
{
[Attribute] int Property { get; }
}
class C
{
[Attribute] int Property
{
get
{
// comment
return x;
}
}
}
|
始终 |
|---|
interface I
{
[Attribute] int Property { get; }
}
class C
{
[Attribute] int Property
{
get
{
// comment
return x;
}
}
}
|
将访问器特性置于同一行中
属性名称:
[resharper_]csharp_place_accessor_attribute_on_same_line, [resharper_]csharp_place_attribute_on_same_line, [resharper_]place_accessor_attribute_on_same_line, [resharper_]place_attribute_on_same_line
可能的值:
false:从不从不:从不如果所属元素为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
interface I
{
int Property
{
[Attribute]
get;
}
}
class C
{
int Property
{
[Attribute]
get { return x; }
[Attribute]
set
{
x = value;
NotifySomething();
}
}
}
|
从不 |
|---|
interface I
{
int Property
{
[Attribute]
get;
}
}
class C
{
int Property
{
[Attribute]
get { return x; }
[Attribute]
set
{
x = value;
NotifySomething();
}
}
}
|
如果所有者是单行 |
|---|
interface I
{
int Property { [Attribute] get; }
}
class C
{
int Property
{
[Attribute] get { return x; }
[Attribute]
set
{
x = value;
NotifySomething();
}
}
}
|
true |
|---|
interface I
{
int Property { [Attribute] get; }
}
class C
{
int Property
{
[Attribute] get { return x; }
[Attribute] set
{
x = value;
NotifySomething();
}
}
}
|
始终 |
|---|
interface I
{
int Property { [Attribute] get; }
}
class C
{
int Property
{
[Attribute] get { return x; }
[Attribute] set
{
x = value;
NotifySomething();
}
}
}
|
将字段特性置于同一行中
属性名称:
[resharper_]csharp_place_field_attribute_on_same_line, [resharper_]csharp_place_attribute_on_same_line, [resharper_]place_field_attribute_on_same_line, [resharper_]place_attribute_on_same_line
可能的值:
false:从不从不:从不如果所属元素为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
class C
{
[Attribute]
int x;
[Attribute]
MyObj y = // comment
new MyObj();
}
|
从不 |
|---|
class C
{
[Attribute]
int x;
[Attribute]
MyObj y = // comment
new MyObj();
}
|
如果所有者是单行 |
|---|
class C
{
[Attribute] int x;
[Attribute]
MyObj y = // comment
new MyObj();
}
|
true |
|---|
class C
{
[Attribute] int x;
[Attribute] MyObj y = // comment
new MyObj();
}
|
始终 |
|---|
class C
{
[Attribute] int x;
[Attribute] MyObj y = // comment
new MyObj();
}
|
将记录字段特性置于同一行中
属性名称:
[resharper_]csharp_place_record_field_attribute_on_same_line, [resharper_]csharp_place_attribute_on_same_line, [resharper_]place_record_field_attribute_on_same_line, [resharper_]place_attribute_on_same_line
可能的值:
false:从不从不:从不如果所属元素为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
record MyRecord(
[Attribute]
int Field);
|
从不 |
|---|
record MyRecord(
[Attribute]
int Field);
|
如果所有者是单行 |
|---|
record MyRecord([Attribute] int Field);
|
true |
|---|
record MyRecord([Attribute] int Field);
|
始终 |
|---|
record MyRecord([Attribute] int Field);
|
方法签名的排列
将形参换行
属性名称:
[resharper_]csharp_wrap_parameters_style, [resharper_]wrap_parameters_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
interface IA
{
void M(int p1, int p2);
void SomeMethod(int p1,
int p2, int p3,
int p4);
}
|
chop_if_long |
|---|
interface IA
{
void M(int p1, int p2);
void SomeMethod(int p1,
int p2,
int p3,
int p4);
}
|
chop_always |
|---|
interface IA
{
void M(int p1,
int p2);
void SomeMethod(int p1,
int p2,
int p3,
int p4);
}
|
一行中的最大形参数
属性名称:
[resharper_]csharp_max_formal_parameters_on_line, [resharper_]max_formal_parameters_on_line
可能的值:
一个整数
示例:
值:0 |
|---|
interface IA
{
void M(int arg1);
void M(int arg1,
int arg2);
void M(int arg1,
int arg2,
int arg3);
void M(int arg1,
int arg2,
int arg3,
int arg4);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7,
int arg8);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7,
int arg8,
int arg9);
}
|
值:1 |
|---|
interface IA
{
void M(int arg1);
void M(int arg1,
int arg2);
void M(int arg1,
int arg2,
int arg3);
void M(int arg1,
int arg2,
int arg3,
int arg4);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7,
int arg8);
void M(int arg1,
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7,
int arg8,
int arg9);
}
|
值:2 |
|---|
interface IA
{
void M(int arg1);
void M(int arg1, int arg2);
void M(int arg1, int arg2,
int arg3);
void M(int arg1, int arg2,
int arg3, int arg4);
void M(int arg1, int arg2,
int arg3, int arg4,
int arg5);
void M(int arg1, int arg2,
int arg3, int arg4,
int arg5, int arg6);
void M(int arg1, int arg2,
int arg3, int arg4,
int arg5, int arg6,
int arg7);
void M(int arg1, int arg2,
int arg3, int arg4,
int arg5, int arg6,
int arg7, int arg8);
void M(int arg1, int arg2,
int arg3, int arg4,
int arg5, int arg6,
int arg7, int arg8,
int arg9);
}
|
保留声明中圆括号的现有排列
属性名称:
[resharper_]csharp_keep_existing_declaration_parens_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_declaration_parens_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true | false
示例:
格式化前 | 格式化后,true |
|---|---|
void SomeMethod
(
int p1, int p2,
int p3, int p4
) {}
| void SomeMethod
(
int p1, int p2,
int p3, int p4
)
{
}
|
格式化前 | 格式化后,false |
|---|---|
void SomeMethod
(
int p1, int p2,
int p3, int p4
) {}
| void SomeMethod(int p1, int p2,
int p3, int p4)
{
}
|
首选在声明中的 '(' 前换行
属性名称:
[resharper_]csharp_wrap_before_declaration_lpar, [resharper_]wrap_before_declaration_lpar
可能的值:
true | false
示例:
true |
|---|
void SomeMethod
(int p1, int p2,
int p3, int p4)
{
}
|
false |
|---|
void SomeMethod(int p1, int p2,
int p3, int p4)
{
}
|
首选在声明中的 '(' 后换行
属性名称:
[resharper_]csharp_wrap_after_declaration_lpar, [resharper_]wrap_after_declaration_lpar
可能的值:
true | false
示例:
true |
|---|
void SomeMethod(
int p1, int p2,
int p3, int p4)
{
}
|
false |
|---|
void SomeMethod(int p1, int p2,
int p3, int p4)
{
}
|
首选在声明中的 ')' 前换行
属性名称:
[resharper_]csharp_wrap_before_declaration_rpar, [resharper_]wrap_before_declaration_rpar
可能的值:
true | false
示例:
true |
|---|
void SomeMethod(int p1, int p2,
int p3, int p4
)
{
}
|
false |
|---|
void SomeMethod(int p1, int p2,
int p3, int p4)
{
}
|
允许构造函数初始值设定项位于同一行
属性名称:
[resharper_]csharp_place_constructor_initializer_on_same_line, [resharper_]place_constructor_initializer_on_same_line
可能的值:
true | false
示例:
true |
|---|
class C
{
public C() : base()
{
}
}
|
false |
|---|
class C
{
public C()
: base()
{
}
}
|
主构造函数签名的排列
包装主构造函数形参
属性名称:
[resharper_]csharp_wrap_primary_constructor_parameters_style, [resharper_]wrap_primary_constructor_parameters_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name, IParametersOwner owner, int parameterIndex,
ParameterKind kind, ScopedKind parameterScope,
IType type) : IParameter;
|
chop_if_long |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
chop_always |
|---|
public record Person(
string Name,
int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
一行上的最大主构造函数形参
属性名称:
[resharper_]csharp_max_primary_constructor_parameters_on_line, [resharper_]max_primary_constructor_parameters_on_line
可能的值:
一个整数
示例:
值:0 |
|---|
public record Person(
string Name,
int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
值:1 |
|---|
public record Person(
string Name,
int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
值:2 |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
保留声明中圆括号的现有排列
属性名称:
[resharper_]csharp_keep_existing_primary_constructor_declaration_parens_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_primary_constructor_declaration_parens_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true | false
示例:
格式化前 | 格式化后,true |
|---|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name, IParametersOwner owner, int parameterIndex, ParameterKind kind, ScopedKind parameterScope, IType type
) : IParameter;
| public record Person(string Name, int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type
) : IParameter;
|
格式化前 | 格式化后,false |
|---|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name, IParametersOwner owner, int parameterIndex, ParameterKind kind, ScopedKind parameterScope, IType type
) : IParameter;
| public record Person(string Name, int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
首选在声明中的 '(' 前换行
属性名称:
[resharper_]csharp_wrap_before_primary_constructor_declaration_lpar, [resharper_]wrap_before_primary_constructor_declaration_lpar
可能的值:
true | false
示例:
true |
|---|
public record Person(string Name, int Age);
public partial class Parameter
(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
false |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
首选在声明中的 '(' 后换行
属性名称:
[resharper_]csharp_wrap_after_primary_constructor_declaration_lpar, [resharper_]wrap_after_primary_constructor_declaration_lpar
可能的值:
true | false
示例:
true |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
false |
|---|
public record Person(string Name, int Age);
public partial class Parameter(string name,
IParametersOwner owner,
int parameterIndex,
ParameterKind kind,
ScopedKind parameterScope,
IType type) : IParameter;
|
首选在声明中的 ')' 前换行
属性名称:
[resharper_]csharp_wrap_before_primary_constructor_declaration_rpar, [resharper_]wrap_before_primary_constructor_declaration_rpar
可能的值:
true | false
示例:
true |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name,
int parameterIndex,
ParameterKind kind,
IType type
) : IParameter;
|
false |
|---|
public record Person(string Name, int Age);
public partial class Parameter(
string name,
int parameterIndex,
ParameterKind kind,
IType type) : IParameter;
|
表达式主体成员的排列
保留表达式主体成员的现有排列
属性名称:
[resharper_]csharp_keep_existing_expr_member_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_expr_member_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true | false
示例:
格式化前 | 格式化后,true |
|---|---|
class A
{
public int Foo() => 0;
public int Foo1()
=> 1;
public int Foo2() =>
2;
}
| class A
{
public int Foo() => 0;
public int Foo1()
=> 1;
public int Foo2() =>
2;
}
|
格式化前 | 格式化后,false |
|---|---|
class A
{
public int Foo() => 0;
public int Foo1()
=> 1;
public int Foo2() =>
2;
}
| class A
{
public int Foo() => 0;
public int Foo1() => 1;
public int Foo2() => 2;
}
|
将方法表达式主体置于同一行中
属性名称:
[resharper_]csharp_place_expr_method_on_single_line, [resharper_]place_expr_method_on_single_line
可能的值:
false:从不从不:从不如果所属元素为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
class A
{
public int Foo() =>
0;
public int // comment
Foo1() =>
1;
public int Foo2() =>
1 + // comment
2;
}
|
从不 |
|---|
class A
{
public int Foo() =>
0;
public int // comment
Foo1() =>
1;
public int Foo2() =>
1 + // comment
2;
}
|
如果所有者是单行 |
|---|
class A
{
public int Foo() => 0;
public int // comment
Foo1() =>
1;
public int Foo2() =>
1 + // comment
2;
}
|
true |
|---|
class A
{
public int Foo() => 0;
public int // comment
Foo1() => 1;
public int Foo2() => 1 + // comment
2;
}
|
始终 |
|---|
class A
{
public int Foo() => 0;
public int // comment
Foo1() => 1;
public int Foo2() => 1 + // comment
2;
}
|
将属性表达式主体置于同一行中
属性名称:
[resharper_]csharp_place_expr_property_on_single_line, [resharper_]place_expr_property_on_single_line
可能的值:
false:从不从不:从不如果所有者在单行上:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
class A
{
public int Foo =>
0;
public int // comment
Foo1 =>
1;
public int Foo2 =>
1 + // comment
2;
}
|
从不 |
|---|
class A
{
public int Foo =>
0;
public int // comment
Foo1 =>
1;
public int Foo2 =>
1 + // comment
2;
}
|
如果所有者是单行 |
|---|
class A
{
public int Foo => 0;
public int // comment
Foo1 =>
1;
public int Foo2 =>
1 + // comment
2;
}
|
true |
|---|
class A
{
public int Foo => 0;
public int // comment
Foo1 => 1;
public int Foo2 => 1 + // comment
2;
}
|
始终 |
|---|
class A
{
public int Foo => 0;
public int // comment
Foo1 => 1;
public int Foo2 => 1 + // comment
2;
}
|
将属性访问器表达式主体置于同一行中
属性名称:
[resharper_]csharp_place_expr_accessor_on_single_line, [resharper_]place_expr_accessor_on_single_line
可能的值:
false:从不从不:从不如果所有者在单行上:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
class A
{
public int Foo
{
get =>
0;
}
public int Foo1
{
get =>
1 + // comment
2;
}
}
|
从未 |
|---|
class A
{
public int Foo
{
get =>
0;
}
public int Foo1
{
get =>
1 + // comment
2;
}
}
|
如果所有者是单行 |
|---|
class A
{
public int Foo
{
get => 0;
}
public int Foo1
{
get =>
1 + // comment
2;
}
}
|
true |
|---|
class A
{
public int Foo
{
get => 0;
}
public int Foo1
{
get => 1 + // comment
2;
}
}
|
始终 |
|---|
class A
{
public int Foo
{
get => 0;
}
public int Foo1
{
get => 1 + // comment
2;
}
}
|
首选在后跟表达式的 '=>' 前换行
属性名称:
[resharper_]csharp_wrap_before_arrow_with_expressions, [resharper_]wrap_before_arrow_with_expressions
可能的值:
true | false
示例:
true |
|---|
class A
{
public int Foo(int y)
=> Br(y * y + y <<
y + y);
Func<int, int, int>
Method2()
{
return (xxx, yyy)
=> Br(xxx * yyy);
}
}
|
false |
|---|
class A
{
public int Foo(int y) =>
Br(y * y + y << y + y);
Func<int, int, int>
Method2()
{
return (xxx, yyy) =>
Br(xxx * yyy);
}
}
|
类型参数、约束和基类型的排列
允许类型约束位于同一行
属性名称:
[resharper_]csharp_place_type_constraints_on_same_line, [resharper_]place_type_constraints_on_same_line
可能的值:
true | false
示例:
true |
|---|
class C<T> where T : IEnumerable
{
}
|
false |
|---|
class C<T>
where T : IEnumerable
{
}
|
首选在第一个约束前换行
属性名称:
[resharper_]csharp_wrap_before_first_type_parameter_constraint, [resharper_]wrap_before_first_type_parameter_constraint
可能的值:
true | false
示例:
true |
|---|
class C<T1, T2, T3>
where T1 : I1
where T2 : new()
where T3 : class
|
false |
|---|
class C<T1, T2, T3> where T1 : I1
where T2 : new()
where T3 : class
|
将多类型形参约束换行
属性名称:
[resharper_]csharp_wrap_multiple_type_parameter_constraints_style, [resharper_]wrap_multiple_type_parameter_constraints_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
class C<T1, T2, T3> where T1 : I1 where T2 : new()
where T3 : class
|
chop_if_long |
|---|
class C<T1, T2, T3> where T1 : I1
where T2 : new()
where T3 : class
|
chop_always |
|---|
class C<T1, T2, T3> where T1 : I1
where T2 : new()
where T3 : class
|
首选在类型形参列表的左尖括号前换行
属性名称:
[resharper_]csharp_wrap_before_type_parameter_langle, [resharper_]wrap_before_type_parameter_langle
可能的值:
true | false
示例:
true |
|---|
class C
<Type1, Type2,
Type3, Type4>
{
}
|
false |
|---|
class C<Type1, Type2,
Type3, Type4>
{
}
|
首选在 ':' 前换行
属性名称:
[resharper_]csharp_wrap_before_extends_colon, [resharper_]wrap_before_extends_colon
可能的值:
true | false
示例:
true |
|---|
class Derived
: BaseClass, I1, I2,
I3, I4
{
}
|
false |
|---|
class Derived : BaseClass, I1,
I2,
I3, I4
{
}
|
将 extends/implements 列表换行
属性名称:
[resharper_]csharp_wrap_extends_list_style, [resharper_]wrap_extends_list_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
class Derived : BaseClass, I1,
I2, I3, I4
{
}
|
chop_if_long |
|---|
class Derived : BaseClass,
I1,
I2,
I3,
I4
{
}
|
chop_always |
|---|
class Derived : BaseClass,
I1,
I2,
I3,
I4
{
}
|
声明块的排列
保留声明块的现有排列
属性名称:
[resharper_]csharp_keep_existing_declaration_block_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_declaration_block_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true | false
示例:
格式化前 | 格式化后,true |
|---|---|
interface I{
int Property {
get; set;
}
}
interface I{int Property{get;set;}}
| interface I
{
int Property
{
get;
set;
}
}
interface I
{
int Property { get; set; }
}
|
格式化前 | 格式化后,false |
|---|---|
interface I{
int Property {
get; set;
}
}
interface I{int Property{get;set;}}
| interface I
{
int Property { get; set; }
}
interface I
{
int Property { get; set; }
}
|
将 abstract/auto 属性/索引器/事件声明置于单行中
属性名称:
[resharper_]csharp_place_abstract_accessorholder_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]csharp_place_simple_declaration_blocks_on_single_line, [resharper_]place_abstract_accessorholder_on_single_line, [resharper_]place_simple_blocks_on_single_line, [resharper_]place_simple_declaration_blocks_on_single_line
可能的值:
true | false
示例:
true |
|---|
interface I
{
int Property { get; set; }
}
|
false |
|---|
interface I
{
int Property
{
get;
set;
}
}
|
将简单属性/索引器/事件声明置于单行中
属性名称:
[resharper_]csharp_place_simple_accessorholder_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]csharp_place_simple_declaration_blocks_on_single_line, [resharper_]place_simple_accessorholder_on_single_line, [resharper_]place_simple_blocks_on_single_line, [resharper_]place_simple_declaration_blocks_on_single_line
可能的值:
true | false
示例:
true |
|---|
class C
{
int Property { get { return x; } set { x = value; } }
}
|
false |
|---|
class C
{
int Property
{
get { return x; }
set { x = value; }
}
}
|
即使在访问器上有特性,也将其置于单行中
属性名称:
[resharper_]csharp_place_accessor_with_attrs_holder_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]csharp_place_simple_declaration_blocks_on_single_line, [resharper_]place_accessor_with_attrs_holder_on_single_line, [resharper_]place_simple_blocks_on_single_line, [resharper_]place_simple_declaration_blocks_on_single_line
可能的值:
true | false
示例:
true |
|---|
class C
{
int Property
{
[Attr] get { return x; }
[Attr] set { x = value; }
}
}
|
false |
|---|
class C
{
int Property
{
[Attr] get { return x; }
[Attr] set { x = value; }
}
}
|
将简单访问器置于单行中
属性名称:
[resharper_]csharp_place_simple_accessor_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]csharp_place_simple_declaration_blocks_on_single_line, [resharper_]place_simple_accessor_on_single_line, [resharper_]place_simple_blocks_on_single_line, [resharper_]place_simple_declaration_blocks_on_single_line
可能的值:
true | false
示例:
true |
|---|
class C
{
int Property
{
get { return x; }
set
{
if (value == null) throw new Exception();
}
}
}
|
false |
|---|
class C
{
int Property
{
get
{
return x;
}
set
{
if (value == null) throw new Exception();
}
}
}
|
将简单方法置于单行中
属性名称:
[resharper_]csharp_place_simple_method_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]csharp_place_simple_declaration_blocks_on_single_line, [resharper_]place_simple_method_on_single_line, [resharper_]place_simple_blocks_on_single_line, [resharper_]place_simple_declaration_blocks_on_single_line
可能的值:
true | false
示例:
true |
|---|
class C
{
void Foo() { DoSomethingSimple(); }
}
|
false |
|---|
class C
{
void Foo()
{
DoSomethingSimple();
}
}
|
枚举的排列
保留枚举的现有排列
属性名称:
[resharper_]csharp_keep_existing_enum_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_enum_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true | false
示例:
格式化前 | 格式化后,true |
|---|---|
public enum Enum1 { a, b, c }
public enum Enum2 {
a,
b,
c
}
public enum Enum3 {
a, b,
c, d
}
| public enum Enum1 { a, b, c }
public enum Enum2
{
a,
b,
c
}
public enum Enum3
{
a, b,
c, d
}
|
格式化前 | 格式化后,false |
|---|---|
public enum Enum1 { a, b, c }
public enum Enum2 {
a,
b,
c
}
public enum Enum3 {
a, b,
c, d
}
| public enum Enum1
{
a,
b,
c
}
public enum Enum2
{
a,
b,
c
}
public enum Enum3
{
a,
b,
c,
d
}
|
一行中的最大枚举成员数
属性名称:
[resharper_]csharp_max_enum_members_on_line, [resharper_]max_enum_members_on_line
可能的值:
一个整数
示例:
值:0 |
|---|
public enum Enum1
{
val1
}
public enum Enum2
{
val1,
val2
}
public enum Enum3
{
val1,
val2,
val3
}
public enum Enum4
{
val1,
val2,
val3,
val4
}
public enum Enum5
{
val1,
val2,
val3,
val4,
val5
}
public enum Enum6
{
val1,
val2,
val3,
val4,
val5,
val6
}
public enum Enum7
{
val1,
val2,
val3,
val4,
val5,
val6,
val7
}
public enum Enum8
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8
}
public enum Enum9
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8,
val9
}
|
值:1 |
|---|
public enum Enum1
{
val1
}
public enum Enum2
{
val1,
val2
}
public enum Enum3
{
val1,
val2,
val3
}
public enum Enum4
{
val1,
val2,
val3,
val4
}
public enum Enum5
{
val1,
val2,
val3,
val4,
val5
}
public enum Enum6
{
val1,
val2,
val3,
val4,
val5,
val6
}
public enum Enum7
{
val1,
val2,
val3,
val4,
val5,
val6,
val7
}
public enum Enum8
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8
}
public enum Enum9
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8,
val9
}
|
值:2 |
|---|
public enum Enum1
{
val1
}
public enum Enum2
{
val1, val2
}
public enum Enum3
{
val1, val2,
val3
}
public enum Enum4
{
val1, val2,
val3, val4
}
public enum Enum5
{
val1, val2,
val3, val4,
val5
}
public enum Enum6
{
val1, val2,
val3, val4,
val5, val6
}
public enum Enum7
{
val1, val2,
val3, val4,
val5, val6,
val7
}
public enum Enum8
{
val1, val2,
val3, val4,
val5, val6,
val7, val8
}
public enum Enum9
{
val1, val2,
val3, val4,
val5, val6,
val7, val8,
val9
}
|
将简单枚举置于单行中
属性名称:
[resharper_]csharp_place_simple_enum_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]csharp_place_simple_declaration_blocks_on_single_line, [resharper_]place_simple_enum_on_single_line, [resharper_]place_simple_blocks_on_single_line, [resharper_]place_simple_declaration_blocks_on_single_line
可能的值:
true | false
示例:
true |
|---|
public enum Enum1 { a, b, c }
|
false |
|---|
public enum Enum1
{
a, b, c
}
|
将枚举声明换行
属性名称:
[resharper_]csharp_wrap_enum_declaration, [resharper_]wrap_enum_declaration
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
public enum Enum1
{
a, b, c
}
public enum Enum2
{
aaaaa, bbbbb, ccccc,
ddddd, eeeee, fffff
}
|
chop_if_long |
|---|
public enum Enum1
{
a, b, c
}
public enum Enum2
{
aaaaa,
bbbbb,
ccccc,
ddddd,
eeeee,
fffff
}
|
chop_always |
|---|
public enum Enum1
{
a,
b,
c
}
public enum Enum2
{
aaaaa,
bbbbb,
ccccc,
ddddd,
eeeee,
fffff
}
|
语句的排列
将 'else' 置于新行中
属性名称:
csharp_new_line_before_else, [resharper_]new_line_before_else
可能的值:
true | false
示例:
true |
|---|
if (condition)
{
foo();
}
else
{
foo();
}
|
false |
|---|
if (condition)
{
foo();
} else
{
foo();
}
|
将 'while' 置于新行中
属性名称:
[resharper_]csharp_new_line_before_while, [resharper_]new_line_before_while
可能的值:
true | false
示例:
true |
|---|
do
{
foo();
}
while (condition);
|
false |
|---|
do
{
foo();
} while (condition);
|
将 'catch' 置于新行中
属性名称:
csharp_new_line_before_catch, [resharper_]new_line_before_catch
可能的值:
true|false
示例:
true |
|---|
try
{
foo();
}
catch (Exception e)
{
foo();
}
finally
{
foo();
}
|
false |
|---|
try
{
foo();
} catch (Exception e)
{
foo();
}
finally
{
foo();
}
|
将 'finally' 置于新行中
属性名称:
csharp_new_line_before_finally, [resharper_]new_line_before_finally
可能的值:
true|false
示例:
true |
|---|
try
{
foo();
}
catch (Exception e)
{
foo();
}
finally
{
foo();
}
|
false |
|---|
try
{
foo();
}
catch (Exception e)
{
foo();
} finally
{
foo();
}
|
换行 'for' 语句头
属性名称:
[resharper_]csharp_wrap_for_stmt_header_style, [resharper_]wrap_for_stmt_header_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
for (int i = initial;
i < loopLimit; i++)
{
}
|
chop_if_long |
|---|
for (int i = initial;
i < loopLimit;
i++)
{
}
|
chop_always |
|---|
for (int i = initial;
i < loopLimit;
i++)
{
}
|
将多个声明换行
属性名称:
[resharper_]csharp_wrap_multiple_declaration_style, [resharper_]wrap_multiple_declaration_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
class C
{
public int i = 0, j = 0,
k = 2, l = 3, m = 4,
n = 5;
}
|
chop_if_long |
|---|
class C
{
public int i = 0,
j = 0,
k = 2,
l = 3,
m = 4,
n = 5;
}
|
chop_always |
|---|
class C
{
public int i = 0,
j = 0,
k = 2,
l = 3,
m = 4,
n = 5;
}
|
嵌套语句的排列
保留嵌入式语句的现有排列
属性名称:
[resharper_]csharp_keep_existing_embedded_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_embedded_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
{
if (condition) DoSomething();
if (condition1)
DoSomething1();
}
| {
if (condition) DoSomething();
if (condition1)
DoSomething1();
}
|
格式化前 | 格式化后,false |
|---|---|
{
if (condition) DoSomething();
if (condition1)
DoSomething1();
}
| {
if (condition) DoSomething();
if (condition1) DoSomething1();
}
|
将简单嵌入式语句置于同一行中
属性名称:
[resharper_]csharp_place_simple_embedded_statement_on_same_line, [resharper_]place_simple_embedded_statement_on_same_line
可能的值:
false:从不永不:从不如果所有者为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
{
if (condition)
DoSomething();
if (condition && // comment
condition1)
DoSomething();
}
|
从未 |
|---|
{
if (condition)
DoSomething();
if (condition && // comment
condition1)
DoSomething();
}
|
如果所有者是单行 |
|---|
{
if (condition) DoSomething();
if (condition && // comment
condition1)
DoSomething();
}
|
true |
|---|
{
if (condition) DoSomething();
if (condition && // comment
condition1) DoSomething();
}
|
始终 |
|---|
{
if (condition) DoSomething();
if (condition && // comment
condition1) DoSomething();
}
|
将简单 'case' 语句置于同一行中
属性名称:
[resharper_]csharp_place_simple_case_statement_on_same_line, [resharper_]place_simple_case_statement_on_same_line
可能的值:
false:从不永不:从不如果所有者为单行:如果所有者是单行true:总是始终:总是
示例:
false |
|---|
switch (foo)
{
case 1:
return a;
case 2:
case 3:
return a;
}
|
从未 |
|---|
switch (foo)
{
case 1:
return a;
case 2:
case 3:
return a;
}
|
如果所有者是单行 |
|---|
switch (foo)
{
case 1: return a;
case 2:
case 3:
return a;
}
|
true |
|---|
switch (foo)
{
case 1: return a;
case 2:
case 3: return a;
}
|
始终 |
|---|
switch (foo)
{
case 1: return a;
case 2:
case 3: return a;
}
|
嵌套块的排列
保留嵌入式块的现有排列
属性名称:
[resharper_]csharp_keep_existing_embedded_block_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_embedded_block_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
{
if (condition) { DoSomething(); }
if (condition1)
{
DoSomething1();
}
}
| {
if (condition) { DoSomething(); }
if (condition1)
{
DoSomething1();
}
}
|
格式化前 | 格式化后,false |
|---|---|
{
if (condition) { DoSomething(); }
if (condition1)
{
DoSomething1();
}
}
| {
if (condition)
{
DoSomething();
}
if (condition1)
{
DoSomething1();
}
}
|
将带有单条简单语句的块置于同一行中
属性名称:
[resharper_]csharp_place_simple_embedded_block_on_same_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]place_simple_embedded_block_on_same_line, [resharper_]place_simple_blocks_on_single_line
可能的值:
true|false
示例:
true |
|---|
if (condition) { DoSomething(); }
|
false |
|---|
if (condition)
{
DoSomething();
}
|
将简单匿名方法置于单行中
属性名称:
[resharper_]csharp_place_simple_anonymousmethod_on_single_line, [resharper_]csharp_place_simple_blocks_on_single_line, [resharper_]place_simple_anonymousmethod_on_single_line, [resharper_]place_simple_blocks_on_single_line
可能的值:
true|false
示例:
true |
|---|
EventHandler e = delegate { return; };
|
false |
|---|
EventHandler e = delegate
{
return;
};
|
switch 表达式的排列
保留 switch 表达式的现有排列
属性名称:
[resharper_]csharp_keep_existing_switch_expression_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_switch_expression_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
{
var result = x switch {
T.A => 0, T.B => 1
};
var result = x switch { T.A => 0, T.B => 1 };
}
| {
var result = x switch
{
T.A => 0, T.B => 1
};
var result = x switch { T.A => 0, T.B => 1 };
}
|
格式化前 | 格式化后,false |
|---|---|
{
var result = x switch {
T.A => 0, T.B => 1
};
var result = x switch { T.A => 0, T.B => 1 };
}
| {
var result = x switch
{
T.A => 0,
T.B => 1
};
var result = x switch
{
T.A => 0,
T.B => 1
};
}
|
将简单 switch 表达式置于单行中
属性名称:
[resharper_]csharp_place_simple_switch_expression_on_single_line, [resharper_]place_simple_switch_expression_on_single_line
可能的值:
true|false
示例:
true |
|---|
var result = x switch { T.A => 0, T.B => 1 };
|
false |
|---|
var result = x switch
{
T.A => 0, T.B => 1
};
|
将 switch 表达式换行
属性名称:
[resharper_]csharp_wrap_switch_expression, [resharper_]wrap_switch_expression
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
(x switch
{
T.A => 0, T.B => 1, T.C => 2
}) +
(x switch
{
T.A => 0, T.B => 1 +
2,
T.C => 2
})
|
chop_if_long |
|---|
(x switch
{
T.A => 0, T.B => 1, T.C => 2
}) +
(x switch
{
T.A => 0,
T.B => 1 +
2,
T.C => 2
})
|
chop_always |
|---|
(x switch
{
T.A => 0,
T.B => 1,
T.C => 2
}) +
(x switch
{
T.A => 0,
T.B => 1 +
2,
T.C => 2
})
|
属性模式的排列
保留属性模式的现有排列
属性名称:
[resharper_]csharp_keep_existing_property_patterns_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_property_patterns_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
bool matches = sourceObject is MyType {
F1: 1,
F2: 2
} &&
sourceObject is MyType { F1: 1, F2: 2 };
| bool matches = sourceObject is MyType
{
F1: 1,
F2: 2
} &&
sourceObject is MyType { F1: 1, F2: 2 };
|
格式化前 | 格式化后,false |
|---|---|
bool matches = sourceObject is MyType {
F1: 1,
F2: 2
} &&
sourceObject is MyType { F1: 1, F2: 2 };
| bool matches = sourceObject is MyType { F1: 1, F2: 2 } &&
sourceObject is MyType { F1: 1, F2: 2 };
|
将简单属性模式置于单行中
属性名称:
[resharper_]csharp_place_simple_property_pattern_on_single_line, [resharper_]place_simple_property_pattern_on_single_line
可能的值:
true|false
示例:
true |
|---|
bool matches = sourceObject is MyType { F1: 1, F2: 2 };
|
false |
|---|
bool matches = sourceObject is MyType
{
F1: 1, F2: 2
};
|
将属性模式换行
属性名称:
[resharper_]csharp_wrap_property_pattern, [resharper_]wrap_property_pattern
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
bool matches =
sourceObject is MyType
{
F1: 1, F2: 2
} &&
sourceObject is MyType
{
F1: 1, F2: 2, F3: 3, F4: 4,
F5: 5, F6: 6, F7: 7, F8: 8
};
|
chop_if_long |
|---|
bool matches =
sourceObject is MyType
{
F1: 1, F2: 2
} &&
sourceObject is MyType
{
F1: 1,
F2: 2,
F3: 3,
F4: 4,
F5: 5,
F6: 6,
F7: 7,
F8: 8
};
|
chop_always |
|---|
bool matches = sourceObject is MyType
{
F1: 1,
F2: 2
} &&
sourceObject is MyType
{
F1: 1,
F2: 2,
F3: 3,
F4: 4,
F5: 5,
F6: 6,
F7: 7,
F8: 8
};
|
列表模式的排列
保留列表模式和集合表达式的现有排列
属性名称:
[resharper_]csharp_keep_existing_list_patterns_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_list_patterns_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
true |
|---|
int[] collection =
[
1,
2,
3,
4,
5,
6
];
var otherCollection = [1, 2, 3, 4, 5, 6];
var matches = collection is
[
1,
> 0,
not 42,
4,
5,
6
];
var otherMatches = otherCollection is [1, 2, 3, 4, 5, 6];
|
false |
|---|
int[] collection = [1, 2, 3, 4, 5, 6];
var otherCollection = [1, 2, 3, 4, 5, 6];
var matches = collection is [1, > 0, not 42, 4, 5, 6];
var otherMatches = otherCollection is [1, 2, 3, 4, 5, 6];
|
将简单列表模式和集合表达式置于单行中
属性名称:
[resharper_]csharp_place_simple_list_pattern_on_single_line, [resharper_]place_simple_list_pattern_on_single_line
可能的值:
true|false
示例:
true |
|---|
int[] collection = [1, 2, 3, 4, 5, 6, 7, 8];
var matches = collection is [1, > 0, not 42, 4, 5, 6, 7, 8];
|
false |
|---|
int[] collection =
[
1, 2, 3, 4, 5, 6, 7, 8
];
var matches = collection is
[
1, > 0, not 42, 4, 5, 6, 7, 8
];
|
将列表模式和集合表达式换行
属性名称:
[resharper_]csharp_wrap_list_pattern, [resharper_]wrap_list_pattern
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
int[] collection =
[
Element1, Element2, Element3,
Element4, Element5, Element6,
Element7
];
var matches = collection is
[
1, 2, > 0, 4, 5, 6, not 42, 8,
9, 10, 11, 12, 13
];
|
chop_if_long |
|---|
int[] collection =
[
Element1,
Element2,
Element3,
Element4,
Element5,
Element6,
Element7
];
var matches = collection is
[
1,
2,
> 0,
4,
5,
6,
not 42,
8,
9,
10,
11,
12,
13
];
|
chop_always |
|---|
int[] collection =
[
Element1,
Element2,
Element3,
Element4,
Element5,
Element6,
Element7
];
var matches = collection is
[
1,
2,
> 0,
4,
5,
6,
not 42,
8,
9,
10,
11,
12,
13
];
|
初始化器的排列
保留初始值设定项的现有排列
属性名称:
[resharper_]csharp_keep_existing_initializer_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_initializer_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
{
var result = new {
A = 0
};
var result = new { A = 0 };
}
| {
var result = new
{
A = 0
};
var result = new { A = 0 };
}
|
格式化前 | 格式化后,false |
|---|---|
{
var result = new {
A = 0
};
var result = new { A = 0 };
}
| {
var result = new { A = 0 };
var result = new { A = 0 };
}
|
将简单数组、对象和集合置于单行中
属性名称:
[resharper_]csharp_place_simple_initializer_on_single_line, [resharper_]place_simple_initializer_on_single_line
可能的值:
true|false
示例:
true |
|---|
var result = new { A = 0 };
|
false |
|---|
var result = new
{
A = 0
};
|
一行中的最大对象和集合初始值设定项元素数
属性名称:
[resharper_]csharp_max_initializer_elements_on_line, [resharper_]max_initializer_elements_on_line
可能的值:
一个整数
示例:
值:0 |
|---|
{
x = new C() { Prop1 = 1 };
x = new C()
{
Prop1 = 1,
Prop2 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1,
Prop7 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1,
Prop7 = 1,
Prop8 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1,
Prop7 = 1,
Prop8 = 1,
Prop9 = 1
};
}
|
值:1 |
|---|
{
x = new C() { Prop1 = 1 };
x = new C()
{
Prop1 = 1,
Prop2 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1,
Prop7 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1,
Prop7 = 1,
Prop8 = 1
};
x = new C()
{
Prop1 = 1,
Prop2 = 1,
Prop3 = 1,
Prop4 = 1,
Prop5 = 1,
Prop6 = 1,
Prop7 = 1,
Prop8 = 1,
Prop9 = 1
};
}
|
值:2 |
|---|
{
x = new C() { Prop1 = 1 };
x = new C() { Prop1 = 1, Prop2 = 1 };
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1
};
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1, Prop4 = 1
};
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1, Prop4 = 1,
Prop5 = 1
};
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1, Prop4 = 1,
Prop5 = 1, Prop6 = 1
};
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1, Prop4 = 1,
Prop5 = 1, Prop6 = 1,
Prop7 = 1
};
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1, Prop4 = 1,
Prop5 = 1, Prop6 = 1,
Prop7 = 1, Prop8 = 1
};
x = new C()
{
Prop1 = 1, Prop2 = 1,
Prop3 = 1, Prop4 = 1,
Prop5 = 1, Prop6 = 1,
Prop7 = 1, Prop8 = 1,
Prop9 = 1
};
}
|
将对象和集合初始值设定项换行
属性名称:
[resharper_]csharp_wrap_object_and_collection_initializer_style, [resharper_]wrap_object_and_collection_initializer_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
new C()
{
PropertyX = 1, PropertyY = 2,
PropertyZ = 3
}
|
chop_if_long |
|---|
new C()
{
PropertyX = 1,
PropertyY = 2,
PropertyZ = 3
}
|
chop_always |
|---|
new C()
{
PropertyX = 1,
PropertyY = 2,
PropertyZ = 3
}
|
一行中的最大数组初始值设定项和集合表达式元素数
属性名称:
[resharper_]csharp_max_array_initializer_elements_on_line, [resharper_]max_array_initializer_elements_on_line
可能的值:
一个整数
示例:
值:0 |
|---|
{
x = new[] { val1 };
x = new[]
{
val1,
val2
};
x = new[]
{
val1,
val2,
val3
};
x = new[]
{
val1,
val2,
val3,
val4
};
x = new[]
{
val1,
val2,
val3,
val4,
val5
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6,
val7
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8,
val9
};
}
|
值:1 |
|---|
{
x = new[] { val1 };
x = new[]
{
val1,
val2
};
x = new[]
{
val1,
val2,
val3
};
x = new[]
{
val1,
val2,
val3,
val4
};
x = new[]
{
val1,
val2,
val3,
val4,
val5
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6,
val7
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8
};
x = new[]
{
val1,
val2,
val3,
val4,
val5,
val6,
val7,
val8,
val9
};
}
|
值:2 |
|---|
{
x = new[] { val1 };
x = new[] { val1, val2 };
x = new[]
{
val1, val2,
val3
};
x = new[]
{
val1, val2,
val3, val4
};
x = new[]
{
val1, val2,
val3, val4,
val5
};
x = new[]
{
val1, val2,
val3, val4,
val5, val6
};
x = new[]
{
val1, val2,
val3, val4,
val5, val6,
val7
};
x = new[]
{
val1, val2,
val3, val4,
val5, val6,
val7, val8
};
x = new[]
{
val1, val2,
val3, val4,
val5, val6,
val7, val8,
val9
};
}
|
将数组初始值设定项换行
属性名称:
[resharper_]csharp_wrap_array_initializer_style, [resharper_]wrap_array_initializer_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
new C[]
{
Element1, ElementX, ElementY,
ElementZ, ElementZzz
}
|
chop_if_long |
|---|
new C[]
{
Element1,
ElementX,
ElementY,
ElementZ,
ElementZzz
}
|
chop_always |
|---|
new C[]
{
Element1,
ElementX,
ElementY,
ElementZ,
ElementZzz
}
|
调用的排列
将调用实参换行
属性名称:
[resharper_]csharp_wrap_arguments_style, [resharper_]wrap_arguments_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
{
CallMethod(arg1, arg2);
CallMethod(arg1, arg2,
arg3, arg4, arg5);
}
|
chop_if_long |
|---|
{
CallMethod(arg1, arg2);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5);
}
|
chop_always |
|---|
{
CallMethod(arg1,
arg2);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5);
}
|
一行中的最大调用实参数
属性名称:
[resharper_]csharp_max_invocation_arguments_on_line, [resharper_]max_invocation_arguments_on_line
可能的值:
一个整数
示例:
值:0 |
|---|
{
CallMethod(arg1);
CallMethod(arg1,
arg2);
CallMethod(arg1,
arg2,
arg3);
CallMethod(arg1,
arg2,
arg3,
arg4);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7,
arg8);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7,
arg8,
arg9);
}
|
值:1 |
|---|
{
CallMethod(arg1);
CallMethod(arg1,
arg2);
CallMethod(arg1,
arg2,
arg3);
CallMethod(arg1,
arg2,
arg3,
arg4);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7,
arg8);
CallMethod(arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7,
arg8,
arg9);
}
|
值:2 |
|---|
{
CallMethod(arg1);
CallMethod(arg1, arg2);
CallMethod(arg1, arg2,
arg3);
CallMethod(arg1, arg2,
arg3, arg4);
CallMethod(arg1, arg2,
arg3, arg4,
arg5);
CallMethod(arg1, arg2,
arg3, arg4,
arg5, arg6);
CallMethod(arg1, arg2,
arg3, arg4,
arg5, arg6,
arg7);
CallMethod(arg1, arg2,
arg3, arg4,
arg5, arg6,
arg7, arg8);
CallMethod(arg1, arg2,
arg3, arg4,
arg5, arg6,
arg7, arg8,
arg9);
}
|
保留调用中圆括号的现有排列
属性名称:
[resharper_]csharp_keep_existing_invocation_parens_arrangement, [resharper_]csharp_keep_existing_arrangement, [resharper_]keep_existing_invocation_parens_arrangement, [resharper_]keep_existing_arrangement
可能的值:
true|false
示例:
格式化前 | 格式化后,true |
|---|---|
CallMethod
(
arg1, arg2,
arg3, arg4, arg5
);
| CallMethod
(
arg1, arg2,
arg3, arg4, arg5
);
|
格式化前 | 格式化后,false |
|---|---|
CallMethod
(
arg1, arg2,
arg3, arg4, arg5
);
| CallMethod(arg1, arg2,
arg3, arg4, arg5);
|
首选在调用中的 '(' 前换行
属性名称:
[resharper_]csharp_wrap_before_invocation_lpar, [resharper_]wrap_before_invocation_lpar
可能的值:
true|false
示例:
true |
|---|
CallMethod
(arg1, arg2,
arg3, arg4, arg5);
|
false |
|---|
CallMethod(arg1, arg2,
arg3, arg4, arg5);
|
首选在调用中的 '(' 后换行
属性名称:
[resharper_]csharp_wrap_after_invocation_lpar, [resharper_]wrap_after_invocation_lpar
可能的值:
true|false
示例:
true |
|---|
CallMethod(
arg1, arg2,
arg3, arg4, arg5);
|
false |
|---|
CallMethod(arg1, arg2,
arg3, arg4, arg5);
|
首选在调用中的 ')' 前换行
属性名称:
[resharper_]csharp_wrap_before_invocation_rpar, [resharper_]wrap_before_invocation_rpar
可能的值:
true|false
示例:
true |
|---|
CallMethod(arg1, arg2,
arg3, arg4, arg5
);
|
false |
|---|
CallMethod(arg1, arg2,
arg3, arg4, arg5);
|
成员访问表达式的排列
首选在 '.' 后换行
属性名称:
[resharper_]csharp_wrap_after_dot_in_method_calls, [resharper_]wrap_after_dot_in_method_calls
可能的值:
true|false
示例:
true |
|---|
obj.Method().
Method().
Method().
Method().
Method().
Method().
Method().
Method().
Method().
Method();
|
false |
|---|
obj.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method();
|
将链式方法调用换行
属性名称:
[resharper_]csharp_wrap_chained_method_calls, [resharper_]wrap_chained_method_calls
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
obj.Method().Method() +
obj.Method().Method()
.Method().Method()
.Method().Method()
.Method().Method()
.Method().Method();
|
chop_if_long |
|---|
obj.Method().Method() +
obj.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method();
|
chop_always |
|---|
obj.Method()
.Method() +
obj.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method();
|
首选在第一个方法调用前换行
属性名称:
[resharper_]csharp_wrap_before_first_method_call, [resharper_]wrap_before_first_method_call
可能的值:
true|false
示例:
true |
|---|
obj
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method();
|
false |
|---|
obj.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method()
.Method();
|
首选在链式方法调用中的属性和字段后换行
属性名称:
[resharper_]csharp_wrap_after_property_in_chained_method_calls, [resharper_]wrap_after_property_in_chained_method_calls
可能的值:
true|false
示例:
true |
|---|
obj.Property
.Method()
.Property
.Method()
.Property
.Method()
.Property
.Method()
.Property
.Method();
|
false |
|---|
obj.Property.Method()
.Property.Method()
.Property.Method()
.Property.Method()
.Property.Method();
|
二元表达式的排列
首选在二元表达式中的运算符前换行
属性名称:
[resharper_]csharp_wrap_before_binary_opsign, [resharper_]wrap_before_binary_opsign
可能的值:
true|false
示例:
true |
|---|
myField1 = expression1
+ expression2
+ expression3
+ expression4
+ expression5
+ expression6
+ expression7;
|
false |
|---|
myField1 = expression1 +
expression2 +
expression3 +
expression4 +
expression5 +
expression6 +
expression7;
|
将链式二元表达式换行
属性名称:
[resharper_]csharp_wrap_chained_binary_expressions, [resharper_]wrap_chained_binary_expressions
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割
示例:
wrap_if_long |
|---|
b = a != b && c != d && e &&
f.IsSumOf(g, h) &&
i.Value == j && k == l &&
m == n && o == p;
|
chop_if_long |
|---|
b = a != b &&
c != d &&
e &&
f.IsSumOf(g, h) &&
i.Value == j &&
k == l &&
m == n &&
o == p;
|
首选在二元模式中的运算符前换行
属性名称:
[resharper_]csharp_wrap_before_binary_pattern_op, [resharper_]wrap_before_binary_pattern_op
可能的值:
true|false
示例:
true |
|---|
b = foo is VeryLongName1
or VeryLongName2
or VeryLongName3
or VeryLongName4
or VeryLongName5;
|
false |
|---|
b = foo is VeryLongName1 or
VeryLongName2 or
VeryLongName3 or
VeryLongName4 or
VeryLongName5;
|
将复杂二元模式换行
属性名称:
[resharper_]csharp_wrap_chained_binary_patterns, [resharper_]wrap_chained_binary_patterns
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割
示例:
wrap_if_long |
|---|
b = foo is C1 or C2 or C3 or C4
or C5 or VeryLongName1
or VeryLongName2
or VeryLongName3;
|
chop_if_long |
|---|
b = foo is C1
or C2
or C3
or C4
or C5
or VeryLongName1
or VeryLongName2
or VeryLongName3;
|
在 'if' 语句中强制拆分复合条件
属性名称:
[resharper_]csharp_force_chop_compound_if_expression, [resharper_]force_chop_compound_if_expression
可能的值:
true|false
示例:
true |
|---|
if (var1 == null ||
var2 == null)
Foo();
|
false |
|---|
if (var1 == null || var2 == null)
Foo();
|
在 'while' 语句中强制拆分复合条件
属性名称:
[resharper_]csharp_force_chop_compound_while_expression, [resharper_]force_chop_compound_while_expression
可能的值:
true|false
示例:
true |
|---|
while (var1 == null ||
var2 == null)
Foo();
|
false |
|---|
while (var1 == null || var2 == null)
Foo();
|
在 'do' 语句中强制拆分复合条件
属性名称:
[resharper_]csharp_force_chop_compound_do_expression, [resharper_]force_chop_compound_do_expression
可能的值:
true|false
示例:
true |
|---|
do
{
Foo();
} while (var1 == null ||
var2 == null);
|
false |
|---|
do
{
Foo();
} while (var1 == null || var2 == null);
|
三元表达式的排列
首选在三元表达式中的 '?' 和 ':' 前换行
属性名称:
[resharper_]csharp_wrap_before_ternary_opsigns, [resharper_]wrap_before_ternary_opsigns
可能的值:
true|false
示例:
true |
|---|
return hereGoesSomeBoolExpression
? returnThisIfTrue
: returnThatIfFalse;
|
false |
|---|
return hereGoesSomeBoolExpression ?
returnThisIfTrue :
returnThatIfFalse;
|
将三元表达式换行
属性名称:
[resharper_]csharp_wrap_ternary_expr_style, [resharper_]wrap_ternary_expr_style
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
myField = someCondition ? true
: false;
|
chop_if_long |
|---|
myField = someCondition
? true
: false;
|
chop_always |
|---|
myField = someCondition
? true
: false;
|
嵌套三元表达式样式
属性名称:
[resharper_]csharp_nested_ternary_style, [resharper_]nested_ternary_style
可能的值:
simple_wrap:简单换行/不更改autodetect:以现有样式拆分compact:以紧凑样式拆分expanded:以扩展样式拆分
示例:
格式化前 | 格式化后,simple_wrap |
|---|---|
{
a = i ? "am" : you ? "are" : "is";
b = error ? red :
warning ? yellow :
green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses ? red
: violets ? blue
: so_are_you;
}
| {
a = i ? "am" : you ? "are"
: "is";
b = error ? red :
warning ? yellow :
green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses ? red
: violets ? blue
: so_are_you;
}
|
格式化前 | 格式化后,autodetect |
|---|---|
{
a = i ? "am" : you ? "are" : "is";
b = error ? red :
warning ? yellow :
green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses ? red
: violets ? blue
: so_are_you;
}
| {
a = i ? "am" :
you ? "are" : "is";
b = error ? red :
warning ? yellow :
green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses ? red
: violets ? blue
: so_are_you;
}
|
格式化前 | 格式化后,compact |
|---|---|
{
a = i ? "am" : you ? "are" : "is";
b = error ? red :
warning ? yellow :
green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses ? red
: violets ? blue
: so_are_you;
}
| {
a = i ? "am" :
you ? "are" : "is";
b = error ? red :
warning ? yellow :
green;
c = tiger ? dangerous :
cat ? cute : boring;
d = roses ? red :
violets ? blue :
so_are_you;
}
|
格式化前 | 格式化后,expanded |
|---|---|
{
a = i ? "am" : you ? "are" : "is";
b = error ? red :
warning ? yellow :
green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses ? red
: violets ? blue
: so_are_you;
}
| {
a = i
? "am"
: you
? "are"
: "is";
b = error
? red
: warning
? yellow
: green;
c = tiger
? dangerous
: cat
? cute
: boring;
d = roses
? red
: violets
? blue
: so_are_you;
}
|
LINQ 表达式的排列
将 LINQ 表达式换行
属性名称:
[resharper_]csharp_wrap_linq_expressions, [resharper_]wrap_linq_expressions
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割chop_always:始终分割
示例:
wrap_if_long |
|---|
var result = from x in list
where cond(x) select x;
|
chop_if_long |
|---|
var result = from x in list
where cond(x)
select x;
|
chop_always |
|---|
var result = from x in list
where cond(x)
select x;
|
首选在多行 LINQ 表达式前换行
属性名称:
[resharper_]csharp_wrap_before_linq_expression, [resharper_]wrap_before_linq_expression
可能的值:
true|false
示例:
true |
|---|
var result =
from x in list
where cond(x)
select x;
|
false |
|---|
var result = from x in list
where cond(x)
select x;
|
在 LINQ 表达式中将 'into' 置于新行中
属性名称:
[resharper_]csharp_place_linq_into_on_new_line, [resharper_]place_linq_into_on_new_line
可能的值:
true|false
示例:
true |
|---|
var q1 = from i in l
select i
into j
where j != 0
select j;
|
false |
|---|
var q1 = from i in l
select i into j
where j != 0
select j;
|
插值字符串的排列
将内插字符串换行
属性名称:
[resharper_]csharp_wrap_verbatim_interpolated_strings, [resharper_]wrap_verbatim_interpolated_strings
可能的值:
wrap_if_long:简单换行chop_if_long:如果过长或多行则分割no_wrap:即使过长也不换行
示例:
wrap_if_long |
|---|
var s1 = $"id={id} src={src
} dest={dest}";
var s2 = $@"id={id} src={src
} dest={dest}";
var s3 = $"""
id={id} src={src
} dest={dest}
""";
|
chop_if_long |
|---|
var s1 = $"id={
id
} src={
src
} dest={
dest
}";
var s2 = $@"id={
id
} src={
src
} dest={
dest
}";
var s3 = $"""
id={
id
} src={
src
} dest={
dest
}
""";
|
no_wrap |
|---|
var s1 =
$"id={id} src={src} dest={dest}";
var s2 =
$@"id={id} src={src} dest={dest}";
var s3 = $"""
id={id} src={src} dest={dest}
""";
|