views:

20

answers:

1

Hello, I am using VS2010, is there a way, to disable full root namespaces, when VS is autogenerating 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);
}
+3  A: 

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.

Will
WAIT. i don't get it. is that bad?
Scott M.
@Scott updated. Generated code that isn't globally scoped is the devil's code. It sneaks into your project and wreaks havoc. It gives your daughters UTIs and beats your sons at H.O.R.S.E.
Will
sorry i should have surrounded that with <sarcasm> tags
Scott M.