C #: Why is the first namespace redundant?

This is a little creepy.

I think there must be some setting somewhere that explains why this is happening.

Our solution has about 50 different projects. For the most part, libraries start with the namespace OurCompany.

We have OurComany.This.That and OurCompany.Foo.Bar ... etc.

There is a namespace / class collision between an external library and a namespace

OurCompany.Foo.Bar

And a class that has that qualification.

OurCompany.Some.Location.Foo

The error is as follows:

Error   75  The type or namespace name 'MethodName' does not exist in the
namespace 'OurCompany.Foo' (are you missing an assembly reference?)

Even Resharper gives me the message "Qualifier is redundant" when I fully qualify anything in the namespace "OurCompany" .. i.e.

OurCompany.Some.Location.Foo.MethodName();
//OurCompany is redundant

, . , , , .

, ...

Some.Location.Foo.MethodName(); //Leaving out OurCompany

... Resharper .

+4
2

, , , - , #.

, . , - - OurCompany; , OurCompany.This.That. , OurCompany.This.That, OurCompany.This OurCompany, , . , OurCompany.Foo ( OurCompany , Foo, [-] ), " re ( Some OurCompany, ).

, , - . , :

namespace OurCompany
{
    namespace Some
    {
        namespace Location
        {
            public class Foo
            {
                public static void MethodName() { }
            }
        }
    }

    namespace Foo
    {
        namespace Bar { }
    }
}

, ( , , ) :

using OurCompany.Some.Location;

namespace OurCompany
{
    namespace This
    {
        namespace That
        {
            class BeepBoop
            {
                private void DoSomething()
                {
                    Foo.MethodName();  // No good; Foo is a namespace here.
                }
            }
        }
    }
}

... :

namespace OurCompany
{
    namespace This
    {
        namespace That
        {
            using OurCompany.Some.Location;
            class BeepBoop
            {
                private void DoSomething()
                {
                    Foo.MethodName();  // Puh-wha?  This works?
                }
            }
        }
    }
}

, , . , , , " , ".

+2

, dll . , . , Resharper VS , .

, :

  • 50 . ( sln ).
  • " ".
  • , . , . 1.

, , , (# 3000) , .

+1

All Articles