Gerhard
Gerhard

Reputation: 1362

exclude a class from a used namespace

The first statement of all my C# files is "using System;". Now with framework version 4 this namespace contains a class called "Action". This is also the name for a class im my own code in a regularly used namespace. Now there is of course a conflict. Ofcourse I can resolve this conflict by using explicit "MyNamespace.Action" where ever I was using "Action" before. This are several hundreds if not thousands of lines. Or I could not use the System namespace, which of course leads to many other problems. I would like to write something like "using System but not System.Action", but I cannot find a statement to do this. Any ideas?

Upvotes: 8

Views: 5725

Answers (2)

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

The using directive has two uses:

To permit the use of types in a namespace so you do not have to qualify the use of a type in that namespace:

using System.Text;

To create an alias for a namespace or a type (you could go for this one).

using Project = PC.MyCompany.Project;

The using keyword can also be used to create using statements, which define when an object will be disposed. See using statement for more information.

using directive (C# Reference)

Upvotes: 0

erikkallen
erikkallen

Reputation: 34401

No, you can't.

But you can add using Action = MyNamespace.Action. This will be highly confusing for new developers, though, as Action is a fundamental part of .net since 3.5 so I strongly suggest you rename your class.

Upvotes: 12

Related Questions