关于在公共区域添加命名空间
我们总是在 win 应用程序中的每个表单的顶部添加命名空间
,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business;
using System.Data.SqlClient;
using Business;
并且大多数命名空间在大多数表单中都很常见,但在 ASP.NET 中,有一项规定只能在 web.config 文件中添加一次命名空间。所以我们不必在所有网络表单中添加它,这样可以节省时间。所以我只需要知道我们的胜利应用程序是否有任何相同的规定。如何实现它。谢谢
we always add namespace at the top of the every form in win apps
like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business;
using System.Data.SqlClient;
using Business;
and most of namespace are common in most form but in asp.net there is a provision to add namespace only once in web.config file. so we dont have to add it in all web form and it save time. so i just need to know is there any same sort of provision for our win apps. how to achieve it. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您的 WinForm 应用程序没有任何类型的规定,而 ASP.NET 应用程序则使用 web.config 中的
部分。另请注意,这仅适用于.aspx
页面,不适用于 C# 背后的代码。在 C# 中,您必须添加正确的using
语句,以便将要使用的类型引入作用域。No, there isn't any sort of provision for your WinForm applications as there is for ASP.NET applications using the
<namespaces>
section in web.config. Also note that this applies only to.aspx
pages and not code behind C#. In C# you have to add properusing
statements in order to bring the types you want to use into scope.一种方法是将标准 using 指令添加到通用模板中。
您没有提及您正在使用哪个版本的 Visual Studio,但在 VS2010 中您可以在以下位置找到模板:
更改 zip 中的 Class.cs 文件以默认包含您想要的用法。
唯一的缺点是它是针对每台机器的 - 因此您需要在每台开发人员计算机上执行此操作 - 尽管我敢说您可以使用 Active Directory 来推出它(这是 serverfault.com 的问题)。
我相信也可以设置团队模板 - 但这不是我尝试过的。更多信息请访问:
http://msdn.microsoft.com/en-us/杂志/cc188697.aspx
One method is to add the standard using directives into the common templates.
You don't mention which version of visual studio you are using but in VS2010 you can find the templates in:
Change the Class.cs file in the zip to include the usings you want by default.
The only downside to this is that it is per machine - so you will need to do it on each developers computer - although I daresay you could roll it out with Active Directory (that's a question for serverfault.com).
I believe it also possible to set up team templates - but it's not something I have tried. More information available here:
http://msdn.microsoft.com/en-us/magazine/cc188697.aspx