How to stop ReSharper from inserting unnecessary newline between the assigned variable and chained method call(如何阻止ReSharper在赋值变量和链接方法调用之间插入不必要的换行符)
问题描述
我有一个类,它有一些返回this
的方法,这样我就可以将调用链接在一起:
public class Person {
public string FirstName { get; set; }
public string LastName { get; set; }
public Person WithFirstName(string firstName) {
FirstName = firstName;
return this;
}
public Person WithLastName(string lastName) {
LastName = lastName;
return this;
}
}
但是,当我将足够多的方法链接在一起,以至于ReSharper中的Right margin (columns)
设置时,表达式的格式有点时髦。
var john =
new Person().WithFirstName("John")
.WithLastName("Smith")
.WithLastName("Smith")
.WithLastName("Smith")
.WithLastName("Smith");
显然,这个示例有点做作,因为我永远不会一遍又一遍地调用相同的方法,但在我的产品代码中,我与一个流畅的API交互,该API是通过将大约10个方法调用链接在一起来配置的。
理想情况下,代码的格式如下:
// on a single line when less characters than `Right margin (columns)`
var john = new Person().WithFirstName("John").WithLastName("Smith");
// aligned at the "." when longer than `Right margin (columns)`
var john = new Person().WithFirstName("John")
.WithLastName("Smith")
.WithLastName("Smith")
.WithLastName("Smith")
.WithLastName("Smith");
真正的问题是为什么ReSharper将整个表达式放在一个新的行上。有什么建议吗?
推荐答案
您需要将"包装链接的方法调用"设置为"始终截断",以便在同一行上获得var john = new Person().WithFirstName("John")
。
这篇关于如何阻止ReSharper在赋值变量和链接方法调用之间插入不必要的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何阻止ReSharper在赋值变量和链接方法调用之间插入不必要的换行符
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01