imports\namespace question

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

    #1

    imports\namespace question

    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?


  • CT

    #2
    Re: imports\namespa ce question

    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?

    --
    Carsten Thomsen
    Enterprise Development with VS .NET, UML, AND MSF


    "Jeff Jarrell" <jjarrel_NOSPAM @yahoo.com> wrote in message
    news:exvMfjTeFH A.3880@tk2msftn gp13.phx.gbl...[color=blue]
    >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?
    >
    >[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: imports\namespa ce question

      "Jeff Jarrell" <jjarrel_NOSPAM @yahoo.com> schrieb:[color=blue]
      > 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".[/color]

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

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Jeff Jarrell

        #4
        Re: imports\namespa ce question

        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).

        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:%23kdNKwWe FHA.2700@tk2msf tngp13.phx.gbl. ..[color=blue]
        > "Jeff Jarrell" <jjarrel_NOSPAM @yahoo.com> schrieb:[color=green]
        >> 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".[/color]
        >
        > Importing the namespace 'Common' will /not/ import its subnamespaces!
        > You'll have to import each namespace separately.
        >
        > --
        > M S Herfried K. Wagner
        > M V P <URL:http://dotnet.mvps.org/>
        > V B <URL:http://classicvb.org/petition/>[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: imports\namespa ce question

          "Jeff Jarrell" <jjarrel_NOSPAM @yahoo.com> schrieb:[color=blue]
          > 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).[/color]

          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.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          Working...