1. 程式人生 > >ActionFilter遞迴鏈剖析

ActionFilter遞迴鏈剖析

class Program
{

    delegate int abc(int i, string j);
    public class ActionExec
    { }
    public class ActionExCon
    { }

    public class ActionExCon1
    { }

    static void Main(string[] args)
    {
        #region
        //int[] data = { 1, 2, 3, 4 };
        //var res = data.Aggregate("String", (str, val) => { Console.Write(str+"     ");Console.WriteLine(val.ToString() + "\r\n");  return str + val.ToString(); });
        //Console.WriteLine(res);
        #endregion
        abc start= delegate (int i, string j)
        {
            Func<Func<ActionExec>> begin = () =>
             {
                 return () => new ActionExec();
             };

            ActionExCon Con = new ActionExCon();
            int[] data = { 1, 2, 3, 4 };
            Func<Func<ActionExec>>  b = data.Aggregate(begin, (next, filter) => () => InvokeWith(filter, Con, next));
            b();
            (b())();

            return 0;
        };
        start(0, "1");
        Console.ReadLine();
    }
    public  static Func<ActionExec> InvokeWith(int i,ActionExCon Con,Func<Func<ActionExec>> func)
    {
        Func<ActionExec> C = func();

        return () =>
        {
            ActionExec A1;
            A1 = C();
            return A1;
        };
    }



    public static void Test1()
    {
        int[] nums = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

        int sum1 = nums.Sum();
        int sum2 = nums.Aggregate((i, j) => { Console.Write(i);Console.Write(j+"\r\n");  return i + j; });
    }
}