tags:

views:

66

answers:

2

Is there a way to tell .Net to search for a namespace from the root of the namespace tree?

Say I have these two, completely independent, namespaces:

Apple.Orange.Banana
Orange.Grape.Peach

Assume they came from different programmers and the "Orange" in each one is completely coincidental.

If I'm inside "Apple.Orange.Banana" and I trying to import (or reference) "Orange.Grape.Peach," .Net things I'm trying to search from the "Orange" in "Apple.Orange.Banana".

How do I tell it, "Look from the root, not where I'm at now." This would be great:

~Orange.Grape.Peach

But, alas, that doesn't exist.

I know that some of you will say I should just plan namespaces better, but what happens when I'm using code from two places that come with namespaces predefined that I cannot change, and they conflict as I've noted above?

+3  A: 

You could alias the root Orange like this:

using RootOrange = Orange;

Then you can do:

RootOrange.Grape.Peach
Mark
+6  A: 

Have you tried using the global:: resolution scope? For example, if you have the following:

private global::Orange.Grape.Peach.classname x;

Also, you get different resolution depending on whether namespaces are imported outside of a namespace declaration or inside, so

using System.Linq;
namespace MyLinq 
{
   // ...
}

can provide different resolution rules than:

namespace MyLinq 
{
   using System.Linq;

   // ...
}
Scott Dorman
Excellent. Thank you.
Deane
@Deane: You're welcome. Glad you were able to resolve the problem.
Scott Dorman