排序和删除 C# 代码中未使用的用途 [英] Sort and Remove unused usings in C# code

查看:24
本文介绍了排序和删除 C# 代码中未使用的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法像在 Visual Studio 2015 和 2017 中一样在 C# 中排序删除未使用的usings?

Is there a way to Sort and Remove Unused usings in C# just like in Visual Studio 2015 and 2017?

如果没有,这是否可以添加到未来的 Visual Studio Code 版本中?

If not, could this be an addition to a future Visual Studio Code version?

推荐答案

vscode 中内置了一个命令来帮助删除未使用的用法.

There is a command that is built into vscode to help out removing unused usings.

默认键绑定定义为:

{ "key": "ctrl+.", "command": "editor.action.quickFix",
                      "when": "editorHasCodeActionsProvider && 
                               editorTextFocus && 
                               !editorReadonly" },

至于对 using 进行排序:我没有找到为 using 语句明确构建的任何内容,但是有一个命令可以对行进行排序.将类似于以下内容的内容添加到您的键绑定文件中:

As for sorting the usings: I did not find anything built explicitly for using statements, but there is a command to sort lines. Add something similar to the following into your keybindings file:

{ "key": "ctrl+q", "command": "editor.action.sortLinesAscending",
                      "when": "editorFocus && !editorReadonly" },

然后,选择 using 语句并按 ctrl+q 对其进行排序.

Then, select the using statements and press ctrl+q to sort them.

这篇关于排序和删除 C# 代码中未使用的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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