Intellisense, public modules, and public methods

  • Thread starter Christopher W. Douglas
  • Start date
C

Christopher W. Douglas

I'm working in VB.Net, using Visual Studio 2003.

I have a project, let's call it Foo, that contains common methods, forms,
and objects I use in other projects. It compiles as Foo.dll, which I then
reference from the project that needs it.

Let's say I have a method, Bar, that I want to access from another project.
If I add a public module Methods to Foo, and add a public method Bar to
Methods, I can call it from my other project a couple of different ways, and
intellisense acts differently.

This works, but with no intellisense:
Foo.Bar

This works:
Foo.Methods (shows in intellisense)
and then:
Foo.Methods.Bar (shows in intellisense)

If, INSTEAD, I create a public class IO in Foo, and a public shared method
Bar in IO, I can call it like so (without instantiating a copy of the IO
class):

Foo.Bar (doesn't work)
Foo.IO.Bar (works, and shows in intellisense)

However, Microsoft, with their awesome powers, has a Namespace
Microsoft.VisualBasic, with a public module Strings, and a public method
UCase.

This works, even if I don't have Microsoft.VisualBasic imported:

UCase("string") (shows in intellisense)
Microsoft.VisualBasic.UCase("string") (shows in intellisense)
Microsoft.VisualBasic.Strings.UCase("string") (shows in intellisense)

I guess what I want is to have a Foo.dll, with a public module or class,
with the public method Bar, and be able to do this:

Foo.Bar

WITH intellisense. Microsoft can do it, why can't I? I appreciate any
assistance.
 
C

Chris Dunaway

Christopher said:
Let's say I have a method, Bar, that I want to access from another project.
If I add a public module Methods to Foo, and add a public method Bar to
Methods, I can call it from my other project a couple of different ways, and
intellisense acts differently.

This works, but with no intellisense:
Foo.Bar

I wouldn't expect that to work because Bar is not a member of Foo but
of Methods.
This works:
Foo.Methods (shows in intellisense)
and then:
Foo.Methods.Bar (shows in intellisense)

That is the expected behavior
If, INSTEAD, I create a public class IO in Foo, and a public shared method
Bar in IO, I can call it like so (without instantiating a copy of the IO
class):

Foo.Bar (doesn't work)

Again, since Bar is not a member of Foo but of IO, I would not expect
this to work.
Foo.IO.Bar (works, and shows in intellisense)

This is the behavior I would expect.
However, Microsoft, with their awesome powers, has a Namespace
Microsoft.VisualBasic, with a public module Strings, and a public method
UCase.

This works, even if I don't have Microsoft.VisualBasic imported:

UCase("string") (shows in intellisense)

Did you check your project properties to see if the VisualBasic
namespace was imported by default?
Microsoft.VisualBasic.UCase("string") (shows in intellisense)

Hmmm... I'm not sure how this works. It makes no sense. I checked
the IL and it seems to map to the function in the Strings namespace.
The only UCase I can find is Microsoft.VisualBasic.Strings.UCase. I'm
not sure how MS is pulling of this bit of wizardry. Maybe someone who
knows more about the internals of .Net can shed some light?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top