public override Expression ToExpression(ParserContext parserContext)
 {
     Expression test = ExpressionFingerprint.ToExpression(this.Test, parserContext);
     Expression ifTrue = ExpressionFingerprint.ToExpression(this.IfTrue, parserContext);
     Expression ifFalse = ExpressionFingerprint.ToExpression(this.IfFalse, parserContext);
     return Expression.Condition(test, ifTrue, ifFalse);
 }
        public static ConstantExpressionFingerprint Create(ConstantExpression expression, ParserContext parserContext) {
            ConstantExpressionFingerprint fingerprint = new ConstantExpressionFingerprint(expression) {
                HoistedLocalsIndex = parserContext.HoistedValues.Count
            };

            parserContext.HoistedValues.Add(expression.Value);
            return fingerprint;
        }
 public static ParameterExpressionFingerprint Create(ParameterExpression expression, ParserContext parserContext)
 {
     if (expression == parserContext.ModelParameter)
     {
         return new ParameterExpressionFingerprint(expression);
     }
     return null;
 }
 public static MemberExpressionFingerprint Create(MemberExpression expression, ParserContext parserContext)
 {
     ExpressionFingerprint fingerprint = ExpressionFingerprint.Create(expression.Expression, parserContext);
     if ((fingerprint == null) && (expression.Expression != null))
     {
         return null;
     }
     return new MemberExpressionFingerprint(expression) { Target = fingerprint };
 }
 public static UnaryExpressionFingerprint Create(UnaryExpression expression, ParserContext parserContext)
 {
     ExpressionFingerprint fingerprint = ExpressionFingerprint.Create(expression.Operand, parserContext);
     if ((fingerprint == null) && (expression.Operand != null))
     {
         return null;
     }
     return new UnaryExpressionFingerprint(expression) { Operand = fingerprint };
 }
 public override Expression ToExpression(ParserContext parserContext)
 {
     Expression expression = ExpressionFingerprint.ToExpression(this.Operand, parserContext);
     if (base.NodeType == ExpressionType.UnaryPlus)
     {
         return Expression.UnaryPlus(expression, this.Method);
     }
     return Expression.MakeUnary(base.NodeType, expression, base.Type, this.Method);
 }
 public static ParameterExpressionFingerprint Create(ParameterExpression expression, ParserContext parserContext) {
     if (expression == parserContext.ModelParameter) {
         return new ParameterExpressionFingerprint(expression);
     }
     else {
         // degenerate case - uncaptured parameter expression passed into the system
         return null;
     }
 }
        public static MemberExpressionFingerprint Create(MemberExpression expression, ParserContext parserContext) {
            ExpressionFingerprint target = Create(expression.Expression, parserContext);
            if (target == null && expression.Expression != null) {
                return null;
            }

            return new MemberExpressionFingerprint(expression) {
                Target = target
            };
        }
        public override Expression ToExpression(ParserContext parserContext) {
            Expression operandExpr = ToExpression(Operand, parserContext);

            // in .NET 3.5 SP1, Expression.MakeUnary() throws if NodeType is UnaryPlus, so special-case
            if (NodeType == ExpressionType.UnaryPlus) {
                return Expression.UnaryPlus(operandExpr, Method);
            }
            else {
                return Expression.MakeUnary(NodeType, operandExpr, Type, Method);
            }
        }
