Nik*_*las 3 asp.net code-generation
当我查看生成的aspx页面代码时,有一件事让我感到震惊.每次打印每个类引用,而不是在代码文件的顶部应用"using"方法.
这样做是否有理由?
如果两种方法没有区别那么为什么不使用"使用"来简化?
System.Data.DataSet theSet = new DataSet();
Run Code Online (Sandbox Code Playgroud)
VS
using System.Data;
DataSet theSet = new DataSet();
Run Code Online (Sandbox Code Playgroud)
因为对于生成的代码,读取的简单性不是优先考虑的.
然而,写作的简单性是一个问题:如果始终使用完全限定名称指定类型,则名称冲突的可能性会降低.想象一下,您有两个提供TextBox控件的库,并将它们添加到Web表单中.
// no problem
System.Web.UI.WebControls.TextBox myDefaultTextBox = new System.Web.UI.WebControls.TextBox();
CustomLibrary.TextBox theOtherTextBox = new CustomLibrary.TextBox();
Run Code Online (Sandbox Code Playgroud)
相比于
using System.Web.UI.WebControls;
using CustomLibrary;
// won't compile, would need special treatment by the code generator
TextBox myDefaultTextBox = new TextBox();
TextBox theOtherTextBox = new TextBox();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
150 次 |
| 最近记录: |