【问题标题】:How to fix Resharper object initializer indentation as method argument如何修复 Resharper 对象初始化程序缩进作为方法参数
【发布时间】:2017-04-29 19:53:00
【问题描述】:

Resharper 2016.2

当前格式

IEnumerable<Customer> customers = dbCustomers.Select(customer => new Customer
                                                     {
                                                         Name = customer.Name,
                                                         Address = customer.Address,
                                                         Number = customer.Number
                                                     });

预期格式

IEnumerable<Customer> customers = dbCustomers.Select(customer => new Customer
{
    Name = customer.Name,
    Address = customer.Address,
    Number = customer.Number
});

哪种 Resharper 2016.2 配置可以解决这个问题?

请注意,初始化器在参数括号内,而不是在变量中。

【问题讨论】:

  • 你试过这个:选项 -> 代码编辑 -> C# -> 格式化样式 -> 其他 -> 对齐多行结构 -> 数组、对象和集合初始化器
  • @OscarSiauw:是的,这个选项被禁用了。

标签: c# .net resharper code-formatting


【解决方案1】:

如果仍然有人需要帮助,试试这个: Resharper 选项 --> 代码编辑 --> C# --> 格式化样式 --> 其他 --> 取消选中“数组、对象和集合初始值设定项”。

然后在:Resharper Options --> Code Editing --> C# --> Formatting Style --> Braces Layout --> "Array and object initializer" = "At next line (BSD Style)".

您也可以这样做,这样会更好一些: Resharper Options --> Code Editing --> C# --> Formatting Style --> Line Breaks and Wrappings --> "Wrap object and collection initializer" = "Chop if long or multiline"。

【讨论】:

    【解决方案2】:

    这对我有用。希望对您有所帮助!

    转到 Resharper -> Visual Studio 菜单栏中的选项。

    在树视图上:

    代码编辑 -> C# -> 格式样式 -> 大括号布局

    在右侧面板上:

    数组和对象初始化器

    • 展开选项组合框。
    • 选择At the next Line (BSD style)(第三个选项)。

    【讨论】:

    • 此选项已启用。它不会按预期更改格式。问题是,初始化器在方法参数列表中。
    【解决方案3】:

    更新到 2016.3 版本之后,它刚刚开始工作,没有对 R# 设置进行任何更改。

    【讨论】:

      猜你喜欢
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 2016-05-26
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多