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. Visual Basic
  4. Namespace importing at project level question

Namespace importing at project level question

Scheduled Pinned Locked Moved Visual Basic
visual-studioperformancequestion
7 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.
  • P Offline
    P Offline
    programmervb netc
    wrote on last edited by
    #1

    I have just rewritten some shared code to put it into namespaces so that it will be easier to find. After adding this stuff to namespaces now my code does not work because I am not importing the namespaces on each form. I know that you can import namespaces for the entire project in properties but I am wondering is this something that will hurt performance. Even if it will not hurt performance is there another way that I can only import the namespaces into the code files that actually use them because I am not wanting them at project level because while that will make my code work.., it defeats the reason for doing this to begin with which is to narrow the amount of things showing up in intellisense. I hope that is clear enough if not please just tell me. Thanks, Brian Humble Programmer

    L G 2 Replies Last reply
    0
    • P programmervb netc

      I have just rewritten some shared code to put it into namespaces so that it will be easier to find. After adding this stuff to namespaces now my code does not work because I am not importing the namespaces on each form. I know that you can import namespaces for the entire project in properties but I am wondering is this something that will hurt performance. Even if it will not hurt performance is there another way that I can only import the namespaces into the code files that actually use them because I am not wanting them at project level because while that will make my code work.., it defeats the reason for doing this to begin with which is to narrow the amount of things showing up in intellisense. I hope that is clear enough if not please just tell me. Thanks, Brian Humble Programmer

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      You need to import namespaces only in the files where you use their types. Example: Having one source file doing networking does not make all files need an Import System.Net And even then, you don't HAVE to import anything, you could also use the fully qualified name. Eample: Dim form as System.Windows.Forms.Form would not require an Import System.Windows.Forms In general I do not recommend you do this though. So, if you have moved types to another namespace, watch the compiler error messages, and fix them, in the files the error messages point you to. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read formatted code with indentation, so please use PRE tags for code snippets.


      I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


      P 1 Reply Last reply
      0
      • L Luc Pattyn

        You need to import namespaces only in the files where you use their types. Example: Having one source file doing networking does not make all files need an Import System.Net And even then, you don't HAVE to import anything, you could also use the fully qualified name. Eample: Dim form as System.Windows.Forms.Form would not require an Import System.Windows.Forms In general I do not recommend you do this though. So, if you have moved types to another namespace, watch the compiler error messages, and fix them, in the files the error messages point you to. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


        P Offline
        P Offline
        programmervb netc
        wrote on last edited by
        #3

        I understand that you should not share every file. Is there an easy way than going through and fixing each imports manually? Humble Programmer

        L 1 Reply Last reply
        0
        • P programmervb netc

          I understand that you should not share every file. Is there an easy way than going through and fixing each imports manually? Humble Programmer

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          No. You fix the files the compiler complains about, there is no overall approach, if there were, it would to a large extent defeat the purpose of the namespace concept. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read formatted code with indentation, so please use PRE tags for code snippets.


          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


          P 1 Reply Last reply
          0
          • L Luc Pattyn

            No. You fix the files the compiler complains about, there is no overall approach, if there were, it would to a large extent defeat the purpose of the namespace concept. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            P Offline
            P Offline
            programmervb netc
            wrote on last edited by
            #5

            I guess I was just hoping there would be something like the window where you can show unused references. oh Well thank you for your time luc. Brian Humble Programmer

            L 1 Reply Last reply
            0
            • P programmervb netc

              I guess I was just hoping there would be something like the window where you can show unused references. oh Well thank you for your time luc. Brian Humble Programmer

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              I believe there is a feature where you can tell Visual to remove unused imports. Which would be a file operation (so you order it for each source file, one by one), and not very valuable. I don't have any details about it, I've never used it. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              1 Reply Last reply
              0
              • P programmervb netc

                I have just rewritten some shared code to put it into namespaces so that it will be easier to find. After adding this stuff to namespaces now my code does not work because I am not importing the namespaces on each form. I know that you can import namespaces for the entire project in properties but I am wondering is this something that will hurt performance. Even if it will not hurt performance is there another way that I can only import the namespaces into the code files that actually use them because I am not wanting them at project level because while that will make my code work.., it defeats the reason for doing this to begin with which is to narrow the amount of things showing up in intellisense. I hope that is clear enough if not please just tell me. Thanks, Brian Humble Programmer

                G Offline
                G Offline
                Gideon Engelberth
                wrote on last edited by
                #7

                As far as the performance question, importing extra namespaces at the project level *may* affect the performance of the compiler *slightly*, but it will not affect the runtime performance of your program/library at all. By the time the IL is run, all calls are performed against fully resolved types/functions regardless of your imports.

                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