Beispiel #1
0
        /// <summary>
        /// Precompiles a parameterized query to optimized parallel code that can by invoked using a Func.
        /// <b>Warning</b> : Enabling non-public member access might lead to performance degradation.
        /// </summary>
        /// <typeparam name="T1">The type of the first query parameter.</typeparam>
        /// <typeparam name="T2">The type of the second query parameter.</typeparam>
        /// <typeparam name="T3">The type of the third query parameter.</typeparam>
        /// <typeparam name="T4">The type of the fourth query parameter.</typeparam>
        /// <typeparam name="T5">The type of the fifth query parameter.</typeparam>
        /// <typeparam name="TResult">The type of the query.</typeparam>
        /// <param name="template">The parameterized query.</param>
        /// <param name="enableNonPublicMemberAccess">Enable or not non public member access from the compiled code.</param>
        /// <returns>A delegate to the optimized query.</returns>
        public static Func <T1, T2, T3, T4, T5, TResult> Compile <T1, T2, T3, T4, T5, TResult>(this Expression <Func <T1, T2, T3, T4, IParallelQueryExpr <TResult> > > template, bool enableNonPublicMemberAccess = false)
        {
            var param = template.Parameters.ToArray();
            var query = CSharpExpressionOptimizer.ToQueryExpr(template.Body);

            return((Func <T1, T2, T3, T4, T5, TResult>)CoreHelpers.CompileTemplateToParallelVariadic <TResult>(param, query, CSharpExpressionOptimizer.Optimize, enableNonPublicMemberAccess));
        }
        /// <summary>
        /// Precompiles a parameterized query to optimized code that can by invoked using a Func.
        /// <b>Warning</b> : Enabling non-public member access might lead to performance degradation.
        /// </summary>
        /// <typeparam name="T1">The type of the first query parameter.</typeparam>
        /// <typeparam name="T2">The type of the second query parameter.</typeparam>
        /// <typeparam name="T3">The type of the third query parameter.</typeparam>
        /// <typeparam name="T4">The type of the fourth query parameter.</typeparam>
        /// <typeparam name="T5">The type of the fifth query parameter.</typeparam>
        /// <param name="template">The parameterized query.</param>
        /// <param name="enableNonPublicMemberAccess">Enable or not non public member access from the compiled code.</param>
        /// <returns>A delegate to the optimized query.</returns>
        public static Action <T1, T2, T3, T4, T5> Compile <T1, T2, T3, T4, T5>(this Expression <Func <T1, T2, T3, T4, IQueryExpr> > template, bool enableNonPublicMemberAccess = false)
        {
            var param = template.Parameters.ToArray();
            var query = CSharpExpressionOptimizer.ToQueryExpr(template.Body);

            return((Action <T1, T2, T3, T4, T5>)CoreHelpers.CompileActionTemplateVariadic(param, query, CSharpExpressionOptimizer.Optimize, enableNonPublicMemberAccess));
        }
Beispiel #3
0
        /// <summary>
        /// Creates a parallel query that projects each element of a sequence to an IEnumerable, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TCol">The type of the intermediate elements collected by collectionSelector.</typeparam>
        /// <typeparam name="TResult">The type of the elements of the sequence returned by selector.</typeparam>
        /// <param name="query">A query whose values to project.</param>
        /// <param name="collectionSelector">A transform function to apply to each element of the input sequence.</param>
        /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
        /// <returns>A parallel query whose elements are the result of invoking the one-to-many transform function on each element of the input sequence and the result selector function on each element therein.</returns>
        public static IParallelQueryExpr <IEnumerable <TResult> > SelectMany <TSource, TCol, TResult>(this IParallelQueryExpr <IEnumerable <TSource> > query, Expression <Func <TSource, IEnumerable <TCol> > > collectionSelector, Expression <Func <TSource, TCol, TResult> > resultSelector)
        {
            var paramExpr = collectionSelector.Parameters.Single();
            var bodyExpr  = collectionSelector.Body;
            var nested    = Tuple.Create(paramExpr, CSharpExpressionOptimizer.ToQueryExpr(bodyExpr));

            return(new ParallelQueryExpr <IEnumerable <TResult> >(QExpr.NewNestedQueryTransform(nested, resultSelector, query.Expr)));
        }
        /// <summary>
        /// Creates a new query that projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TResult">The type of the elements of the sequence returned by selector.</typeparam>
        /// <param name="query">A query whose values to project.</param>
        /// <param name="selector">A transform function to apply to each element.</param>
        /// <returns>A query whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.</returns>
        public static IQueryExpr <IEnumerable <TResult> > SelectMany <TSource, TResult>(this IQueryExpr <IEnumerable <TSource> > query, Expression <Func <TSource, IEnumerable <TResult> > > selector)
        {
            var paramExpr = selector.Parameters.Single();
            var bodyExpr  = selector.Body;
            var nested    = Tuple.Create(paramExpr, CSharpExpressionOptimizer.ToQueryExpr(bodyExpr));

            return(new QueryExpr <IEnumerable <TResult> >(QExpr.NewNestedQuery(nested, query.Expr)));
        }