ReSharper 2025.2 Help

针对 C# 的 EditorConfig 属性:大括号布局

此页面列出了自定义 ReSharper EditorConfig 属性 ,您可以使用这些属性来配置 C# 的格式化偏好,特别是 ReSharper 在生成新代码和 重新格式化现有代码时如何排列大括号;尤其是,大括号在 iffor 运算符后的位置有多种方式。

大括号布局

类型和命名空间声明

属性名称:

[resharper_]csharp_type_declaration_braces, [resharper_]csharp_brace_style, [resharper_]type_declaration_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

namespace N { interface I { void foo(); } class C { } }

end_of_line_no_space

namespace N{ interface I{ void foo(); } class C{ } }

下一行

namespace N { interface I { void foo(); } class C { } }

下一行缩进

namespace N { interface I { void foo(); } class C { } }

下一行缩进 2

namespace N { interface I { void foo(); } class C { } }

pico

namespace N { interface I { void foo(); } class C { } }

在命名空间声明中缩进

属性名称:

[resharper_]csharp_indent_inside_namespace[resharper_]indent_inside_namespace

可能的值:

true|false

示例:

true

namespace N { interface I { void foo(); } class C { } }

false

namespace N { interface I { void foo(); } class C { } }

方法声明

属性名称:

[resharper_]csharp_invocable_declaration_braces, [resharper_]csharp_brace_style, [resharper_]invocable_declaration_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

class C { void Method() { foo(); foo1(); } }

end_of_line_no_space

class C { void Method(){ foo(); foo1(); } }

下一行

class C { void Method() { foo(); foo1(); } }

下一行缩进

class C { void Method() { foo(); foo1(); } }

下一行缩进 2

class C { void Method() { foo(); foo1(); } }

pico

class C { void Method() { foo(); foo1(); } }

lambda 和委托(匿名方法声明)

属性名称:

[resharper_]csharp_anonymous_method_declaration_braces, [resharper_]csharp_brace_style, [resharper_]anonymous_method_declaration_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

D d = delegate() { int x = 0; return x; }

end_of_line_no_space

D d = delegate(){ int x = 0; return x; }

下一行

D d = delegate() { int x = 0; return x; }

下一行缩进

D d = delegate() { int x = 0; return x; }

下一行缩进 2

D d = delegate() { int x = 0; return x; }

pico

D d = delegate() { int x = 0; return x; }

属性声明

属性名称:

[resharper_]csharp_accessor_owner_declaration_braces, [resharper_]csharp_brace_style, [resharper_]accessor_owner_declaration_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

class C { int Property { get { return null; } set { } } }

end_of_line_no_space

class C { int Property{ get { return null; } set { } } }

next_line

class C { int Property { get { return null; } set { } } }

下一行缩进

class C { int Property { get { return null; } set { } } }

下一行缩进 2

class C { int Property { get { return null; } set { } } }

pico

class C { int Property { get { return null; } set { } } }

访问器声明

属性名称:

[resharper_]csharp_accessor_declaration_braces, [resharper_]csharp_brace_style, [resharper_]accessor_declaration_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

end_of_line_no_space

class C { int Property { get{ return null; } set{ Notify(value); Set(value); } } }

next_line

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

next_line_shifted

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

next_line_shifted_2

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

pico

class C { int Property { get { return null; } set { Notify(value); Set(value); } } }

'case' 标签下的块

属性名称:

[resharper_]csharp_case_block_braces, [resharper_]csharp_brace_style, [resharper_]case_block_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

switch (expression) { case 0: { foo(); break; } }

end_of_line_no_space

switch (expression) { case 0:{ foo(); break; } }

next_line

switch (expression) { case 0: { foo(); break; } }

next_line_shifted

switch (expression) { case 0: { foo(); break; } }

next_line_shifted_2

switch (expression) { case 0: { foo(); break; } }

pico

switch (expression) { case 0: { foo(); break; } }

表达式(初始值设定项、switch 表达式、模式、集合表达式)

属性名称:

[resharper_]csharp_initializer_braces, [resharper_]csharp_brace_style, [resharper_]initializer_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

int[] array = new int[] { 1, 2, 3 }

end_of_line_no_space

int[] array = new int[]{ 1, 2, 3 }

next_line

int[] array = new int[] { 1, 2, 3 }

next_line_shifted

int[] array = new int[] { 1, 2, 3 }

next_line_shifted_2

int[] array = new int[] { 1, 2, 3 }

pico

int[] array = new int[] { 1, 2, 3 }

在表达式大括号内使用连续行缩进

属性名称:

[resharper_]csharp_use_continuous_indent_inside_initializer_braces[resharper_]use_continuous_indent_inside_initializer_braces

可能的值:

true | false

示例:

true

int[] array = new int[] { 1, 2, 3 }

false

int[] array = new int[] { 1, 2, 3 }

其它

属性名称:

[resharper_]csharp_other_braces, [resharper_]csharp_brace_style, [resharper_]other_braces, [resharper_]brace_style

可能的值:

  • end_of_line :行尾(K&R 风格)

  • end_of_line_no_space :行尾(无空格)

  • next_line :下一行(BSD 风格)

  • next_line_shifted :下一行缩进(Whitesmiths 风格)

  • next_line_shifted_2 :下一行缩进 2(GNU 风格)

  • pico :紧凑(Pico 风格)

示例:

end_of_line

if (condition) { foo(); } else { foo(); }

end_of_line_no_space

if (condition){ foo(); } else{ foo(); }

next_line

if (condition) { foo(); } else { foo(); }

next_line_shifted

if (condition) { foo(); } else { foo(); }

next_line_shifted_2

if (condition) { foo(); } else { foo(); }

pico

if (condition) { foo(); } else { foo(); }

允许在 '{' 后添加注释

属性名称:

[resharper_]csharp_allow_comment_after_lbrace[resharper_]allow_comment_after_lbrace

可能的值:

true | false

示例:

true

if (condition) { // comment statement; }

false

if (condition) { // comment statement; }

空大括号格式设置

属性名称:

[resharper_]csharp_empty_block_style[resharper_]empty_block_style

可能的值:

  • multiline :在不同的行上

  • together :将大括号放在一起

  • together_same_line :在同一行上放在一起

示例:

多行

class C { void EmptyMethod() { } }

一起

class C { void EmptyMethod() { } }

同一行一起

class C { void EmptyMethod() { } }
最后修改日期: 2025年 9月 27日