public static ConstantExpressionFingerprint Create(ConstantExpression expression, ParserContext parserContext) {
            ConstantExpressionFingerprint fingerprint = new ConstantExpressionFingerprint(expression) {
                HoistedLocalsIndex = parserContext.HoistedValues.Count
            };

            parserContext.HoistedValues.Add(expression.Value);
            return fingerprint;
        }
Пример #2
0
 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;
     }
 }
Пример #3
0
        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 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;
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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 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
            };
        }
Пример #8
0
        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 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
            });
        }
Пример #11
0
 public override Expression ToExpression(ParserContext parserContext) {
     Expression targetExpr = ToExpression(Target, parserContext);
     return Expression.MakeMemberAccess(targetExpr, Member);
 }
Пример #12
0
 public override Expression ToExpression(ParserContext parserContext) {
     Expression leftExpr = ToExpression(Left, parserContext);
     Expression rightExpr = ToExpression(Right, parserContext);
     return Expression.MakeBinary(NodeType, leftExpr, rightExpr, IsLiftedToNull, Method);
 }
Пример #13
0
 public CompiledExpressionDelegate <TModel, TValue> GetDelegate(ParserContext context)
 {
     return(FetchOrCreateItem(context.Fingerprint, () => CreateDelegate(context)));
 }
Пример #14
0
 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;
 }
Пример #16
0
 public override Expression ToExpression(ParserContext parserContext) {
     Expression targetExpr = ToExpression(Target, parserContext);
     IEnumerable<Expression> argumentsExpr = ToExpression(Arguments, parserContext);
     return Expression.Call(targetExpr, Method, argumentsExpr);
 }
Пример #17
0
                private static CompiledExpressionDelegate <TModel, TValue> CreateDelegate(ParserContext context)
                {
                    var bodyExpr   = context.Fingerprint.ToExpression(context);
                    var lambdaExpr = Expression.Lambda <CompiledExpressionDelegate <TModel, TValue> >(bodyExpr, context.ModelParameter, ParserContext.HoistedValuesParameter);
                    var del        = lambdaExpr.Compile();

                    return(del);
                }
 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 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
            });
        }
 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 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 testExpr = ToExpression(Test, parserContext);
     Expression ifTrueExpr = ToExpression(IfTrue, parserContext);
     Expression ifFalseExpr = ToExpression(IfFalse, parserContext);
     return Expression.Condition(testExpr, ifTrueExpr, ifFalseExpr);
 }