我正在使用 VS2010,当 VS 自动生成代码时,有没有办法禁用完整的根命名空间?由此:
{
global::System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new global::System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
}
对此:
using System.ComponentModel;
{
CollectionChangeEventHandler schemaChangedHandler = new CollectionChangeEventHandler(this.SchemaChanged);
}
最佳答案
我不知道是否有,但是这样做是一个非常糟糕的主意。
很坏。
很坏。
非常非常糟糕。
首先,它建议您正在编辑生成的代码。如果是,请参见上文。解决方案是使用部分类,如果你还没有的话。几乎所有生成的代码都是使用 partial classes 完成的.如果没有,打开一个 Connect .
其次,它的存在是有原因的——它可以防止生成的代码类名称和 namespace 与您的名称发生冲突。当生成的代码不是全局范围的并且确实发生冲突时,您只有两种选择:重命名代码或在每次重新生成时编辑生成的代码。这是屁股痛的定义。
我知道它看起来不漂亮,但事实是你永远不应该看它。
绝不。
等等。
Here's a connect I opened because the EF4 T4 templates didn't globally scope their variables, so the generated code clashed with my Debug
namespace.
关于visual-studio-2010 - Visual Studio 和根命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3471033/