Visual Studio 2015在嵌套使用语句中的行为

rex*_*ghk 3 .net c# visual-studio visual-studio-2015

之前提出类似问题来看,众所周知,缩进嵌套using语句的首选方法是(这是Visual Studio 2015的默认设置):

using (var enumerator1 = list1.GetEnumerator())
using (var enumerator2 = list2.GetEnumerator())
{
    // Use enuemrator1 and enumerator2 here
}
Run Code Online (Sandbox Code Playgroud)

但是,当我输入以下内容时,我发现Visual Studio 2015中的行为已更改:

using (var enumerator1 = list1.GetEnumerator())
Run Code Online (Sandbox Code Playgroud)

并点击,光标在第二行缩进:

using (var enumerator1 = list1.GetEnumerator())
    ? // Text caret appears here instead of at the same level of
     // indent of the previous line
Run Code Online (Sandbox Code Playgroud)

如何恢复旧行为以及更改此行为的理由是什么?

Pie*_*ult 5

如果您有ReSharper,则需要取消选中名为的设置 Indent nested "using" statements.

它可以在Code Editing=> C#=> Formatting Style=> 部分找到Other.

ReSharper选项


即使选项未被选中,插入符号仍将显示缩进.但是,一旦您创建换行符,ReSharper将using正确格式化您的块:

ReSharper格式化踢