Confusion over namespaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Epetruk

    #1

    Confusion over namespaces

    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


  • AMDRIT

    #2
    Re: Confusion over namespaces

    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\o bj

    a way that I use namespaces is to break the assemblies into thought areas,
    i.e

    mycompany.mypro ject.

    data libraries would go into mycompany.mypro ject.datalib
    graphic libraries into mycompany.mypro ject..graphics
    UI components into mycompany.mypro ject and
    mycompany.mypro ject.customcont rols.

    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.encry ption
    Our xml, adodbo, and csv wrappers live in mycompany.data
    Our generic containers such as sorted bindinglist(of T) live in
    mycompany.gener ics
    Our login UI components, security model all live in mycompany.secur ity and
    mycompany.secur ity.ui

    Finally, we then reference these libraries when designing an application

    Accounting package base namespace is mycompany.accpa c

    imports mycompany.accpa c
    imports gencol = mycompany.gener ics

    UI components import
    imports mycompany.accpa c.business
    imports mycompany.accpa c.UI

    Business Objects import
    imports mycompany.accpa c.data
    imports db = mycompany.data
    imports enc = mycompany.encry ption
    imports sec = mycompany.secur ity

    add system references (i.e. xml, data, text, collections) as appropriate

    "Epetruk" <nobody@blackho le.com> wrote in message
    news:4cuonuF183 t4qU1@individua l.net...[color=blue]
    > 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
    >
    >[/color]


    Comment

    Working...