【问题标题】:Code formatting in Visual Studio 2017Visual Studio 2017 中的代码格式
【发布时间】:2018-04-13 08:14:28
【问题描述】:

我注意到,当我在 Visual Studio 中复制时,粘贴的代码大部分都向左移动了:

    class TestClass
    {
        public IEnumerable<MyObject> TestMethod()
        {
            // Code copying from here...
            yield return new MyObject(
              "",
              "",
              ""  
            );
            // ...to here

            // Pasted code looks like this
            yield return new MyObject(
"",
"",
""  
);

            yield return new MyObject(
"",
"",
""  
);

            yield return new MyObject(
"",
"",
""  
);
            // End of pasted code
        }
    }

当我点击“CTRL+K、CTRL+D”或从“编辑 -> 高级”菜单中选择“格式化文档”时,代码不会移动。

我知道文档格式有效,但在某些“特殊”条件(例如某些缩进)存在时似乎不起作用。

有没有办法告诉 Visual Studio 根据其默认规则重新格式化整个文档并完全忽略“特殊”条件?

【问题讨论】:

    标签: visual-studio


    【解决方案1】:

    我看到与开箱即用的 Visual Studio 相同的行为,但是,当使用 ReSharper 时,粘贴此代码的格式符合预期。如果 ReSharper 太重/太贵,你可以尝试像 Code Formatter 这样的轻量级扩展。

    【讨论】:

      猜你喜欢
      • 2017-07-29
      • 1970-01-01
      • 2019-08-17
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多