Visual Studio中多行参数列表的自动缩进 [英] Automatic indentation of arguments list on multiple lines in Visual Studio

查看:344
本文介绍了Visual Studio中多行参数列表的自动缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当方法的参数列表增长到无法舒适地放在一行上的程度时,我喜欢对代码进行格式化,以使每个参数都在单独的一行上(遵循StyleCop建议),如下所示:

When the list of arguments to a method grows to the point where they do not fit comfortably on one line, I like to format code such that each argument is on a separate line (following StyleCop suggestion), like this:

public void MyMethod(
   int someArgument,
   double someOtherArgument,
   int someMoreArguments)

我遇到的问题是这种格式是易碎的,使用Ctrl时不会自动重新格式化+ K + D。例如,如果我碰巧在其中一个参数前面插入了一些空格,则该空格不会被删除,最终我需要进行一些繁琐的手动重新格式化。如果我复制一个方法(例如,提供重载的签名),则副本中的参数缩进将变得非常混乱。

我在LINQ语句上也遇到类似的问题,我也想在多行上设置格式,例如:

The problem I run into is that this formatting is "fragile" and does not get automatically re-formatted when using Ctrl+K+D. For instance, if I happen to insert some spaces in front of one of the arguments, it doesn't get removed, and I end up doing some tedious manual reformatting. If I copy a method (say, to provide an overloaded signature), the argument indentation in the copy gets totally messy.
I have a similar issue with LINQ statements, which I also like to format on multiple lines, like:

myEnumerable.
   .Where(this and that)
   .Where(this and that)
   .FirstOrDefault();

我意识到这是完整的强迫症格式,是一个很小的问题,但是有办法使Visual Studio 2010在未对齐时自动按照该模式重新缩进多行参数?

I realize this is complete Obsessive-Compulsive formatting, and a very minor issue, but is there a way to make Visual Studio 2010 automatically re-indent multi-line arguments following that pattern when it gets misaligned?

推荐答案

看看JetBrains的Resharper。它具有可用于格式化代码的各种规则,比内置VS更好。

You may want to look at Resharper from JetBrains. It has all sorts of rules that can be applied to formatting code that is much better that the built-in VS stuff.

http://www.jetbrains.com/resharper/

该特定选项位于在:

更新

Resharper>选项> C#>格式样式>行中断和包裹>包裹长行

Resharper > Options > C# >Formatting Style > Line Breaks and Wrapping > Wrap long lines

我不知道它是否完全符合您的要求,但它确实包裹了长行

I don't know if it does exactly what you want, but it does wrap long lines

这篇关于Visual Studio中多行参数列表的自动缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