Exemplo n.º 1
0
        public void Leave(
            FilterOperationField field,
            ObjectFieldNode node,
            IQueryableFilterVisitorContext context)
        {
            if (field.Operation.Kind == FilterOperationKind.ArraySome ||
                field.Operation.Kind == FilterOperationKind.ArrayNone ||
                field.Operation.Kind == FilterOperationKind.ArrayAll)
            {
                QueryableClosure nestedClosure = context.PopClosure();
                LambdaExpression lambda        = nestedClosure.CreateLambda();
                Type             closureType   = GetTypeFor(field.Operation);

                Expression expression;
                switch (field.Operation.Kind)
                {
                case FilterOperationKind.ArraySome:
                    expression = FilterExpressionBuilder.Any(
                        closureType,
                        context.GetInstance(),
                        lambda
                        );
                    break;

                case FilterOperationKind.ArrayNone:
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.Any(
                            closureType,
                            context.GetInstance(),
                            lambda
                            )
                        );
                    break;

                case FilterOperationKind.ArrayAll:
                    expression = FilterExpressionBuilder.All(
                        closureType,
                        context.GetInstance(),
                        lambda
                        );
                    break;

                default:
                    throw new NotSupportedException();
                }

                if (context.InMemory)
                {
                    expression = FilterExpressionBuilder.NotNullAndAlso(
                        context.GetInstance(), expression);
                }

                context.GetLevel().Enqueue(expression);
                context.PopInstance();
            }
        }
        public static QueryableClosure AddIsNullClosure(
            this IQueryableFilterVisitorContext context,
            Type type)
        {
            QueryableClosure closure =
                context.AddClosure(type, "_s" + context.Closures.Count, false);

            context.GetLevel().Enqueue(FilterExpressionBuilder.Equals(closure.Parameter, null));
            return(closure);
        }
Exemplo n.º 3
0
        public static void Leave(
            FilterOperationField field,
            ObjectFieldNode node,
            IQueryableFilterVisitorContext context)
        {
            if (field.Operation.Kind == FilterOperationKind.Object)
            {
                // Deque last expression to prefix with nullcheck
                Expression condition = context.GetLevel().Dequeue();
                Expression property  = context.GetInstance();

                // wrap last expression only if  in memory
                if (context.InMemory)
                {
                    condition = FilterExpressionBuilder.NotNullAndAlso(
                        property, condition);
                }

                context.GetLevel().Enqueue(condition);
                context.PopInstance();
            }
        }
Exemplo n.º 4
0
        public static bool Enter(
            FilterOperationField field,
            ObjectFieldNode node,
            IQueryableFilterVisitorContext context,
            [NotNullWhen(true)] out ISyntaxVisitorAction?action)
        {
            if (node.Value.IsNull())
            {
                if (field.Operation.IsNullable)
                {
                    MemberExpression nestedProperty = Expression.Property(
                        context.GetInstance(),
                        field.Operation.Property);

                    Expression expression =
                        FilterExpressionBuilder.Equals(nestedProperty, null !);

                    context.GetLevel().Enqueue(expression);
                }
                else
                {
                    context.ReportError(
                        ErrorHelper.CreateNonNullError(field, node, context));
                }

                action = SyntaxVisitor.Skip;
                return(true);
            }

            if (field.Operation.Kind == FilterOperationKind.Object)
            {
                MemberExpression nestedProperty = Expression.Property(
                    context.GetInstance(),
                    field.Operation.Property);

                context.PushInstance(nestedProperty);
                action = SyntaxVisitor.Continue;
                return(true);
            }
            action = null;
            return(false);
        }