|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Confusion over namespacesI have a solution with two projects. One of the projects is called MyProj with a root namespace called MyProj.Obj. The single source (vb) file for MyProj has a class called Obj. There is no enclosing namespace, i.e. the class declaration is at the top of the file. The second project is called MyProjUser and has a reference to MyProj. The single source file for MyProjUser has the following imports statement: Imports MyProj.Obj Then I have a statement further down in MyProjUser like this: Dim o as Obj But the compiler doesn't like it. It says that Obj isn't defined. The compiler is happier when I either have this Imports statement: Imports MyProj.Obj.Obj or with this statement in code: Dim o as Obj.Obj. What's happening here? I thought that once I imported the namespace (in this case MyObj.Obj), then all classes in that namespace (including Obj) should be usable without further qualification. Or is the fact that part of the namespace and the class name are the same (i.e. Obj) causing confusion? TIA for any answers. -- Akin aknak at aksoto dot idps dot co dot uk Think of namespaces and objects as files and directories on your harddrive
your namespace is akin to c:\myproj\obj and inside that you have created a file called obj. in order to access your file, you must specify its full path c:\myproj\obj\obj a way that I use namespaces is to break the assemblies into thought areas, i.e mycompany.myproject. data libraries would go into mycompany.myproject.datalib graphic libraries into mycompany.myproject..graphics UI components into mycompany.myproject and mycompany.myproject.customcontrols. Additionally, when I create an assembly with a sepreate namespace it is generally because the project itself can potentially be reused by other assemblies without modification, otherwise, the code would all live with the executing assembly. for example Our encryption library is mycompany.encryption Our xml, adodbo, and csv wrappers live in mycompany.data Our generic containers such as sorted bindinglist(of T) live in mycompany.generics Our login UI components, security model all live in mycompany.security and mycompany.security.ui Finally, we then reference these libraries when designing an application Accounting package base namespace is mycompany.accpac imports mycompany.accpac imports gencol = mycompany.generics UI components import imports mycompany.accpac.business imports mycompany.accpac.UI Business Objects import imports mycompany.accpac.data imports db = mycompany.data imports enc = mycompany.encryption imports sec = mycompany.security add system references (i.e. xml, data, text, collections) as appropriate Show quoteHide quote "Epetruk" <nob***@blackhole.com> wrote in message news:4cuonuF183t4qU1@individual.net... > Hello, > > I have a solution with two projects. > > > > One of the projects is called MyProj with a root namespace called > MyProj.Obj. > > The single source (vb) file for MyProj has a class called Obj. There is no > enclosing namespace, i.e. the class declaration is at the top of the file. > > The second project is called MyProjUser and has a reference to MyProj. > > The single source file for MyProjUser has the following imports statement: > > Imports MyProj.Obj > > > > Then I have a statement further down in MyProjUser like this: > > Dim o as Obj > > But the compiler doesn't like it. It says that Obj isn't defined. > > > > The compiler is happier when I either have this Imports statement: > > Imports MyProj.Obj.Obj > > > > or with this statement in code: > > Dim o as Obj.Obj. > > > > What's happening here? I thought that once I imported the namespace (in > this > case MyObj.Obj), then all classes in that namespace (including Obj) should > be usable without further qualification. > > Or is the fact that part of the namespace and the class name are the same > (i.e. Obj) causing confusion? > > TIA for any answers. > > -- > Akin > > aknak at aksoto dot idps dot co dot uk > >
Byte to Chr - not correctly translated!!
GetDefaultPrinter Frustrated trying to use "pure" VS.NET to access database properties VB.NET Windows Service Question (Timing) How Do I Put An End Of Line Character In A TextBox User Software Settings and System Software Settings in Windows Regsitry Dynamically Create Timers are Run-Time VB Express - How to access query value on my form? VS2003 and VS2005 Side by Side CSV file reading every other record... |
|||||||||||||||||||||||