Problem with namespaces and the IDE

  • Thread starter Thread starter TheSilverHammer
  • Start date Start date
T

TheSilverHammer

Maybe I am not using namespaces correctly, but in general, my project has one
namespace. The problem is that the IDE keeps fighting me with them, as in
it tries to 'help' by adding a bunch of namespace qualifies to things it
should not.

My big issue right now is databinding. My project namespace is
"AutoTerm", and I have a class AutoEmailMessage and the keeps messing up the
databinding source such:
this.autoEmailMessageBindingSource.DataSource =
typeof(AutoTerm.AutoEmailMessage);

it should be:

this.autoEmailMessageBindingSource.DataSource = typeof(AutoEmailMessage);

Because the designer.cs file for the form is in the same namespace. Any
time I change the form, "AutoTerm." is being added back in which messes
things up. I can't figure out how to tell it to stop doing that or how I am
supposed to correct the problem.


Other issues happen when I create sub folders, and design a new form, it
always prepends the form namespace with "AutoTerm.Subfoldername.Whatever" and
I have to edit those as well.

Is there any way to tell it to just assume it is always in the default
namespace?
 
TheSilverHammer said:
Maybe I am not using namespaces correctly, but in general, my project has one
namespace. The problem is that the IDE keeps fighting me with them, as in
it tries to 'help' by adding a bunch of namespace qualifies to things it
should not.

My big issue right now is databinding. My project namespace is
"AutoTerm", and I have a class AutoEmailMessage and the keeps messing up the
databinding source such:
this.autoEmailMessageBindingSource.DataSource =
typeof(AutoTerm.AutoEmailMessage);

it should be:

this.autoEmailMessageBindingSource.DataSource = typeof(AutoEmailMessage);

Because the designer.cs file for the form is in the same namespace. Any
time I change the form, "AutoTerm." is being added back in which messes
things up. I can't figure out how to tell it to stop doing that or how I am
supposed to correct the problem.

I don't see how it's a problem. If the class can be resolved either way
and this is in a designer file, why is it an issue to qualify the class
within the "typeof"?
Other issues happen when I create sub folders, and design a new form, it
always prepends the form namespace with "AutoTerm.Subfoldername.Whatever" and
I have to edit those as well.

Yes, that's deliberate and helpful. Why are you creating subfolders
without wanting to create a new namespace?
Is there any way to tell it to just assume it is always in the default
namespace?

You could edit the templates for classes etc. I don't know much about
that side of things, but I'm sure it's possible.
 
it is a problem because it doesn't compile.

The implied namespace is AutoTerm, so when it puts AutoTerm.AutoEmailMessage
it *really* is looking for AutoTerm.AutoTerm.AutoEmailMessage. The
compiler complains that there is no "AutoTerm.AutoTerm" which is true.

With reguards to everything else, I do not like them because they also do
not compile right. Make a folder, make a new form in that folder and
suddenly the designer IDE pukes until you delete the extra namespace stuff
and then it all works again.
 
TheSilverHammer said:
it is a problem because it doesn't compile.

The implied namespace is AutoTerm, so when it puts AutoTerm.AutoEmailMessage
it *really* is looking for AutoTerm.AutoTerm.AutoEmailMessage.

No, it's not. There's no problem explicitly using a namespace. For
example:

using System;

namespace Foo
{
class Bar
{
}

class Test
{
static void Main()
{
Foo.Bar x = new Foo.Bar();
}
}
}

The compiler complains that there is no "AutoTerm.AutoTerm" which is true.

My guess is that you've got a *class* called AutoTerm as well. Let's
change my example slightly:

using System;

namespace Foo
{
// This is new
class Foo
{
}

class Bar
{
}

class Test
{
static void Main()
{
Foo.Bar x = new Foo.Bar();
}
}
}

Now it fails to compile. Basically, using a class with the same name as
a namespace introduces quite a few opportunities for ambiguity - best
to avoid it. Some later designers use global::Namespace.TypeName I
believe, in order to avoid this problem, admittedly, but it looks like
that's not the case for you.
With reguards to everything else, I do not like them because they also do
not compile right. Make a folder, make a new form in that folder and
suddenly the designer IDE pukes until you delete the extra namespace stuff
and then it all works again.

Again, I suspect that's because you've got something "odd" in your
situation. It works fine normally.
 
Yeah there is a class called AutoTerm, the one the project created when I
chose the name "AutoTerm" for the project.
 
TheSilverHammer said:
Yeah there is a class called AutoTerm, the one the project created when I
chose the name "AutoTerm" for the project.

That sounds unlikely to me. Normally:

o If you create a Windows Forms app, it creates Form1.cs and
Program.cs.

o If you create a class library, it creates Class1.cs

o If you create a console app, it creates Program.cs (IIRC)

See if you can reproduce it...
 
Yeah there is a class called AutoTerm, the one the project created when I
chose the name "AutoTerm" for the project.

That is not the default. It does create a namespace with the same
name, but the class is named Form1 and there is also a Program.cs
 

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

Back
Top