Tech Off Post

Single Post Permalink

View Thread: Interface + Extension Methods -- any improvement on abstract classes?
  • User profile image
    Anthony​Johnston

    AnthonyJohnston said:
    You can scope your extensions in our out eg

    namespace Sandbox.ExtensionMethods
    {
        class Class1
        {
        }
    }

    namespace Sandbox.ExtensionMethods.ns2
    {
        static class Extension
        {
            public static void Extend2(this Class1 item)
            {
            }
        }
    }

    namespace Sandbox.ExtensionMethods.ns1
    {
        static class Extension
        {
            public static void Extend1(this Class1 item)
            {
            }
        }
    }

    now putting a using for the namespace to the corresponding extension it will be scoped in

    eg

    using Sandbox.ExtensionMethods.ns2;

                Class1 item = new Class1();
                item.Extend2();

    Or


    using Sandbox.ExtensionMethods.ns1;

                Class1 item = new Class1();
                item.Extend1();

    not sure where you'd use it tho, Smiley Ant
    Sorry,I completely mis-read your question - will be more careful in future,
    Ant