Example #10
0
        public static ExpressionFingerprint Create(Expression expression, ParserContext parserContext)
        {
            {
                BinaryExpression binaryExpression = expression as BinaryExpression;
                if (binaryExpression != null) {
                    return BinaryExpressionFingerprint.Create(binaryExpression, parserContext);
                }
            }

            {
                ConditionalExpression conditionalExpression = expression as ConditionalExpression;
                if (conditionalExpression != null) {
                    return ConditionalExpressionFingerprint.Create(conditionalExpression, parserContext);
                }
            }

            {
                ConstantExpression constantExpression = expression as ConstantExpression;
                if (constantExpression != null) {
                    return ConstantExpressionFingerprint.Create(constantExpression, parserContext);
                }
            }

            {
                MemberExpression memberExpression = expression as MemberExpression;
                if (memberExpression != null) {
                    return MemberExpressionFingerprint.Create(memberExpression, parserContext);
                }
            }

            {
                MethodCallExpression methodCallExpression = expression as MethodCallExpression;
                if (methodCallExpression != null) {
                    return MethodCallExpressionFingerprint.Create(methodCallExpression, parserContext);
                }
            }

            {
                ParameterExpression parameterExpression = expression as ParameterExpression;
                if (parameterExpression != null) {
                    return ParameterExpressionFingerprint.Create(parameterExpression, parserContext);
                }
            }

            {
                UnaryExpression unaryExpression = expression as UnaryExpression;
                if (unaryExpression != null) {
                    return UnaryExpressionFingerprint.Create(unaryExpression, parserContext);
                }
            }

            // unknown expression
            return null;
        }
        public static UnaryExpressionFingerprint Create(UnaryExpression expression, ParserContext parserContext) {
            ExpressionFingerprint operand = Create(expression.Operand, parserContext);
            if (operand == null && expression.Operand != null) {
                // couldn't convert the operand, so bail
                return null;
            }

            return new UnaryExpressionFingerprint(expression) {
                Operand = operand
            };
        }
 public static ReadOnlyCollection<ExpressionFingerprint> Create(IEnumerable<Expression> expressions, ParserContext parserContext)
 {
     List<ExpressionFingerprint> list = new List<ExpressionFingerprint>();
     foreach (Expression expression in expressions)
     {
         ExpressionFingerprint item = Create(expression, parserContext);
         if ((item == null) && (expression != null))
         {
             return null;
         }
         list.Add(item);
     }
     return new ReadOnlyCollection<ExpressionFingerprint>(list);
 }
 public static MethodCallExpressionFingerprint Create(MethodCallExpression expression, ParserContext parserContext)
 {
     ReadOnlyCollection<ExpressionFingerprint> onlys = ExpressionFingerprint.Create(expression.Arguments, parserContext);
     if (onlys == null)
     {
         return null;
     }
     ExpressionFingerprint fingerprint = ExpressionFingerprint.Create(expression.Object, parserContext);
     if ((fingerprint == null) && (expression.Object != null))
     {
         return null;
     }
     return new MethodCallExpressionFingerprint(expression) { Arguments = onlys, Target = fingerprint };
 }
        public static MethodCallExpressionFingerprint Create(MethodCallExpression expression, ParserContext parserContext) {
            ReadOnlyCollection<ExpressionFingerprint> arguments = Create(expression.Arguments, parserContext);
            if (arguments == null) {
                return null;
            }

            ExpressionFingerprint target = Create(expression.Object, parserContext);
            if (target == null && expression.Object != null) {
                return null;
            }

            return new MethodCallExpressionFingerprint(expression) {
                Arguments = arguments,
                Target = target
            };
        }
 public static BinaryExpressionFingerprint Create(BinaryExpression expression, ParserContext parserContext)
 {
     if (expression.Conversion != null)
     {
         return null;
     }
     ExpressionFingerprint fingerprint = ExpressionFingerprint.Create(expression.Left, parserContext);
     if ((fingerprint == null) && (expression.Left != null))
     {
         return null;
     }
     ExpressionFingerprint fingerprint2 = ExpressionFingerprint.Create(expression.Right, parserContext);
     if ((fingerprint2 == null) && (expression.Right != null))
     {
         return null;
     }
     return new BinaryExpressionFingerprint(expression) { Left = fingerprint, Right = fingerprint2 };
 }
 public static ConditionalExpressionFingerprint Create(ConditionalExpression expression, ParserContext parserContext)
 {
     ExpressionFingerprint fingerprint = ExpressionFingerprint.Create(expression.Test, parserContext);
     if ((fingerprint == null) && (expression.Test != null))
     {
         return null;
     }
     ExpressionFingerprint fingerprint2 = ExpressionFingerprint.Create(expression.IfTrue, parserContext);
     if ((fingerprint2 == null) && (expression.IfTrue != null))
     {
         return null;
     }
     ExpressionFingerprint fingerprint3 = ExpressionFingerprint.Create(expression.IfFalse, parserContext);
     if ((fingerprint3 == null) && (expression.IfFalse != null))
     {
         return null;
     }
     return new ConditionalExpressionFingerprint(expression) { Test = fingerprint, IfTrue = fingerprint2, IfFalse = fingerprint3 };
 }
 public static ExpressionFingerprint Create(Expression expression, ParserContext parserContext)
 {
     BinaryExpression expression2 = expression as BinaryExpression;
     if (expression2 != null)
     {
         return BinaryExpressionFingerprint.Create(expression2, parserContext);
     }
     ConditionalExpression expression3 = expression as ConditionalExpression;
     if (expression3 != null)
     {
         return ConditionalExpressionFingerprint.Create(expression3, parserContext);
     }
     ConstantExpression expression4 = expression as ConstantExpression;
     if (expression4 != null)
     {
         return ConstantExpressionFingerprint.Create(expression4, parserContext);
     }
     MemberExpression expression5 = expression as MemberExpression;
     if (expression5 != null)
     {
         return MemberExpressionFingerprint.Create(expression5, parserContext);
     }
     MethodCallExpression expression6 = expression as MethodCallExpression;
     if (expression6 != null)
     {
         return MethodCallExpressionFingerprint.Create(expression6, parserContext);
     }
     ParameterExpression expression7 = expression as ParameterExpression;
     if (expression7 != null)
     {
         return ParameterExpressionFingerprint.Create(expression7, parserContext);
     }
     UnaryExpression expression8 = expression as UnaryExpression;
     if (expression8 != null)
     {
         return UnaryExpressionFingerprint.Create(expression8, parserContext);
     }
     return null;
 }
        public static BinaryExpressionFingerprint Create(BinaryExpression expression, ParserContext parserContext) {
            if (expression.Conversion != null) {
                // we don't support the Conversion property
                return null;
            }

            // if any fingerprinting fails, bail out
            ExpressionFingerprint left = Create(expression.Left, parserContext);
            if (left == null && expression.Left != null) {
                return null;
            }

            ExpressionFingerprint right = Create(expression.Right, parserContext);
            if (right == null && expression.Right != null) {
                return null;
            }

            return new BinaryExpressionFingerprint(expression) {
                Left = left,
                Right = right
            };
        }
        public static ConditionalExpressionFingerprint Create(ConditionalExpression expression, ParserContext parserContext) {
            // if any fingerprinting fails, bail out
            ExpressionFingerprint test = Create(expression.Test, parserContext);
            if (test == null && expression.Test != null) {
                return null;
            }

            ExpressionFingerprint ifTrue = Create(expression.IfTrue, parserContext);
            if (ifTrue == null && expression.IfTrue != null) {
                return null;
            }

            ExpressionFingerprint ifFalse = Create(expression.IfFalse, parserContext);
            if (ifFalse == null && expression.IfFalse != null) {
                return null;
            }

            return new ConditionalExpressionFingerprint(expression) {
                Test = test,
                IfTrue = ifTrue,
                IfFalse = ifFalse
            };
        }
 public override Expression ToExpression(ParserContext parserContext) {
     Expression testExpr = ToExpression(Test, parserContext);
     Expression ifTrueExpr = ToExpression(IfTrue, parserContext);
     Expression ifFalseExpr = ToExpression(IfFalse, parserContext);
     return Expression.Condition(testExpr, ifTrueExpr, ifFalseExpr);
 }
 public abstract Expression ToExpression(ParserContext parserContext);
 protected static IEnumerable<Expression> ToExpression(IEnumerable<ExpressionFingerprint> fingerprints, ParserContext parserContext) {
     return from fingerprint in fingerprints select ToExpression(fingerprint, parserContext);
 }
 protected static Expression ToExpression(ExpressionFingerprint fingerprint, ParserContext parserContext) {
     return (fingerprint != null) ? fingerprint.ToExpression(parserContext) : null;
 }
 public static ReadOnlyCollection<ExpressionFingerprint> Create(IEnumerable<Expression> expressions, ParserContext parserContext) {
     List<ExpressionFingerprint> fingerprints = new List<ExpressionFingerprint>();
     foreach (Expression expression in expressions) {
         ExpressionFingerprint fingerprint = Create(expression, parserContext);
         if (fingerprint == null && expression != null) {
             // something couldn't be parsed properly
             return null;
         }
         else {
             fingerprints.Add(fingerprint);
         }
     }
     return new ReadOnlyCollection<ExpressionFingerprint>(fingerprints);
 }
        public static ExpressionFingerprint Create(Expression expression, ParserContext parserContext)
        {
            {
                BinaryExpression binaryExpression = expression as BinaryExpression;
                if (binaryExpression != null)
                {
                    return(BinaryExpressionFingerprint.Create(binaryExpression, parserContext));
                }
            }

            {
                ConditionalExpression conditionalExpression = expression as ConditionalExpression;
                if (conditionalExpression != null)
                {
                    return(ConditionalExpressionFingerprint.Create(conditionalExpression, parserContext));
                }
            }

            {
                ConstantExpression constantExpression = expression as ConstantExpression;
                if (constantExpression != null)
                {
                    return(ConstantExpressionFingerprint.Create(constantExpression, parserContext));
                }
            }

            {
                MemberExpression memberExpression = expression as MemberExpression;
                if (memberExpression != null)
                {
                    return(MemberExpressionFingerprint.Create(memberExpression, parserContext));
                }
            }

            {
                MethodCallExpression methodCallExpression = expression as MethodCallExpression;
                if (methodCallExpression != null)
                {
                    return(MethodCallExpressionFingerprint.Create(methodCallExpression, parserContext));
                }
            }

            {
                ParameterExpression parameterExpression = expression as ParameterExpression;
                if (parameterExpression != null)
                {
                    return(ParameterExpressionFingerprint.Create(parameterExpression, parserContext));
                }
            }

            {
                UnaryExpression unaryExpression = expression as UnaryExpression;
                if (unaryExpression != null)
                {
                    return(UnaryExpressionFingerprint.Create(unaryExpression, parserContext));
                }
            }

            // unknown expression
            return(null);
        }
        public static ReadOnlyCollection <ExpressionFingerprint> Create(IEnumerable <Expression> expressions, ParserContext parserContext)
        {
            List <ExpressionFingerprint> fingerprints = new List <ExpressionFingerprint>();

            foreach (Expression expression in expressions)
            {
                ExpressionFingerprint fingerprint = Create(expression, parserContext);
                if (fingerprint == null && expression != null)
                {
                    // something couldn't be parsed properly
                    return(null);
                }
                else
                {
                    fingerprints.Add(fingerprint);
                }
            }
            return(new ReadOnlyCollection <ExpressionFingerprint>(fingerprints));
        }
 public override Expression ToExpression(ParserContext parserContext)
 {
     Expression left = ExpressionFingerprint.ToExpression(this.Left, parserContext);
     Expression right = ExpressionFingerprint.ToExpression(this.Right, parserContext);
     return Expression.MakeBinary(base.NodeType, left, right, this.IsLiftedToNull, this.Method);
 }
 protected static Expression ToExpression(ExpressionFingerprint fingerprint, ParserContext parserContext)
 {
     return((fingerprint != null) ? fingerprint.ToExpression(parserContext) : null);
 }
 protected static IEnumerable <Expression> ToExpression(IEnumerable <ExpressionFingerprint> fingerprints, ParserContext parserContext)
 {
     return(from fingerprint in fingerprints select ToExpression(fingerprint, parserContext));
 }
 public abstract Expression ToExpression(ParserContext parserContext);
        public static MethodCallExpressionFingerprint Create(MethodCallExpression expression, ParserContext parserContext)
        {
            ReadOnlyCollection <ExpressionFingerprint> arguments = Create(expression.Arguments, parserContext);

            if (arguments == null)
            {
                return(null);
            }

            ExpressionFingerprint target = Create(expression.Object, parserContext);

            if (target == null && expression.Object != null)
            {
                return(null);
            }

            return(new MethodCallExpressionFingerprint(expression)
            {
                Arguments = arguments,
                Target = target
            });
        }
 public override Expression ToExpression(ParserContext parserContext)
 {
     Expression instance = ExpressionFingerprint.ToExpression(this.Target, parserContext);
     IEnumerable<Expression> arguments = ExpressionFingerprint.ToExpression(this.Arguments, parserContext);
     return Expression.Call(instance, this.Method, arguments);
 }
 public override Expression ToExpression(ParserContext parserContext) {
     Expression targetExpr = ToExpression(Target, parserContext);
     return Expression.MakeMemberAccess(targetExpr, Member);
 }
 public override Expression ToExpression(ParserContext parserContext) {
     // (Type) HoistedValues[HoistedLocalsIndex]
     BinaryExpression arrayIndex = Expression.ArrayIndex(ParserContext.HoistedValuesParameter, Expression.Constant(HoistedLocalsIndex));
     UnaryExpression castExpr = Expression.Convert(arrayIndex, Type);
     return castExpr;
 }
 public override Expression ToExpression(ParserContext parserContext) {
     // The only time an instance of this class exists is if it represents the actual model parameter,
     // so just return it directly.
     return parserContext.ModelParameter;
 }
 public override Expression ToExpression(ParserContext parserContext)
 {
     return Expression.MakeMemberAccess(ExpressionFingerprint.ToExpression(this.Target, parserContext), this.Member);
 }