Exemple #1
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 void AddFingerprint(ExpressionFingerprint fingerprint) {
     if (fingerprint != null) {
         fingerprint.AddToHashCodeCombiner(this);
     }
     else {
         AddInt32(0);
     }
 }
 public void AddFingerprint(ExpressionFingerprint fingerprint)
 {
     if (fingerprint != null)
     {
         fingerprint.AddToHashCodeCombiner(this);
     }
     else
     {
         AddInt32(0);
     }
 }
        public static ParserContext Parse <TModel, TValue>(Expression <Func <TModel, TValue> > expression)
        {
            ParserContext context = new ParserContext()
            {
                ModelParameter = expression.Parameters[0]
            };

            Expression body = expression.Body;

            context.Fingerprint = ExpressionFingerprint.Create(body, context);
            return(context);
        }
        public override bool Equals(object obj)
        {
            ExpressionFingerprint other = obj as ExpressionFingerprint;

            if (other == null)
            {
                return(false);
            }

            return(this.NodeType == other.NodeType &&
                   this.Type == other.Type &&
                   this.GetType() == other.GetType());
        }
        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 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> 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 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
            });
        }
 protected bool Equals(ExpressionFingerprint other)
 {
     return (other != null)
            && (this.NodeType == other.NodeType)
            && Equals(this.Type, other.Type);
 }
 protected static Expression ToExpression(ExpressionFingerprint fingerprint, ParserContext parserContext) {
     return (fingerprint != null) ? fingerprint.ToExpression(parserContext) : null;
 }
 protected bool Equals(ExpressionFingerprint other)
 {
     return((other != null) &&
            (this.NodeType == other.NodeType) &&
            Equals(this.Type, other.Type));
 }
 protected static Expression ToExpression(ExpressionFingerprint fingerprint, ParserContext parserContext)
 {
     return((fingerprint != null) ? fingerprint.ToExpression(parserContext) : null);
 }
 protected static Expression ToExpression(ExpressionFingerprint fingerprint, ParserContext parserContext)
 {
     if (fingerprint == null)
     {
         return null;
     }
     return fingerprint.ToExpression(parserContext);
 }