开发者

Visual Studio and root namespaces

开发者 https://www.devze.com 2023-01-11 13:46 出处:网络
I am using VS2010, is there a way, to disable full root namespaces, when VS is autogenerati开发者_如何学运维ng code? From this:

I am using VS2010, is there a way, to disable full root namespaces, when VS is autogenerati开发者_如何学运维ng code? From this:

{
global::System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new global::System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
}

to this:

using System.ComponentModel;
{
CollectionChangeEventHandler schemaChangedHandler = new CollectionChangeEventHandler(this.SchemaChanged);
}


I don't know if there is, however doing so is a VERY BAD idea.

VERY BAD.

VERY BAD.

VERY VERY BAD.

First, it suggests you are editing generated code. If you are, see above. The solution is to use partial classes, if you aren't already. Almost all generated code is done using partial classes. If not, open a Connect.

Second, it is there for a reason--it prevents generated code class names and namespaces from clashing with yours. When generated code isn't globally scoped and it does clash, you only have two choices: Either rename your code or edit the generated code every time you regenerate it. This is the definition of a Pain in the Ass.

I know it doesn't look pretty, but the fact is you should NEVER be looking at it.

NEVER.

etc.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号