如何使不需要的名称空间默认情况下不会出现在新类的顶部

发布于 2024-08-29 00:26:22 字数 188 浏览 0 评论 0原文

在 Visual Studio 2008 C# 中,如果我创建一个新类,则默认情况下会出现以下命名空间,并且我每次都会手动删除它们。是否有一个设置/文件夹模板,我可以在其中删除这些不需要的名称空间,使其不再出现在项目中创建的每个新类上?

使用 System.Collections.Generic; 使用 System.Linq; 使用系统文本;

In Visual Studio 2008 C#, if I create a new class the following namespaces appear by default and I remove them manually every time. Is there a setting/folder template where I can go and remove these unwanted namespaces from appearing on each and every new class that's created on the project?

using System.Collections.Generic;
using System.Linq;
using System.Text;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我们的影子 2024-09-05 00:26:23

这是来自新类的 ItemTemplate。转到

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033

(如果您安装的是非英语版本,则可能是不同的 LCID),您可以更改 Class.zip 中的 Class.cs 以适应您的需求。然后清除

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplateCache

中的缓存您应该会发现您的类现在以您刚刚更改模板的方式创建。请记住,这不是受支持的行为,您实际上是在“破解”VS(尽管以一种非常简单的方式)。

支持的方法是创建您自己的模板并使用它,如下所示:http://www.switchonthecode.com/tutorials/visual-studio-how-创建项目模板

This is coming from the ItemTemplate for a new class. Go to

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033

(possibly a different LCID if you have a non English installation), and you can alter Class.cs inside Class.zip to fit your needs. Then clear out the cache at

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplateCache

You should find your classes now get created in whatever way you just altered the template. Keep in mind this is not supported behavior, you are effectively "hacking" VS (although in a very trivial way)

The supported way to do this is to create your own template and use that, as shown here: http://www.switchonthecode.com/tutorials/visual-studio-how-to-create-item-templates

ら栖息 2024-09-05 00:26:23

添加到马特的答案中,您会发现根据项目类型,您将看到不同的命名空间导入集。我怀疑这些是单独的模板,但有些模板可能很难或不可能修改,具体取决于它们的实现方式。例如,在 WPF 或 Silverlight 应用程序中,您会获得一大堆 System.Windows.* 导入的命名空间,这些命名空间在普通的类库项目中是看不到的。

另一种选择是将键序列映射到RemoveAndSortUsings 命令。如果您转到“工具”->“选项->键盘您将看到键盘快捷键界面。只需输入“sort”,您就应该找到该命令,然后将一些按键序列映射到它,每当您想要整理东西时,您就可以轻松地调用该命令。

To add to Matt's answer, you will find that depending on the project type you will see different sets of namespace imports. I suspect these are separate templates but some of the templates may be difficult or impossible to modify depending on how they were implemented. For example in a WPF or Silverlight application you get a whole bunch of System.Windows.* imported namespaces that you don't see in a normal class library project.

Another option would be to map a key sequence to the RemoveAndSortUsings command. If you go to Tools -> Options -> Keyboard you will see the keyboard shortcut interface. Just type "sort" and you should find the command, then map some key sequence to it and you can easily invoke that command whenever you want to tidy things up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文