public bool TryParse(ExpressionNodeContext context, bool withParameterName, out string output)
 {
     if (context.Node is MethodCallExpression call && call.Method.DeclaringType == typeof(Enumerable) &&
         (
             call.Method.Name == nameof(Enumerable.Any) ||
             call.Method.Name == nameof(Enumerable.All)
         ))
     {
         if (ValueOrMemberParser.TryParse(context.CreateChild(call.Arguments[0]), withParameterName, out string applyTo))
         {
             var methodName = call.Method.Name.ToLowerInvariant();
             if (call.Arguments.Count > 1)
             {
                 var le = (LambdaExpression)call.Arguments[1];
                 if (LambdaFilterParser.TryParse(new ExpressionNodeContext(le.Body, le.Parameters[0])
                 {
                     ParentContext = context
                 }, true, out string innerOutput))
                 {
                     var lambda = $"{le.Parameters[0].Name}:{innerOutput}";
                     output = $"{applyTo}/{methodName}({lambda})";
                     return(true);
                 }
             }
             else
             {
                 output = $"{applyTo}/{methodName}()";
                 return(true);
             }
         }
     }
     output = null;
     return(false);
 }
Beispiel #2
0
        public bool TryParse(ExpressionNodeContext context, bool withParameterName, out string output)
        {
            if (context.Node is BinaryExpression binary)
            {
                switch (context.Node.NodeType)
                {
                case ExpressionType.Equal:
                case ExpressionType.NotEqual:
                case ExpressionType.GreaterThan:
                case ExpressionType.GreaterThanOrEqual:
                case ExpressionType.LessThan:
                case ExpressionType.LessThanOrEqual:
                    if (ValueOrMemberParser.TryParse(context.CreateChild(binary.Left, binary.Right), withParameterName, out string left1) &&
                        ValueOrMemberParser.TryParse(context.CreateChild(binary.Right, binary.Left), withParameterName, out string right1))
                    {
                        output = $"({left1} {context.Node.NodeType.ToCompareOperator()} {right1})";
                        return(true);
                    }
                    break;

                case ExpressionType.OrElse:
                case ExpressionType.AndAlso:
                    if (LambdaFilterParser.TryParse(context.CreateChild(binary.Left), withParameterName, out string left) &&
                        LambdaFilterParser.TryParse(context.CreateChild(binary.Right), withParameterName, out string right))
                    {
                        output = $"({left} {context.Node.NodeType.ToLogicOperator()} {right})";
                        return(true);
                    }
                    break;
                }
                if (ValueOrMemberParser.TryParse(context.CreateChild(binary.Left, binary.Right), withParameterName, out string left2))
                {
                    output = left2;
                    return(true);
                }
            }
            output = null;
            return(false);
        }