How to make an object belong to a namespace (VS 2008)?

I have a Company.Controls namespace that contains several controls. I also have a class called "Common" that contains the enumerations / structures / static methods that I use in all controls.

Is there a way to make these "common" peices belong to the Company.Controls namespace so I don't need to type "Common.Structure"? Essentially, it is "Common" and the namespace and class.

It just seems messy and confusing when reading code.

(all other controls are in the Blah.Controls.Common namespace)

namespace Blah.Controls
{
    public enum ControlTouchState
    {
        Down = 0x00,
        Up = 0x01,
    }

    public Common()
    {
      //Stuff here
    }

}

Thank.

+3
2

, ; # .

, , - :

namespace Blah.Controls
{
    public class CommonControl { }

    public static class Common
    {
        public static void Foo(this CommonControl cc) { }
    }

    public class Control1 : CommonControl
    {
        public void Bar()
        {
            this.Foo();
        }
    }
}

, , - partial, :

namespace Blop.Controls
{
    public static class Common
    {
        public static void Foo() { }
    }

    public partial class Control1
    {
        public void Bar()
        {
            Foo();
        }
    }

    public partial class Control1
    {
        public void Foo()
        {
            Common.Foo();
        }
    }
} 

, ; , .

+1

- , Common ? ?

namespace Common
{
    public struct Structure 
    {
        // ... 
    }

    public enum Enumeration
    {
        // ...
    }

    public class Common
    {
        // ...
    }
}

Common :

namespace Blah.Controls
{
    using Common;

    class Control
    {
        Struct myStruct;
        Enumeration myEnum;
        Common myCommon; // references the class, not the namespace
    }
}
0

Source: https://habr.com/ru/post/1732709/


All Articles