Exemplo n.º 1
0
        private static LambdaExpression ComposeWithInlining(IReadOnlyList <LambdaExpression> projections, int indexToMerge)
        {
            var currentProjection = projections[indexToMerge];

            if (indexToMerge == 0)
            {
                return(currentProjection);
            }

            // construct the merger of all previous projections
            var previousProjection = ComposeWithInlining(projections, indexToMerge - 1);

            Throw.If(!currentProjection.Parameters[0].Type.IsAssignableFrom(previousProjection.ReturnType), "projections: cannot be chained due to type mismatch");

            // merge the current with the previous by inlining
            var replacer    = new ParameterReplacer(currentProjection.Parameters[0], previousProjection.Body);
            var inlinedBody = replacer.Visit(currentProjection.Body);

            return(Expression.Lambda(inlinedBody, previousProjection.Parameters));
        }
        private static LambdaExpression ComposeWithInlining(IReadOnlyList<LambdaExpression> projections, int indexToMerge)
        {
            var currentProjection = projections[indexToMerge];

            if (indexToMerge == 0)
            {
                return currentProjection;
            }

            // construct the merger of all previous projections
            var previousProjection = ComposeWithInlining(projections, indexToMerge - 1);
            Throw.If(!currentProjection.Parameters[0].Type.IsAssignableFrom(previousProjection.ReturnType), "projections: cannot be chained due to type mismatch");

            // merge the current with the previous by inlining
            var replacer = new ParameterReplacer(currentProjection.Parameters[0], previousProjection.Body);
            var inlinedBody = replacer.Visit(currentProjection.Body);
            return Expression.Lambda(inlinedBody, previousProjection.Parameters);
        }