views:

63

answers:

1

In a visual studio 2008 solution, I have two versions of the same class in two different namespaces.

In VB, if I do this:

imports MyNamespace
' ...
dim x as DuplicatedClass = new DuplicatedClass()

it uses MyNamespace.DuplicatedClass instead of the globally-namespaced DuplicatedClass. Meanwhile, in C#, doing this:

using MyNamespace;
// ...
DuplicatedClass x = new DuplicatedClass();

uses the globally-namespaced DuplicatedClass. To use the other version, I have to use MyNamespace.DuplicatedClass.

I realize this is a problematic setup, but I can't change it. Is there a way to prevent C# from seeing the globally namespaced class, or to specifically un-load it, or...? Given how many classes are in the global namespace, being forced to choose the namespace every time could get pretty time-costly.

+3  A: 

Perhaps the best you could do is create a using alias:

//create alias
using defDuplicatedClass = MyNamespace.DuplicatedClass;

defDuplicatedClass x = new defDuplicatedClass();

The alias is file scoped. So you'd have to repeat it at the top of each file as needed, but perhaps that is better than repeating a namespace with every occurance of DuplicatedClass.

Brent Arias
Link to an example article: http://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx
Ryan Bennett
That works excellently, thanks! Didn't know about the alias feature. Apparently it can't override the global namespaced class, but that's wholly acceptable.
Groxx