Exemplo n.º 1
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            try
            {
                string methodName = node.Method.Name.ToLower();

                if (methodName.Equals("select"))
                {
                    /*
                     * The following means this,
                     *
                     *      01. Get arguments of select.
                     *      02. Second argument is the expression that is invoked in select.
                     *      03. If it is a new expression, it means it is possibly multiple project expression.
                     *      04. But just in case look at the number of arguments to see if it is actually projecting
                     *          more than one attributes.
                     */
                    UnaryExpression  unaryExpression  = (UnaryExpression)node.Arguments[1];
                    LambdaExpression lambdaExpression = (LambdaExpression)unaryExpression.Operand;

                    if (lambdaExpression.Body is NewExpression newExpression)
                    {
                        multipleProjectionFlag = newExpression.ArgumentCount() > 1;
                    }
                }
                functions[methodName]++;
            }
            catch (Exception e)
            {
                Logger.Log(e, Microsoft.Extensions.Logging.LogLevel.Warning);
            }

            if (node.Object != null)
            {
                Visit(node.Object);
            }

            for (int i = 0, n = node.ArgumentCount(); i < n; i++)
            {
                Visit(node.GetArgument(i));
            }

            return(node);
        }
Exemplo n.º 2
0
        /* ********************************************************************************************************
        * --------------------------------                VISITORS              -------------------------------- *
        ******************************************************************************************************** */

        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            Logger.Log("VisitMethodCall : " + node.ToString(), Microsoft.Extensions.Logging.LogLevel.Trace);

            object evalResult = EvaluateMethodAndCall(node);

            if (evalResult != null)
            {
                PadPossibleStringValueToWhere(evalResult)
                .Append(Space);

                /*
                 * We don't need to visit further nodes.
                 * Doing so will pad the arguments of the
                 * method invoked which shouldn't be done.
                 */
                return(node);
            }

            if (node.Object != null)
            {
                Visit(node.Object);
            }

            for (int i = 0, n = node.ArgumentCount(); i < n; i++)
            {
                Visit(node.GetArgument(i));
            }

            // Add an 'AND' for separating query data criteria.
            if (IsAndAble(node.Method.Name))
            {
                if (whereBuilder.Length > 0)
                {
                    whereBuilder.Append("AND").Append(Space);
                }
            }

            return(node);
        }
Exemplo n.º 3
0
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            int        start = 0;
            Expression ob    = node.Object;

            if (node.Method.GetCustomAttribute(typeof(ExtensionAttribute)) != null)
            {
                start = 1;
                ob    = node.GetArgument(0);
            }

            if (ob != null)
            {
                Visit(ob);
                Out('.');
            }
            _criteriaBuilder.Clear();
            Out(node.Method.Name);
            Out('(');
            for (int i = start, n = node.ArgumentCount(); i < n; i++)
            {
                if (i > start)
                {
                    Out(", ");
                }
                Visit(node.GetArgument(i));
            }
            Out(')');
            if (string.Equals(node.Method.Name, "Where", StringComparison.InvariantCultureIgnoreCase))
            {
                _queryCriteriaStr.Add(_criteriaBuilder.ToString());
                _queryCriteriaExp.Add(node.GetArgument(1));
            }
            _criteriaBuilder.Clear();
            return(node);
        }
Exemplo n.º 4
0
            protected override Expression VisitMethodCall(MethodCallExpression node)
            {
                Logger.Log("Visiting node : " + node.ToString(), Microsoft.Extensions.Logging.LogLevel.Trace);

                if (node.Object != null)
                {
                    Visit(node.Object);
                }

                for (int i = 0, n = node.ArgumentCount(); i < n; i++)
                {
                    Visit(node.GetArgument(i));
                }

                if (node.Method.Name.Equals("Select"))
                {
                    foreach (var arg in node.Arguments)
                    {
                        selectArguments.Add(arg);
                    }
                }

                return(node);
            }