Exemplo n.º 1
0
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.IsNonGenericMethod <bool>(typeof(IQueryableItem <>), "Matches"))
            {
                if (IsInsideNotModifier())
                {
                    throw new InvalidOperationException("Unsupported not operation for method Matches");
                }

                var expression       = m.GetUnaryExpressionOperand();
                var entityType       = m.GetMethodExpressionGenericType();
                var entityFilterType = typeof(EntityFilter <>).MakeGenericType(entityType);
                var matchesFilter    = (QueryFilter)Activator.CreateInstance(entityFilterType, expression);
                AppendQueryFilter(matchesFilter);
                return(m);
            }

            if (m.IsGenericMethod <bool>(typeof(IQueryableItem), "Is"))
            {
                var entityType = m.GetGenericMethodArgument();
                AppendQueryFilter(new EntityTypeFilter(entityType, IsInsideNotModifier()));
                return(m);
            }

            if (m.IsGenericMethod <bool>(typeof(IQueryableItem), "HasRelationship") ||
                m.IsGenericMethod <bool>(typeof(IQueryableItem <>), "HasRelationship"))
            {
                if (IsInsideNotModifier())
                {
                    throw new InvalidOperationException("Unsupported not operation for method HasRelationship");
                }

                var relationType = m.GetGenericMethodArgument();
                AppendQueryFilter(new RelationshipFilter(relationType));
                return(m);
            }

            if (m.IsGenericMethod <bool>(typeof(IQueryableItem), "HasInboundRelationship") ||
                m.IsGenericMethod <bool>(typeof(IQueryableItem <>), "HasInboundRelationship"))
            {
                if (IsInsideNotModifier())
                {
                    throw new InvalidOperationException("Unsupported not operation for method HasInboundRelationship");
                }

                var relationType = m.GetGenericMethodArgument();
                AppendQueryFilter(new RelationshipToFilter(relationType));
                return(m);
            }

            if (m.IsGenericMethod <bool>(typeof(IQueryableItem), "HasOutboundRelationship") ||
                m.IsGenericMethod <bool>(typeof(IQueryableItem <>), "HasOutboundRelationship"))
            {
                if (IsInsideNotModifier())
                {
                    throw new InvalidOperationException("Unsupported not operation for method HasOutboundRelationship");
                }

                var relationType = m.GetGenericMethodArgument();
                AppendQueryFilter(new RelationshipFromFilter(relationType));
                return(m);
            }

            throw new InvalidOperationException($"Unknown method {m.ToString()}");
        }