自动命名空间导入 [英] automatic namespace importing

查看:56
本文介绍了自动命名空间导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你创建和aspx页面时,这是默认生成的:


使用System;

使用System.Collections;

使用System.Collections.Specialized;

使用System.Configuration;

使用System.Text;

使用System.Text.RegularExpressions;

使用System.Web;

使用System.Web.Caching;

使用System.Web.SessionState;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System .Web.UI.HtmlControls;


有没有办法通过web.config中的某些配置自动导入比aspx页面中的

默认值更多的命名空间?

我讨厌保留所有<%@ Import Namespace =" xxx" %GT;在所有页面中...


我知道在2.0中有一个配置标签,但我在1.1中找不到任何内容......

When you create and aspx page, this is generated by default:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

Is there any way to automatically import more namespaces than the
default in aspx pages through some configuration in web.config?
I hate to keep all that <%@ Import Namespace="xxx" %> in all the pages...

I know in 2.0 there is a configuration tag, but I didn''t find any in 1.1...

推荐答案

Natan写道:
当你创建和aspx页面时,这是默认生成的:

使用System;
使用System.Collections;
使用System.Collections.Specialized;
使用System.Configuration;
使用System.Text;
使用System.Text.RegularExpressions;
使用System.Web;
使用System.Web.Caching;
使用System.Web.SessionState;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;


真的吗?我得到的列表是不同的。

有没有办法通过web.config中的某些配置自动导入比aspx页面中的
默认更多的命名空间?
我不想保留所有<%@ Import Namespace =" xxx" %GT;在所有
页面中......
我知道在2.0中有一个配置标签,但我在
1.1中找不到任何内容......
When you create and aspx page, this is generated by default:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

Really? The list I get is different.
Is there any way to automatically import more namespaces than the
default in aspx pages through some configuration in web.config?
I hate to keep all that <%@ Import Namespace="xxx" %> in all the
pages...
I know in 2.0 there is a configuration tag, but I didn''t find any in
1.1...




我不这么认为:web.config控制应用程序*如何工作*,

和使用指令只是对编译器的一个提示,它需要

来查找这些名称空间,以及查找你使用的某个类名



我发现了一个看起来好像用于初始代码隐藏文件的模板。

尝试将其更改为use您想要的名称空间!

在我的系统上,它位于:

C:\Program Files \ Microsoft Visual Studio .NET 2003 \ VC#\\\\\\\\\\\\ \\ 1033 \NewWebFormCode.cs


Hans Kesting




I don''t think so: web.config controls how the application *works*,
and the "using" directive is just a hint to the compiler that it needs
to look into these namespaces as well when looking for some classname
that you used.

I found a template that looks as if it is used for the initial code-behind file.
Try changing that to "use" the namespaces you want!
On my system it was at:
C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\DesignerTemplates\1033\NewWebFormCode.cs

Hans Kesting



>有没有办法通过web.config中的某些配置自动导入比aspx页面中的默认
> Is there any way to automatically import more namespaces than the default
更多的命名空间?
不,不是在web.config中,但你可以创建自己的基类(从System.Web.UI.Page继承

),在这个类中导入你的命名空间并使所有

您的页面继承自此类而不是System.Web.UI.Page。

我讨厌保留所有<%@ Import Namespace =" xxx" %GT;在所有页面中......
in aspx pages through some configuration in web.config? No, not in web.config, but you can create your own base class (inheriting
from System.Web.UI.Page), import your namespaces in this class and make all
your pages inherit from this class instead of System.Web.UI.Page.
I hate to keep all that <%@ Import Namespace="xxx" %> in all the pages...



如果你有一个包含所有导入的代码隐藏文件,你不需要添加

导入指令到ASPX页面,这些已经完全由代码导入了

课后。


Anders Nor?s
http://dotnetjunkies.com/weblog/anoras/


Hans Kesting写道:
Hans Kesting wrote:
真的吗?我得到的清单是不同的。


这是默认情况下在.NET 1.1中生成的(我使用SP1,但我不会这样说,b $ b认为它会改变任何东西)

我不这么认为:web.config控制应用程序*如何工作*,
和使用指令只是对编译器的一个提示,它在查找您使用的某个类名时需要查看这些命名空间。


不是真的。实际上在.NET 1 beta中有这个标签......但是对于一些

他们删除的原因。他们正在重新使用.NET 2.0,因为它是有意义的。


Web.config不仅控制你的应用程序的工作方式,还控制你的
页面是如何编译的,包括链接其他库,调试和

其他选项。

我找到了一个看起来好像用于初始代码隐藏文件的模板。
尝试将其更改为使用您想要的命名空间!
在我的系统上它位于:
C:\Program Files \ Microsoft Visual Studio .NET 2003 \ VC#\DesignerTemplates\1033 \NewWebFormCode.cs
Really? The list I get is different.
That is what is generated by default in .NET 1.1 (I use SP1, but i don`t
think it changes anything)
I don''t think so: web.config controls how the application *works*,
and the "using" directive is just a hint to the compiler that it needs
to look into these namespaces as well when looking for some classname
that you used.
Not really. Actually there was this tag in .NET 1 beta... but for some
reason they removed. They are putting back in .NET 2.0 since it makes sense.

Web.config controls not only how your application works, but how your
pages are compiled, including linking other libraries, debugging and
other options.
I found a template that looks as if it is used for the initial code-behind file.
Try changing that to "use" the namespaces you want!
On my system it was at:
C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\DesignerTemplates\1033\NewWebFormCode.cs




对不起,我想你正在谈论背后的代码。我在谈论aspx

页面。不同的事情,不同的地方。



Sorry, I think you are talking about code behind. I`m talking about aspx
pages. Different things, different places.


这篇关于自动命名空间导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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