Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Namespace Hell

Namespace Hell

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studiodebuggingtutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephen woolhead
    wrote on last edited by
    #1

    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.

    J 1 Reply Last reply
    0
    • S stephen woolhead

      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.

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • J James T Johnson

        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

        S Offline
        S Offline
        stephen woolhead
        wrote on last edited by
        #3

        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

        J J 2 Replies Last reply
        0
        • S stephen woolhead

          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

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S stephen woolhead

            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

            J Offline
            J Offline
            jparsons
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups