Example #1
0
        /// <summary>
        /// The entry-point of <see cref="PageSelectVisitor"/>.
        /// </summary>
        public static IEnumerable <PropQueryParameters> Process <TSource, TResult>(
            Expression <Func <TSource, TResult> > expression, out Func <PageData, TResult> processedExpression)
        {
            var visitor = new PageSelectVisitor(expression.Parameters.Single());
            var body    = visitor.Visit(expression.Body);

            var gatherer = new UsedPropertiesGatherer();

            gatherer.Gather(body, visitor.m_pageDataGetInfoCall);

            var parameters = visitor.m_parameters;

            if (!gatherer.UsedDirectly && gatherer.UsedProperties.Any(p => !NonInfoProperties.Contains(p)))
            {
                var propQueryParameters = new PropQueryParameters("info").WithProperties(gatherer.UsedProperties);

                var tokens = gatherer.UsedProperties
                             .Where(p => p.EndsWith("token"))
                             .Select(p => p.Substring(0, p.Length - "token".Length))
                             .ToArray();

                if (tokens.Any())
                {
                    propQueryParameters = propQueryParameters.AddSingleValue("token", tokens.ToQueryString());
                }

                parameters["info"] = propQueryParameters;
            }

            processedExpression =
                Expression.Lambda <Func <PageData, TResult> >(body, visitor.m_pageDataParameter).Compile();

            return(parameters.Values);
        }
Example #2
0
        /// <summary>
        /// Parses the select clause of a page source query.
        /// The result is a modified collection of parameters
        /// and a delegate that can be used to create the result for each item
        /// (in the form of <see cref="PageData"/>).
        /// </summary>
        public static PageQueryParameters ParseSelect <TSource, TResult>(
            Expression <Func <TSource, TResult> > expression, PageQueryParameters baseParameters,
            out Func <PageData, TResult> processedExpression)
        {
            var parameters = PageSelectVisitor.Process(expression, out processedExpression);

            return(baseParameters.WithParameters(parameters));
        }