Example #1
0
            public Task <TDestination> Output <TDestination>()
            {
                PipeOutputPackage     solvedPipePackage = _solver.SolveAsPipePackage(typeof(TSource), typeof(TDestination));
                Func <object, object> transformInput    =
                    TransformerFactory.ConvertFor(typeof(TSource), solvedPipePackage.InputType);
                Func <object, object> transformOutput =
                    TransformerFactory.ConvertFor(solvedPipePackage.OutputType, typeof(TDestination));

                var input = transformInput(_source);

                return
                    (solvedPipePackage.ProcessInput(input, _broker)
                     .ContinueWith(task => (TDestination)transformOutput(task.Result)));
            }
        private static PipeOutputPackage SimplifyInput(PipeOutputPackage package)
        {
            Type newInputType = DetermineNewInterestType(package.InputType);

            if (newInputType == package.InputType)
            {
                return(package);
            }

            PipeCallback processCallbackFunc = (input, broker) =>
            {
                Func <object, object> transformFunc =
                    TransformerFactory.ConvertFor(newInputType, package.InputType);
                object revisedInput = transformFunc(input);
                return(package.ProcessInput(revisedInput, broker));
            };

            return(PipeOutputPackage.Direct(newInputType, package.OutputType, processCallbackFunc));
        }