JetBrains Rider 2025.2 Help

用于 C# 的 EditorConfig 属性:大括号布局

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

大括号布局

类型和命名空间声明

属性名称:

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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑(Pico 风格)

示例:

行尾

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

行尾无空格

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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑(Pico 风格)

示例:

行尾

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

行尾无空格

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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑(Pico 风格)

示例:

行尾

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

行尾无空格

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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑(Pico 风格)

示例:

行尾

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

行尾无空格

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

下一行

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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑格式(Pico 风格)

示例:

行尾

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

行尾无空格

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

下一行

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

下一行缩进

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

下一行缩进 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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑(Pico 风格)

示例:

行尾

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

行尾无空格

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

下一行

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

下一行缩进

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

下一行缩进 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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑(Pico 风格)

示例:

行尾

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

行尾无空格

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

下一行

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

下一行缩进

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

下一行缩进 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

可能的值:

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

  • 行尾无空格 :行尾(无空格)

  • 下一行 :下一行(BSD 风格)

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

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

  • pico :紧凑格式(Pico 风格)

示例:

行尾

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

行尾无空格

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

下一行

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

下一行缩进

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

下一行缩进 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

可能的值:

  • 多行 :在不同的行上

  • 一起 :将大括号放在一起

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

示例:

多行

class C { void EmptyMethod() { } }

一起

class C { void EmptyMethod() { } }

同一行一起

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