declaring a namespace

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

    #1

    declaring a namespace

    If I've got something like:

    using System;

    namespace myCompany.myLib rary
    {
    ...class definitions here...
    }

    in a file, such that there's nothing outside of the namespace block except
    the using statement(s), is there an alternative way to say the same thing
    that doesn't require the extra level of nesting for the namespace?

    That is, I'm looking for a declaration that effectively says "everything in
    this file is in the namespace myCompany.myLib rary," and eliminates the need
    for the actual namespace declaration block.

    Michael Roper


  • Hai Ly Hoang - MT00KSTN

    #2
    Re: declaring a namespace

    Hi,
    Why don't you use the using statement ?
    It's quite simple and convinient !

    "Michael Roper" <michaelr@encra ft.com> wrote in message[color=blue]
    > If I've got something like:[color=green]
    > > using System;
    > > namespace myCompany.myLib rary[/color]
    > {
    > ...class definitions here...
    > }
    >
    > in a file, such that there's nothing outside of the namespace block except
    > the using statement(s), is there an alternative way to say the same thing
    > that doesn't require the extra level of nesting for the namespace?[/color]



    Comment

    • Michael Roper

      #3
      Re: declaring a namespace

      Hai Ly Hoang writes:[color=blue]
      > Why don't you use the using statement ?
      > It's quite simple and convinient !
      >
      > "Michael Roper" <michaelr@encra ft.com> wrote in message[color=green]
      > > If I've got something like:[color=darkred]
      > > > using System;
      > > > namespace myCompany.myLib rary[/color]
      > > {
      > > ...class definitions here...
      > > }
      > >
      > > in a file, such that there's nothing outside of the namespace block[/color][/color]
      except[color=blue][color=green]
      > > the using statement(s), is there an alternative way to say the same[/color][/color]
      thing[color=blue][color=green]
      > > that doesn't require the extra level of nesting for the namespace?[/color][/color]

      How would I use it to solve this problem?

      Michael Roper


      Comment

      • Michael Mayer

        #4
        Re: declaring a namespace

        'Using' won't solve the problem. AFAIK, C# is always plagued by an extra
        indentation of indent due to the namespace { }construct that you wouldn't
        have in Java. I haven't heard a good explanation of why... I can't imagine
        wanting to include code for two different namespaces in one file. (And in
        Java, with one class per file, it would be impossible even if they used the
        namespace construct like C#). So here, I have to say that I prefer the Java
        way.

        --
        Mike Mayer

        mike@mag37.com


        "Michael Roper" <michaelr@encra ft.com> wrote in message
        news:bjvael$mj8 5p$1@ID-160215.news.uni-berlin.de...[color=blue]
        > Hai Ly Hoang writes:[color=green]
        > > Why don't you use the using statement ?
        > > It's quite simple and convinient !
        > >
        > > "Michael Roper" <michaelr@encra ft.com> wrote in message[color=darkred]
        > > > If I've got something like:
        > > > > using System;
        > > > > namespace myCompany.myLib rary
        > > > {
        > > > ...class definitions here...
        > > > }
        > > >
        > > > in a file, such that there's nothing outside of the namespace block[/color][/color]
        > except[color=green][color=darkred]
        > > > the using statement(s), is there an alternative way to say the same[/color][/color]
        > thing[color=green][color=darkred]
        > > > that doesn't require the extra level of nesting for the namespace?[/color][/color]
        >
        > How would I use it to solve this problem?
        >
        > Michael Roper
        >
        >[/color]


        Comment

        • Michael Mayer

          #5
          Re: declaring a namespace

          Another thought, get a wide-screen monitor so that you don't have to worry
          about the extra indentation ;-)

          --
          Mike Mayer

          mike@mag37.com


          "Michael Roper" <michaelr@encra ft.com> wrote in message
          news:bjvael$mj8 5p$1@ID-160215.news.uni-berlin.de...[color=blue]
          > Hai Ly Hoang writes:[color=green]
          > > Why don't you use the using statement ?
          > > It's quite simple and convinient !
          > >
          > > "Michael Roper" <michaelr@encra ft.com> wrote in message[color=darkred]
          > > > If I've got something like:
          > > > > using System;
          > > > > namespace myCompany.myLib rary
          > > > {
          > > > ...class definitions here...
          > > > }
          > > >
          > > > in a file, such that there's nothing outside of the namespace block[/color][/color]
          > except[color=green][color=darkred]
          > > > the using statement(s), is there an alternative way to say the same[/color][/color]
          > thing[color=green][color=darkred]
          > > > that doesn't require the extra level of nesting for the namespace?[/color][/color]
          >
          > How would I use it to solve this problem?
          >
          > Michael Roper
          >
          >[/color]


          Comment

          • Daniel O'Connell

            #6
            Re: declaring a namespace


            "Michael Mayer" <mike@mag37.com > wrote in message
            news:u6t8vqjeDH A.3788@tk2msftn gp13.phx.gbl...[color=blue]
            > 'Using' won't solve the problem. AFAIK, C# is always plagued by an extra
            > indentation of indent due to the namespace { }construct that you wouldn't
            > have in Java. I haven't heard a good explanation of why... I can't[/color]
            imagine[color=blue]
            > wanting to include code for two different namespaces in one file. (And in
            > Java, with one class per file, it would be impossible even if they used[/color]
            the[color=blue]
            > namespace construct like C#). So here, I have to say that I prefer the[/color]
            Java[color=blue]
            > way.
            >[/color]

            Although its rare, namespaces can be nested for a purpose. I wouldn't
            normally put things in multiple namespaces in a single file, but I would
            also not normally split a type between files, yet we are getting partial
            type support.
            I would suspect nested namespace support is of use most often in files that
            declare lots of little declarations. Even though I know I shouldn't, alot of
            the time I define multiple delegates or highly simple exception\Event Args
            classes (in essence, do nothing but provide a new specific type), or other
            really simple classes in a single file or in files adjoining the type that
            will use them instead of adding dozens of 6 line files.
            Also, someone might find it more readable to do
            namespace Level1
            {
            namespace Level2
            {

            }
            }
            even if it would drive me nuts(and does in C++, as best I can tell thats the
            only way to nest namespaces, yet another reason I never liked that lanuage)[color=blue]
            > --
            > Mike Mayer
            > http://www.mag37.com/csharp/
            > mike@mag37.com
            >
            >
            > "Michael Roper" <michaelr@encra ft.com> wrote in message
            > news:bjvael$mj8 5p$1@ID-160215.news.uni-berlin.de...[color=green]
            > > Hai Ly Hoang writes:[color=darkred]
            > > > Why don't you use the using statement ?
            > > > It's quite simple and convinient !
            > > >
            > > > "Michael Roper" <michaelr@encra ft.com> wrote in message
            > > > > If I've got something like:
            > > > > > using System;
            > > > > > namespace myCompany.myLib rary
            > > > > {
            > > > > ...class definitions here...
            > > > > }
            > > > >
            > > > > in a file, such that there's nothing outside of the namespace block[/color]
            > > except[color=darkred]
            > > > > the using statement(s), is there an alternative way to say the same[/color]
            > > thing[color=darkred]
            > > > > that doesn't require the extra level of nesting for the namespace?[/color]
            > >
            > > How would I use it to solve this problem?
            > >
            > > Michael Roper
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Michael Mayer

              #7
              Re: declaring a namespace

              "Daniel O'Connell" <onyxkirx@comca st.net> wrote in message
              news:7QL8b.5091 5$mp.23951@rwcr nsc51.ops.asp.a tt.net...[color=blue]
              >
              > Although its rare, namespaces can be nested for a purpose.[/color]
              I agree with the idea of nesting namespaces. e.g.
              System.Data
              System.Data.Ole Db;

              <snip>[color=blue]
              > I would suspect nested namespace support is of use most often in files[/color]
              that[color=blue]
              > declare lots of little declarations. Even though I know I shouldn't, alot[/color]
              of[color=blue]
              > the time I define multiple delegates or highly simple exception\Event Args
              > classes (in essence, do nothing but provide a new specific type), or other
              > really simple classes in a single file or in files adjoining the type that
              > will use them instead of adding dozens of 6 line files.[/color]

              Absolutely, I do the same thing when there's a very tight connection between
              a small thing (like a delegate) and a bigger class that uses it. However,
              if there's a farily loose coupling between the two (enough to merit that
              they go in different namespaces) then I would sure think that separate files
              would be desirable as well.
              [color=blue]
              > Also, someone might find it more readable to do
              > namespace Level1
              > {
              > namespace Level2
              > {
              >
              > }
              > }
              > even if it would drive me nuts(and does in C++, as best I can tell thats[/color]
              the[color=blue]
              > only way to nest namespaces, yet another reason I never liked that[/color]
              lanuage)

              That would drive me nuts as well.


              --
              Mike Mayer

              mike@mag37.com



              Comment

              Working...