コード例 #1
0
        public override Expression HandleOperation(
            QueryableFilterContext context,
            IFilterOperationField field,
            IValueNode value,
            object parsedValue)
        {
            if (context.RuntimeTypes.Count > 0 &&
                context.RuntimeTypes.Peek().TypeArguments is { Count : > 0 } args&&
                parsedValue is bool parsedBool)
            {
                Expression?property = context.GetInstance();

                Expression expression;
                if (parsedBool)
                {
                    expression = FilterExpressionBuilder.Any(args[0].Source, property);
                }
                else
                {
                    expression = FilterExpressionBuilder.Not(
                        FilterExpressionBuilder.Any(args[0].Source, property));
                }

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

                return(expression);
            }
            throw new InvalidOperationException();
        }
コード例 #2
0
        public override bool TryHandleLeave(
            QueryableFilterContext context,
            IFilterField field,
            ObjectFieldNode node,
            [NotNullWhen(true)] out ISyntaxVisitorAction?action)
        {
            if (field.RuntimeType is null)
            {
                action = null;
                return(false);
            }

            // Deque last
            Expression condition = context.GetLevel().Dequeue();

            context.PopInstance();
            context.RuntimeTypes.Pop();

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

            context.GetLevel().Enqueue(condition);
            action = SyntaxVisitor.Continue;
            return(true);
        }
コード例 #3
0
        /// <inheritdoc />
        public override bool TryHandleLeave(
            QueryableFilterContext context,
            IFilterField field,
            ObjectFieldNode node,
            [NotNullWhen(true)] out ISyntaxVisitorAction?action)
        {
            IExtendedType runtimeType = context.RuntimeTypes.Pop();

            if (context.TryCreateLambda(out LambdaExpression? lambda))
            {
                context.Scopes.Pop();
                Expression instance   = context.PopInstance();
                Expression expression = HandleListOperation(
                    context,
                    field,
                    node,
                    runtimeType.Source,
                    lambda);

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

                context.GetLevel().Enqueue(expression);
            }


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