A class and namespace has same name, but still must fully qualify the class???

J

Jack

Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.

I can access my class in my code just fine with:

XXX.XXX.MySub() '(Note: shared sub!)

But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:

XXX.MySub()

right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!

I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?

Thanks,
Jack.
 
C

Cor Ligthert [MVP]

Jack,

If you use as your class by instance the name streamwriter, than it can
become ambigious and you have to qualify both full.

Cor
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jack said:
Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.

I can access my class in my code just fine with:

XXX.XXX.MySub() '(Note: shared sub!)

But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:

XXX.MySub()

right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!

I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?

By not having a class with the same name as it's namespace.
 
J

Jack

Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.

I can access my class in my code just fine with:

XXX.XXX.MySub() '(Note: shared sub!)

But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:

XXX.MySub()

right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!

I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?

Thanks,
Jack.

Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Jack,
As Göran suggests avoid naming a class & namespace the same.

If there is no way around this, for example the class is coming from one
assembly & the namespace from another. You could use an import alias to
locally (to the file) "rename" the namespace or class

Imports ba = XXX.XXX

ba.MySub()
 
J

Jack

Jack,
As Göran suggests avoid naming a class & namespace the same.

If there is no way around this, for example the class is coming from one
assembly & the namespace from another. You could use an import alias to
locally (to the file) "rename" the namespace or class

Imports ba = XXX.XXX

ba.MySub()

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -http://www.tsbradley.net




Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.
I can access my class in my code just fine with:
XXX.XXX.MySub() '(Note: shared sub!)
But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:

right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!
I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?
Thanks,
Jack.- Hide quoted text -

- Show quoted text -

I also noticed this problem occurrs with the framework itself with the
StringBuilder class. One must fully qualify it with:
Dim testString As New System.Text.StringBuilder(30)
because the IDE seems to think 'StringBuilder' is some namespace and
not a class in the following statement:
Dim testString As New StringBuilder(30)

I consider this an oversight with the Visual Studio product. I'm not
sure what to blame though: is it the IDE, intellisense, or the dynamic
IDE compiler?

Jack.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jack said:
Jack,
As Göran suggests avoid naming a class & namespace the same.

If there is no way around this, for example the class is coming from one
assembly & the namespace from another. You could use an import alias to
locally (to the file) "rename" the namespace or class

Imports ba = XXX.XXX

ba.MySub()

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -http://www.tsbradley.net




Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.
I can access my class in my code just fine with:
XXX.XXX.MySub() '(Note: shared sub!)
But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:
XXX.MySub()
right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!
I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?
Thanks,
Jack.- Hide quoted text -
- Show quoted text -

I also noticed this problem occurrs with the framework itself with the
StringBuilder class. One must fully qualify it with:
Dim testString As New System.Text.StringBuilder(30)
because the IDE seems to think 'StringBuilder' is some namespace and
not a class in the following statement:
Dim testString As New StringBuilder(30)

I consider this an oversight with the Visual Studio product. I'm not
sure what to blame though: is it the IDE, intellisense, or the dynamic
IDE compiler?

Jack.

I have never experienced that, but then I use C#, not VB.

There is no StringBuilder namespace, so I have no idea why the IDE would
think there is. Unless you have created a StringBuilder namespace in
your project?
 
J

Jack Jackson

Jack,
As Göran suggests avoid naming a class & namespace the same.

If there is no way around this, for example the class is coming from one
assembly & the namespace from another. You could use an import alias to
locally (to the file) "rename" the namespace or class

Imports ba = XXX.XXX

ba.MySub()

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -http://www.tsbradley.net




Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.
I can access my class in my code just fine with:
XXX.XXX.MySub() '(Note: shared sub!)
But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:

right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!
I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?
Thanks,
Jack.- Hide quoted text -

- Show quoted text -

I also noticed this problem occurrs with the framework itself with the
StringBuilder class. One must fully qualify it with:
Dim testString As New System.Text.StringBuilder(30)
because the IDE seems to think 'StringBuilder' is some namespace and
not a class in the following statement:
Dim testString As New StringBuilder(30)

I consider this an oversight with the Visual Studio product. I'm not
sure what to blame though: is it the IDE, intellisense, or the dynamic
IDE compiler?

I never qualify StringBuilder and haved never had any problems with it
(VB 2005).
 
J

Jay B. Harlow [MVP - Outlook]

Jack
I also noticed this problem occurrs with the framework itself with the
StringBuilder class. One must fully qualify it with:
Dim testString As New System.Text.StringBuilder(30)
because the IDE seems to think 'StringBuilder' is some namespace and
not a class in the following statement:
Dim testString As New StringBuilder(30)
You forgot an "Imports System.Text" as the top of the current file.
I consider this an oversight with the Visual Studio product. I'm not
sure what to blame though: is it the IDE, intellisense, or the dynamic
IDE compiler?
I would blame the user forgetting to import the namespace. ;-)


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Jack,
As Göran suggests avoid naming a class & namespace the same.

If there is no way around this, for example the class is coming from one
assembly & the namespace from another. You could use an import alias to
locally (to the file) "rename" the namespace or class

Imports ba = XXX.XXX

ba.MySub()

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -http://www.tsbradley.net




Hi,
I have a single class XXX residing in a namspace with the same name:
XXX.
I can access my class in my code just fine with:
XXX.XXX.MySub() '(Note: shared sub!)
But I don't want to clutter the code with the namespace every time I
access my class.
o, as per usual, I add in the 'Imports XXX' into my code. So now I can
just access my class like:

right? Wrong. The IDE STILL forces me to fully qualify the class with
the namespace !!??!!
I *think* its getting confused because the class name is the same name
as the namespace.
How can I avoid this?
Thanks,
Jack.- Hide quoted text -

- Show quoted text -

I also noticed this problem occurrs with the framework itself with the
StringBuilder class. One must fully qualify it with:
Dim testString As New System.Text.StringBuilder(30)
because the IDE seems to think 'StringBuilder' is some namespace and
not a class in the following statement:
Dim testString As New StringBuilder(30)

I consider this an oversight with the Visual Studio product. I'm not
sure what to blame though: is it the IDE, intellisense, or the dynamic
IDE compiler?

Jack.
 

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