Пример #1
0
        // Overrides

        public override Expression VisitInvocationExpression(InvocationQuerySyntaxNode node)
        {
            if (string.Equals(node.Name, QuerySyntaxHelper.AscMethodName, StringComparison.OrdinalIgnoreCase))
            {
                var ascProperties = node.Arguments.Select(Visit)
                                    .OfType <MemberExpression>()
                                    .Select(i => new KeyValuePair <Expression, DocumentSortOrder>(Expression.Lambda(QuerySyntaxHelper.Convert(i, typeof(object)), Parameter), DocumentSortOrder.Asc))
                                    .ToArray();

                return(Expression.Constant(ascProperties));
            }

            if (string.Equals(node.Name, QuerySyntaxHelper.DescMethodName, StringComparison.OrdinalIgnoreCase))
            {
                var descProperties = node.Arguments.Select(Visit)
                                     .OfType <MemberExpression>()
                                     .Select(i => new KeyValuePair <Expression, DocumentSortOrder>(Expression.Lambda(QuerySyntaxHelper.Convert(i, typeof(object)), Parameter), DocumentSortOrder.Desc))
                                     .ToArray();

                return(Expression.Constant(descProperties));
            }

            return(base.VisitInvocationExpression(node));
        }
        private static Expression CreateAnyFilterForArrayProperty(ExpressionFilterQuerySyntaxVisitor visitor, InvocationQuerySyntaxNode node, Func <Expression, Expression, Expression> filter)
        {
            // filter(arrayProperty, item) --> Enumerable.Any(i.arrayProperty, ii => filter(ii, item))
            var arrayProperty = visitor.Visit(node.Arguments[0]);
            var item          = visitor.Visit(node.Arguments[1]);
            var itemType      = QuerySyntaxHelper.GetCollectionItemType(arrayProperty.Type);
            var itemParameter = Expression.Parameter(itemType);

            return(QuerySyntaxHelper.InvokeAny(itemType, arrayProperty, Expression.Lambda(QuerySyntaxHelper.Compare(itemParameter, item, filter), itemParameter)));
        }