微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用语句进行排序时的预期排序行为是什么

如何解决使用语句进行排序时的预期排序行为是什么

因此,我们最近遇到了一个问题,即根据正在使用的编辑器(VS Code 与 Visual Studio 正确)对包含行进行排序会导致差异,从而导致文件来回翻转。

老实说,我不确定这是一个 Visual Studio 代码问题,还是一个 Visual Studio 问题,所以尝试在这里询问是否有人可以指出我的“预期”行为。

问题基本上是这样的。

从这组未排序的 using 语句开始。

using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.Threading.Tasks;
using System.CommandLine;
using System;
using System.Diagnostics;
using System.IO;
using Google.Protobuf.Reflection;
using System.Text;

在 VS Code 中使用命令面板中的 Sort Lines Ascending 命令产生 ->

using Google.Protobuf.Reflection;
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;

在 Visual Studio 中使用排序行(编辑->高级->排序行)时(Visual Assist 给出相同的结果)。我也在 Notepad++ 中尝试过,并且在使用词法排序选项时也得到了相同的结果。

using Google.Protobuf.Reflection;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System;

然而,真正让问题困惑的是,如果我将输入块更改为使用 qouted 字符串(我意识到格式错误,但类似于 C++ 包含),行为 翻转

从这里开始

using "System.CommandLine.Invocation";
using "System.CommandLine.IO";
using "System.Threading.Tasks";
using "System.CommandLine";
using "System";
using "System.Diagnostics";
using "System.IO";
using "Google.Protobuf.Reflection";
using "System.Text";

在 VS Code 中排序行命令产生

using "Google.Protobuf.Reflection";
using "System.CommandLine.Invocation";
using "System.CommandLine.IO";
using "System.CommandLine";
using "System.Diagnostics";
using "System.IO";
using "System.Text";
using "System.Threading.Tasks";
using "System";

使用 Visual Studio、Visual Assist 和 Notepad++ 时,我们得到以下内容

using "Google.Protobuf.Reflection";
using "System";
using "System.CommandLine";
using "System.CommandLine.IO";
using "System.CommandLine.Invocation";
using "System.Diagnostics";
using "System.IO";
using "System.Text";
using "System.Threading.Tasks";

如果有人可以解释预期的行为应该是什么,以及为什么带引号的字符串与未带引号的字符串排序不同。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。