Example #1
0
    static void Main(string[] args)
    {
        MyClass      A   = new MyClass();
        MyInterface1 AI1 = A;
        MyInterface2 AI2 = A;

        Console.WriteLine(A.Method2(42) + " " + A.Method((char)42));
        Console.WriteLine(AI1.Method((char)42) + " " + AI2.Method2(42));
        Console.ReadKey();
    }
Example #2
0
    static void Main(string[] args)
    {
        MyClass A = new MyClass(42, "Hi!");

        A.Method();
        MyInterface1 B = A;

        B.Method();
        Console.ReadKey();
    }
    static void Main(string[] args)
    {
        MyClass      A  = new MyClass();
        MyInterface1 A1 = A;
        MyInterface2 A2 = A;

        Console.WriteLine(A.TXT);
        Console.WriteLine(A1.TXT);
        Console.WriteLine(A2.TXT);
        Console.ReadKey();
    }
Example #4
0
        static void Main(string[] args)
        {
            //准备委托
            TestProxy          test         = new TestProxy();
            Func <int, string> nameFunc     = test.Abcdefg;
            Func <string, int> ageFunc      = item => item.Length;
            Func <string>      toStringFunc = () => "重写已重载的方法!";
            Action             action       = () => { Console.WriteLine("复用此函数!"); };

            //创建联合接口代理
            var proxier = new Proxier <MyAbstract, MyInterface1, MyInterface2>();

            proxier["GetName"] = nameFunc;
            //proxier["GetAge"] = ageFunc;
            proxier.SetMethod("GetAge", "return age.Length;");
            proxier["Show"]     = action;
            proxier["ToString"] = toStringFunc;
            proxier["Show2"]    = action;


            //获取接口实例委托
            var func = proxier.GetDefaultCreator <MyInterface1>();
            //创建接口实例
            MyInterface1 interface1 = func();

            Console.WriteLine(interface1.GetName(100));


            //获取接口实例委托
            var func2 = proxier.GetDefaultCreator <MyInterface2>();
            //创建接口实例
            MyInterface2 interface2 = func2();

            Console.WriteLine(interface2.GetAge("abcdefg"));


            //获取接口实例委托
            var func3 = proxier.GetDefaultCreator <MyAbstract>();
            //创建接口实例
            MyAbstract interface3 = func3();

            interface3.Show();
            interface3.Show2();
            Console.WriteLine(interface3.ToString());

            Console.ReadKey();
        }