当前位置: 首页>>代码示例>>C#>>正文


C# Chain.Execute方法代码示例

本文整理汇总了C#中Chain.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Chain.Execute方法的具体用法?C# Chain.Execute怎么用?C# Chain.Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chain的用法示例。


在下文中一共展示了Chain.Execute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            Chain<int, double> chain = new Chain<int, double>()
            .Link<int>(x =>
            {
                // Generate random array of ints
                int[] nums = new int[x];
                Random rand = new Random();
                for (int i = 0; i < x; i++)
                {
                    nums[i] = rand.Next(100);
                }
                return nums;
            })
            .Link<int[]>(x =>
            {
                // order the numbers (pointless but why not)
                return x.OrderBy(y => y).ToArray();
            })
            .Link<int[]>(x =>
            {
                // compute the average and return it
                double average = 0.0;
                for (int i = 0; i < x.Length; i++)
                {
                    average += x[i];
                }
                return average / x.Length;
            });

            // Execute our chain, passing in 100 as the initial argument
            double avg = chain.Execute(100);
            Console.WriteLine("Average int chain finished, result: " + avg);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:34,代码来源:Average.cs

示例2: TestExecutionError

        public void TestExecutionError()
        {
            Chain<int, int> chain = new Chain<int, int>()
            .Link<int>(x => x)
            .Link<int>(x =>
            {
                if (x == 0)
                    throw new NullReferenceException(x.ToString());
                else
                    return x;
            })
            .Link<int>(x => 100);

            ChainExecutionException chEE = null;
            try
            {
                int outcome = chain.Execute(0);
            }
            catch (ChainExecutionException chee)
            {
                chEE = chee;
            }

            Assert.IsNotNull(chEE);
            Assert.AreEqual<string>("0", chEE.InnerException.Message);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:26,代码来源:LinearTests.cs

示例3: TestMethod1

        public void TestMethod1()
        {
            var chain = new Chain<ICommand>()
            .Add<Command1>()
            .Add<Command2>(() => new Command2("Test"))
            .Build();

              chain.Execute();

              chain = new Chain<ICommand>()
            .Add<Command2>()
            .Add<Command1>()
            .Build();

              chain.Execute();
        }
开发者ID:decarufe,项目名称:fluentpatterns,代码行数:16,代码来源:UnitTest1.cs

示例4: Diag

        private static void Diag(Chain<string, double> chain, int loops, int iters, string input)
        {
            for (int loop = 0; loop < loops; loop++)
            {
                Stopwatch swChain = Stopwatch.StartNew();
                for (int i = 0; i < iters; i++)
                {
                    chain.Execute(input);
                }
                swChain.Stop();

                Stopwatch swLin = Stopwatch.StartNew();
                for (int i = 0; i < iters; i++)
                {
                    LinearImp(input);
                }
                swLin.Stop();

                Console.WriteLine("Chain (" + loop + "): " + swChain.ElapsedMilliseconds);
                Console.WriteLine("Linear (" + loop + "): " + swLin.ElapsedMilliseconds);
                Console.WriteLine();
            }
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:23,代码来源:BenchmarkSimple.cs

示例5: TestMultiTypeChain

        public void TestMultiTypeChain()
        {
            Chain<int, string> chain = new Chain<int, string>()
            .Link<int>(x => Enumerable.Range(1, x).ToArray())
            .Link<int[]>(x => x.Sum())
            .Link<int>(x => x.ToString());

            string output = chain.Execute(5);

            Assert.AreEqual<string>("15", output);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:11,代码来源:LinearTests.cs

示例6: TestTypeMismatch

        public void TestTypeMismatch()
        {
            Chain<int, int> chain = new Chain<int, int>();
            chain.Link<int>(x => x + 1)
                .Link<string>(x => x)
                .Link<int>(x => x);

            LinkArgumentException laErr = null;
            try
            {
                int output = chain.Execute(0);
            }
            catch (LinkArgumentException lae)
            {
                laErr = lae;
            }

            Assert.IsNotNull(laErr);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:19,代码来源:LinearTests.cs


注:本文中的Chain.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。