Namespace Hell
-
I have a c# project that is causing me problems at the moment. I have a file that looks like this ------------ using System ; namespace MyNameSpace.System { public class Test { public Test () { System.Diagnostics.Trace.Writeline ("Hello World!") ; } } } ------------ the problem is that when I compile this it VS complains that the namespace Diagnostics does not exist in MyNameSpace.System Also when I type System. the intelisense gives me a choice of 'Test' only i.e. my clases in the MyNameSpace.System namespace. if I change the line to Diagnostics.Trace.Writeline ("Hello World!") dropping the System it all compiles. Is this normal namespace behaviour? If not (hope not as this sucks) anyone got any idea on how to fix it? Thanks Stephen.
-
I have a c# project that is causing me problems at the moment. I have a file that looks like this ------------ using System ; namespace MyNameSpace.System { public class Test { public Test () { System.Diagnostics.Trace.Writeline ("Hello World!") ; } } } ------------ the problem is that when I compile this it VS complains that the namespace Diagnostics does not exist in MyNameSpace.System Also when I type System. the intelisense gives me a choice of 'Test' only i.e. my clases in the MyNameSpace.System namespace. if I change the line to Diagnostics.Trace.Writeline ("Hello World!") dropping the System it all compiles. Is this normal namespace behaviour? If not (hope not as this sucks) anyone got any idea on how to fix it? Thanks Stephen.
Stephen Woolhead wrote: Is this normal namespace behaviour? Yep. Perhaps Eric can explain it better (I just spent 10 minutes trying to and couldn't get it out right) but IIRC namespaces are evaluated from right to left, so the System matches before it gets to the root System namespace; however Diagnostics doesn't match until it gets to the root System namespace. James "Java is free - and worth every penny." - Christian Graus
-
Stephen Woolhead wrote: Is this normal namespace behaviour? Yep. Perhaps Eric can explain it better (I just spent 10 minutes trying to and couldn't get it out right) but IIRC namespaces are evaluated from right to left, so the System matches before it gets to the root System namespace; however Diagnostics doesn't match until it gets to the root System namespace. James "Java is free - and worth every penny." - Christian Graus
Just seemed strange to me that as I was in the namespace MyNameSpace.System and had a using statement for System when I was used System.Diagnostics, that it should resolve to MyNameSpace.System.Diagnostics instead of trying the following MyNameSpace.System.System.Diagnostics (Current namespace) System.System.Diagnostics (Using System Statement) System.Diagnostics (using the global namespace) Of which the last one would have been resolved. Is there a way to say that this is the start of the namespace do not append to anything, something like ::System in C++ ? Thanks Stephen
-
Just seemed strange to me that as I was in the namespace MyNameSpace.System and had a using statement for System when I was used System.Diagnostics, that it should resolve to MyNameSpace.System.Diagnostics instead of trying the following MyNameSpace.System.System.Diagnostics (Current namespace) System.System.Diagnostics (Using System Statement) System.Diagnostics (using the global namespace) Of which the last one would have been resolved. Is there a way to say that this is the start of the namespace do not append to anything, something like ::System in C++ ? Thanks Stephen
Stephen Woolhead wrote: Just seemed strange to me It does to me too; perhaps this will be addressed in the future (so that it tries all the way up instead of stopping at the first failure -- MyNameSpace.System.Diagnostics) Stephen Woolhead wrote: Is there a way to say that this is the start of the namespace do not append to anything Not that I know of, I think something is needed at any rate. James "Java is free - and worth every penny." - Christian Graus
-
Just seemed strange to me that as I was in the namespace MyNameSpace.System and had a using statement for System when I was used System.Diagnostics, that it should resolve to MyNameSpace.System.Diagnostics instead of trying the following MyNameSpace.System.System.Diagnostics (Current namespace) System.System.Diagnostics (Using System Statement) System.Diagnostics (using the global namespace) Of which the last one would have been resolved. Is there a way to say that this is the start of the namespace do not append to anything, something like ::System in C++ ? Thanks Stephen
Stephen Woolhead wrote: Is there a way to say that this is the start of the namespace do not append to anything, something like ::System in C++ ? No but you can try this code example. It's an almost solution to the problem.
using System; using WinSystem=System; namespace Test.System { public class Test { public static void Main(String[] args) { WinSystem.Console.WriteLine("Hello World"); } } }
Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n