请问C#支持项目范围的默认命名空间的进口VB.NET一样? [英] Does C# Support Project-Wide Default Namespace Imports Like VB.NET?

查看:133
本文介绍了请问C#支持项目范围的默认命名空间的进口VB.NET一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近转换VB开发者为C#,但有一件事至今,我一直没能找到。在VB中,当我安装一个新的项目,我可以指定在项目中使用的命名空间,并将其添加到默认进口的所有类(所以一切都自动拥有他们,如果我补充说:进口System.Data.OracleClient的每个类)。用C#我发现,我一直在为每一个新类键入这些。有没有一种方法来设置默认值项目,所以它至少会自动附加那些每类文件给我吗?

I am a recently converted VB developer to C#, but there is one thing thus far that I haven't been able to find. In VB when I setup a new project I can specify the namespaces used in the project and add them to the default imports for all classes (so everything automatically has them as if I added "Imports System.Data.OracleClient" to each class). With C# I've found that I'm always typing these in for each new class. Is there a way to setup defaults for projects so it at least appends those to every class file for me automatically?

推荐答案

没有也没办法。 C#不支持项目级别进口或项目一级命名空间的概念。

No there is no way. C# does not support the concept of project level imports or project level namespaces.

你能做的唯一的事情就是改变你正在使用(或Class.cs code.cs)有你想要的命名空间的项目模板。这些文件位于以下目录

The only thing you can do is alter the item template you are using (Class.cs or Code.cs) to have the namespaces you would like. These files are located under the following directory

的%ProgramFiles%\\微软的Visual Studio 9.0 \\ Common7 \\ IDE \\ itemtemplatescache \\ CSHARP \\ code \\ 1033

%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\itemtemplatescache\CSharp\Code\1033

在这里,你会看到一个Class.zip和code.zip每个目录下他们cs文件。这是所使用的模板文件当你在Visual Studio中的添加新项操作。你可以改变这些以满足您的需求,有你想要的默认命名空间。

Under here you should see a Class.zip and Code.zip directory each with a .cs file under them. This is the template file used when you do an "Add New Item" operation in Visual Studio. You can change these to meet your needs and have the default namespaces you'd like.

一个稍微简单的解决方案,虽然是增加了对您想具体项目每用户code文件。只需创建一个code文件你想成为模板为您的应用程序,然后将其放置在以下目录中。

A slightly easier solution though is adding a per-user code file for the particular project you'd like. Simply create a code file you want to be the template for your application and then place it in the following directory.

C:\\用户\\您的用户名\\文档\\ Visual Studio 2008的\\模板\\的ItemTemplate \\的Visual C#

C:\Users\YourUserName\Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#

这个文件现在将显示当你做一个添加新项操作。

This file will now show up whenever you do a "Add New Item" operation.

这篇关于请问C#支持项目范围的默认命名空间的进口VB.NET一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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