imports\namespace question

J

Jeff Jarrell

I am not really there yet with namespaces.

I have a "common.dll" that is referenced from another project.

now in the consuming project, source file to i'd like to have a
"imports common".

But what happens is that I have to specify the class as well, as in...
"imports common.util".

what i am trying to get to is really a single import statement at the top of
the consuming source file, that will make available all of the types that
are in the "common.dll".

Is there anyway name spaces can help here? Is this even doable?
 
C

CT

Jeff,

If you dll assembly only has a single namespace, which is by default the
name of the project, you Imports statement should be the same as the name of
your project, i.e. Imports common.

The name of the class, util in this case, doesn't go in the Imports
statement, only the fully qualified namespace. Basically, the Imports
statement is a shortcut, so that you don't have to use the fully qualified
namespace in the code file. If you don't have the Imports statement, you'd
have to use common.util whenever you need to access the util class. So, what
this boilds down to is that with the Imports common statement, you have
indeed access to all public types in the common namespace. Have you added a
reference to the common.dll assembly in the consuming project?
 
H

Herfried K. Wagner [MVP]

Jeff Jarrell said:
I have a "common.dll" that is referenced from another project.

now in the consuming project, source file to i'd like to have a
"imports common".

But what happens is that I have to specify the class as well, as in...
"imports common.util".

Importing the namespace 'Common' will /not/ import its subnamespaces!
You'll have to import each namespace separately.
 
J

Jeff Jarrell

so just to confirm a thought, a class becomes an "implied" sub namespace?

imports common.util (where util is a public class)
imports common.winapi (where winapi is a public class with winapi
declarations (dll imports attributes).
 
H

Herfried K. Wagner [MVP]

Jeff Jarrell said:
so just to confirm a thought, a class becomes an "implied" sub namespace?

imports common.util (where util is a public class)
imports common.winapi (where winapi is a public class with winapi
declarations (dll imports attributes).

No, classes are no namespaces! If you want to call shared members of a class
without qualifying them with the class name, you'll have to import the
class. However, this is only useful in rare cases.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top