How do I keep shared methods on the same namespace level in different files

  • Thread starter Thread starter Mark Denardo
  • Start date Start date
M

Mark Denardo

Ok here's my problem:

I have a bunch of Classes at the same namespace level say "abc.xyz". And
all Classes reside in different files.

abc.xyz.Class1 (in Class1.vb)
abc.xyz.Class2 (in Class2.vb)
abc.xyz.Class3 (in Class3.vb)
....
abc.xyz.Class99 (in Class99.vb)

Some of these Classes I want to convert to Shared Methods, because I don't
need to instantiate them, but I still want them at the "abc.xyz" namespace
level.

The only way I can see to make these shared is inside the Class with another
Method (because New doesn't allow the shared keyword). So I'm forced to add
another method say "Go", but this adds another level to the calling tag,
"abc.xyz.Class1.Go", which I am hoping to eliminate.

I even toyed with the idea of putting these in a module, but then the module
name adds another level to the namespace.

Is there anyway to do what I'm needing?

Mark
 
Mark Denardo said:
I have a bunch of Classes at the same namespace level say "abc.xyz". And
all Classes reside in different files.

abc.xyz.Class1 (in Class1.vb)
abc.xyz.Class2 (in Class2.vb)
abc.xyz.Class3 (in Class3.vb)
...
abc.xyz.Class99 (in Class99.vb)

Some of these Classes I want to convert to Shared Methods, because I don't
need to instantiate them, but I still want them at the "abc.xyz" namespace
level.

The only way I can see to make these shared is inside the Class with
another Method (because New doesn't allow the shared keyword). So I'm
forced to add another method say "Go", but this adds another level to the
calling tag, "abc.xyz.Class1.Go", which I am hoping to eliminate.

I even toyed with the idea of putting these in a module, but then the
module name adds another level to the namespace.

Namespaces cannot contain methods directly. Methods either belong to a type
or a module, which is a special class behind the scenes too. If you put the
methods into a module, they can be called without further qualification
because modules are imported automatically:

\\\
Namespace Foo
Module Goo
Sub Bla()
...
End Sub
End Module
End Namespace
///

'Bla' can be called using 'Foo.Goo.Bla', 'Foo.Bla', 'Bla', or 'Goo.Bla'.
 
Back
Top