Пример #1
0
        private static string VisitMethod(MethodCallExpression expression, string currentClause)
        {
            currentClause = VisitExpression(expression.Object, currentClause);
            var argVals     = MethodExpressionArgumentEvaluator.EvaluateArguments(expression);
            var matchFormat = expression.Method.GetCustomAttribute <ParseToCypherAttribute>().Format;

            return(currentClause + String.Format(matchFormat, argVals));
        }
            protected override Expression VisitMethodCall(MethodCallExpression m)
            {
                var cypherFunctionAttribute = m.Method.GetCustomAttribute <ParseToCypherAttribute>();

                if (cypherFunctionAttribute != null)
                {
                    var @params = MethodExpressionArgumentEvaluator.EvaluateArguments(m);
                    _queryBuilder.Append(string.Format(cypherFunctionAttribute.Format, @params));
                    return(m);
                }

                throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
            }
        private static string ParseExpressionToTerm(Expression node, MemberInfo memberInfo)
        {
            node = ExpressionEvaluator.PartialEval(node);
            var constantExp = node as ConstantExpression;

            if (constantExp != null)
            {
                return(constantExp.ToCypherString() + " as " + memberInfo.Name);
            }

            var member = node as MemberExpression;

            // new { prop = param.EntityRef }
            if (member != null)
            {
                var entityName          = member.Member.Name;
                var entityPropertyNames = new EntityReturnColumns(memberInfo.Name);

                return(BuildStatement(entityName, entityPropertyNames, typeof(Relationship).IsAssignableFrom(((PropertyInfo)member.Member).PropertyType)));
            }

            var method = node as MethodCallExpression;

            // new { prop = param.GraphEntity.Prop<T>("prop") }
            if (method != null)
            {
                if (typeof(IGraphEntity).IsAssignableFrom(method.Method.DeclaringType))
                {
                    var methodMember = method.Object as MemberExpression;
                    if (methodMember != null)
                    {
                        var entityName = methodMember.Member.Name;
                        var args       = MethodExpressionArgumentEvaluator.EvaluateArguments(method);
                        var retval     = String.Format("{0}.{1}? as {2}", entityName, args[0], memberInfo.Name);
                        return(retval);
                    }
                }

                var cypherFunctionAttribute = method.Method.GetCustomAttribute <ParseToCypherAttribute>();
                if (cypherFunctionAttribute != null)
                {
                    var @params = MethodExpressionArgumentEvaluator.EvaluateArguments(method);
                    return(string.Format(cypherFunctionAttribute.Format, @params) + " as " +
                           memberInfo.Name);
                }
            }

            throw new InvalidCypherReturnsExpressionException();
        }
Пример #4
0
        private static string BuildStartClause(MethodCallExpression body, string currentExpression)
        {
            var declareAssignMethod = body.Method;

            if (declareAssignMethod.DeclaringType.GetGenericTypeDefinition() != typeof(IStartQueryContext <>))
            {
                throw new InvalidCypherStartExpressionException();
            }

            if (body.Object is MethodCallExpression)
            {
                currentExpression = BuildStartClause((MethodCallExpression)body.Object, currentExpression);
            }

            var findMethodFormat =
                declareAssignMethod.GetCustomAttribute <ParseToCypherAttribute>().Format;
            var @params        = MethodExpressionArgumentEvaluator.EvaluateArguments(body);
            var thisAssignment = string.Format(findMethodFormat, @params);

            return(String.Join(", ", new[] { currentExpression, thisAssignment }.Where(s => !String.IsNullOrEmpty(s))));
        }
        private static string ParseExpressionToTerm(Expression node)
        {
            if (node.NodeType == ExpressionType.Convert)
            {
                return(ParseExpressionToTerm(((UnaryExpression)node).Operand));
            }

            var method = node as MethodCallExpression;

            // new { prop = param.GraphEntity.Prop<T>("prop") }
            if (method != null)
            {
                var cypherFunctionAttribute = method.Method.GetCustomAttribute <ParseToCypherAttribute>();
                if (cypherFunctionAttribute != null)
                {
                    var @params = MethodExpressionArgumentEvaluator.EvaluateArguments(method);
                    return(string.Format(cypherFunctionAttribute.Format, @params));
                }
            }

            throw new InvalidOrderByClauseException();
        }
Пример #6
0
        internal static string BuildSetClause(Expression exp)
        {
            var lambda = exp as LambdaExpression;

            if (lambda == null)
            {
                throw new InvalidCypherStartExpressionException();
            }

            var body = lambda.Body as MethodCallExpression;

            if (body == null)
            {
                throw new InvalidCypherStartExpressionException();
            }

            var declareAssignMethod = body.Method;

            var setFormat =
                declareAssignMethod.GetCustomAttribute <ParseToCypherAttribute>().Format;
            var @params = MethodExpressionArgumentEvaluator.EvaluateArguments(body);

            return(string.Format(setFormat, @params));
        }