Beispiel #1
0
        public static void Run()
        {
            typeof(FourthTest).Top();
            var input = 10;

            Console.WriteLine($"Input Value:{input}[{input.GetType()}]");
            var pipeline = new EventStep <int, int>(new DoubleStep());

            pipeline.OnInput  += i => Console.WriteLine($"Input Value:{i}");
            pipeline.OnOutput += o => Console.WriteLine($"Output Value:{o}");
            var output = pipeline.Process(input);

            Console.WriteLine($"Output Value: {output} [{output.GetType()}]");
            Console.WriteLine("\r\n");

            //补充:使用扩展方法进行调用
            Console.WriteLine(10.Step(new DoubleStep(), i =>
            {
                Console.WriteLine($"Input Value:{i}");
            },
                                      o =>
            {
                Console.WriteLine($"Output Value:{o}");
            }));
        }
Beispiel #2
0
        public static OUTPUT Step <INPUT, OUTPUT>(this INPUT input, IPipelineStep <INPUT, OUTPUT> step, Action <INPUT> inputEvent = null, Action <OUTPUT> outputEvent = null)
        {
            if (inputEvent != null || outputEvent != null)
            {
                var eventDecorator = new EventStep <INPUT, OUTPUT>(step);
                eventDecorator.OnInput  += inputEvent;
                eventDecorator.OnOutput += outputEvent;

                return(eventDecorator.Process(input));
            }
            return(step.Process(input));
        }