Home All Groups Group Topic Archive Search About

How to properly "name" a class library?

Author
10 Nov 2006 10:06 PM
Terry Olsen
I have written a class library that I want to reference from a windows
app.  The filename is UPSTrackTool.dll. The Class name is UPSTrackTool.

When I reference it from my windows app, I put the Imports UPSTrackTool
at the top. But when I call any methods I have to use:

UPSTrackTool.UPSTrackTool.MyMethod()

How do I name this thing so I only have to Imports UPSTrackTool and then
I can just call MyMethod()?




*** Sent via Developersdex http://www.developersdex.com ***

Author
10 Nov 2006 10:17 PM
Chris Dunaway
Terry Olsen wrote:
> I have written a class library that I want to reference from a windows
> app.  The filename is UPSTrackTool.dll. The Class name is UPSTrackTool.
>
> When I reference it from my windows app, I put the Imports UPSTrackTool
> at the top. But when I call any methods I have to use:
>
> UPSTrackTool.UPSTrackTool.MyMethod()
>
> How do I name this thing so I only have to Imports UPSTrackTool and then
> I can just call MyMethod()?
>

You need to make sure the root namespace in the settings for your
project is set appropriately.  You would then refer to your classes by
this root namespace plus the class name.  The root namespace is
typically set to the company name or something like that.  It is also
typical to include other namespaces in the code to group classes
together.

For example, suppose the root namespace for the project was set to
MyCompany

Then in your code, you might have the following:

Namespace "DataClasses"
    Public Class SomeClass
        'Code here
    End Class
End Namespace

The program that uses the class library would use an Imports statement
like this:

Imports MyCompany.DataClasses

And then you could use the class as you propose.

Chris