c# – 如何阻止ReSharper在指定的变量和链式方法调用之间插入不
发布时间:2020-12-15 22:28:20 所属栏目:百科 来源:网络整理
导读:我有一个类有一些返回它的方法,这样我可以将调用链接在一起: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public Person WithFirstName(string firstName) { FirstName = firstName; return 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中的右边距(列)设置时,表达式的格式有点时髦. var john = new Person().WithFirstName("John") .WithLastName("Smith") .WithLastName("Smith") .WithLastName("Smith") .WithLastName("Smith"); 显然,这个例子有点人为,因为我永远不会一遍又一遍地调用相同的方法,但是在我的生产代码中,我正在与一个Fluent 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将整个表达放在一个新的界限上.有什么建议? 解决方法
您需要将“Wrap chained method calls”设置为“Chop always”,以便在同一行上获得var john = new Person().WithFirstName(“John”).
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何告诉oracle按照从java传入的特定排序顺序进行排序?
- 为什么Ruby #hash方法是随机的?
- objective-c – 读取AFNetworking响应头
- Cocos2d-x 3.X, IOS版添加广点通广告平台
- c# – 无法在Docker for Windows中运行容器:“系统找不到指
- ruby-on-rails – 没有ActiveRecord的form_for,表单操作不更
- 当XML在特定命名空间中时,如何将XML读入DataTable
- HCS08系列和HCS12系列MCU的文档
- XML 元素 http://blog.csdn.net/chaiyu2002/article/detail
- Swift 中的位操作