Namespace importing at project level question
-
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
-
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
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 anImport 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).
-
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 anImport 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).
I understand that you should not share every file. Is there an easy way than going through and fixing each imports manually? Humble Programmer
-
I understand that you should not share every file. Is there an easy way than going through and fixing each imports manually? Humble Programmer
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).
-
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).
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
-
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
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).
-
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
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.