コード例 #1
0
    public Prog2()
    {
        var factory = new CommandFactory2();

        factory.Register("A", new Lazy <Action>(() => new A().DoA));
        factory.Register("B", new Lazy <Action>(() => new B().DoB));
        factory.Register("C", new Lazy <Action>(() => factory.DoStuff));
        factory.Execute("A");
    }
コード例 #2
0
    public Prog2()
    {
        var factory = new CommandFactory2();

        factory.Register("A", new Lazy <Action>(() => new A().DoA));

        B        b  = null;
        Func <B> my = () => b ?? (b = new B());

        factory.Register("B", new Lazy <Action>(() =>
        {
            var v = my();
            return(v.DoB);
        }));
        factory.Register("C", new Lazy <Action>(() => factory.DoStuff));
        factory.Execute("A");
    }
コード例 #3
0
    public Prog2()
    {
        var factory = new CommandFactory2();

        factory.Register("A", new Lazy <Command>(
                             () =>
        {
            var a = new A();
            return(new Command(a.DoA, a.UndoA));
        }));
        factory.Register("B", new Lazy <Command>(
                             () =>
        {
            var c = new B();
            return(new Command(c.DoB, c.DoB));
        }));
        factory.Register("C", new Lazy <Command>(
                             () => new Command(DoStuff, UndoStuff)));
        factory.Execute("A");
    }