Namespaces in VB.NET

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

I'm working on a VB library application. I want Visual Studio to
automatically
put in the namespace on the class when I add it under a directory. Like C#
does.

So if I have a directory in my project called /tools, and my default
namespace of the project
is myproject, the editor should put in the namespace of "myproject.tools".
That's how Csharp works.

Does anyone know if this is an option in Visual Studio or something?
 
maxmann,
Does anyone know if this is an option in Visual Studio or something?
Unfortunately there is no option to automatically do this.

I normally include the Namespace statement in each source file. Which of
course has issues if you move the file. Note I still set the root namespace
under Project Properties for classes in the project root.

NameSpace Design

Public Class WidgetEditor
End Class

End NameSpace

Hope this helps
Jay
 
right. we have the root namespace set, I was just wanting to get around
having to manually add the namespace in for every class file we create.
Doesn't make sense that VB can't do this when C# does it by default.
 
* "axmann said:
right. we have the root namespace set, I was just wanting to get around
having to manually add the namespace in for every class file we create.
Doesn't make sense that VB can't do this when C# does it by default.

You can write an add-in that inserts the code...

;-)))
 
Axmann,
I don't think its a matter that VB can't, its a matter that VB does not!

I have to wonder how many VB.NET projects actually include folders. So
adding the feature to VB.NET for the two of us makes sense how? :-)

Also I tend to start all my classes in the root of the project, then when I
have enough classes I tend to move them to folders later, so having the
namespace added when I create the class is not going to help me... Rather
then move them into a folder, I may actually move them into their own class
library assembly. Granted others work differently then you or I.

Also as Herfried stated, you could write a macro or add-in to take care of
it.

I'm not sure if it will be changed in VB.NET 2004 or not.

You could always submit a Wish to Microsoft to have the behavior changed,
not sure if it will make VB.NET 2004 as I understand the beta for VB.NET
2004 will be at PDC.

http://register.microsoft.com/mswish/suggestion.asp?&SD=GN&LN=EN-US&gssnb=1

Hope this helps
Jay
 
Well, for organization sake I would think A LOT of projects, VB or not,
should have code grouped in folders.
I guess if you broke every little piece of functionality into their own dll
you might not, but I would rather not
have to work with 30 different projects myself when the functionality is
closely related, but still groupable.

Also, it's just good coding practice to namespace your classes out
corresponding directly to your folder
structure. I've heard that from the experts. My company recently brought
in Rockford Lhotka (the author)
for .NET training and that's what he recommended.

Anyway, I added it to the wishlist. Thanks for the link. I may try an
add-in, but I have tons of more important
things to do at the moment. :)

thanks, Mark
 
axmann,
Well, for organization sake I would think A LOT of projects, VB or not,
should have code grouped in folders.
I believe you miss read me! You and I believe this way, I question if other,
less informed VB.NET programmers know this, especially when coming from VB6
which did not support it!

And yes my estimate of 2 may have been low ;-)
I guess if you broke every little piece of functionality into their own dll
you might not, but I would rather not
I never said 'little piece', An example of what I meant: Is one project with
500 classes in it better or worse than 10 projects with 50 classes each? I
find 10 projects with 50 classes each to be 'more manageable'. Would I have
5 projects with 100 classes each, I'm not sure. I think it would depend on
how well those classes grouped or didn't. However it is doubtful that I
would have 50 projects with 10 classes each, then again it there were 50
obvious groupings...
Also, it's just good coding practice to namespace your classes out
corresponding directly to your folder structure
I never said it wasn't, I almost always do. However like any rule, there are
exceptions that make sense. :-)

If anything I normally do it the other way: I will put classes into a
namespace in the root folder, before I would put files in a folder without a
namespace (if that made sense).

Hope this helps
Jay
 
Hi Jay, Axman,

2? That's 3, thank you very much!! [much fake indignation, lol]

Actually, though I use folders a lot (and then I might migrate out to
projects), I prefer explicit namespaces. I also have temporary folders where
things are put just so that I don't have to play scroll and click so much. I
wouldn't want any automatic namespaces for those.

I haven't had the pain of too much renaming upheaval but if it comes to
it, ...Hey - opportunity for a utiity. Doesn't even have to be an add-in -
just a console app that reads a bunch of solution files, project files and
directory structures.

Regards,
Fergus
 
well, I submitted it to the good old MS wish list. We'll see what happens.

I think it would be best if it were an option , that way if you wanted
Visual Studio to do it , it would, and vice versa.

I agree that not every programmer out there would want the feature, but the
option would be helpful.
 
Hi Axmanm,

I'm all in favour of options, so I hope you get your wish.

If ever I do that utility, I will send it to you at xceligent.com ;-)

Regards,
Fergus
 
Back
Top