You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JetBrains Rider移除delegate与括号间空格的配置问题

解决Rider与Visual Studio 2022中delegate括号空格不一致的问题

问题背景

团队成员分别使用JetBrains Rider和Visual Studio 2022,执行代码清理时出现格式冲突:

  • VS 2022会在delegate与()之间添加空格:
    var cat = this.ExecuteAFunction("Function Name Here", delegate () {});
    
  • Rider会自动移除该空格:
    var cat = this.ExecuteAFunction("Function Name Here", delegate() {});
    

之前尝试调整Rider里Editor > Code Style > C#下的Before Other Parentheses -> Method call parentheses,但该设置会影响所有方法,无法单独针对delegate配置。且公司编码规范要求必须保留delegate () {}写法,不能替换为箭头函数。

解决方案

方法一:Rider图形界面单独配置

  1. 打开Rider设置(快捷键Ctrl+Alt+S,或通过File → Settings)
  2. 导航到Editor > Code Style > C# > Braces, Parentheses and Brackets
  3. 切换到Parentheses标签页,找到Anonymous method declaration选项,将Before opening parenthesis设置为Add space
  4. 点击Apply和OK,之后Rider执行代码清理时会保留delegate与()之间的空格,与VS2022行为一致。

方法二:用.editorconfig统一团队规范

在项目根目录的.editorconfig文件中添加以下配置,确保Rider和VS2022遵循同一格式:

# 匿名方法的delegate与括号之间添加空格
csharp_space_before_parentheses_in_anonymous_method_declaration = true

该配置仅作用于匿名方法的delegate关键字后,不会影响普通方法调用的括号格式,完美解决之前设置范围过广的问题。

内容的提问来源于stack exchange,提问作者t3mp0ralflux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 16:02:07