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();
            }
        }