Example #1
0
        private Expression RebindMemberAccess(MemberExpression m, ExpressionAnnotation baseAnnotation)
        {
            Debug.Assert(m != null, "m != null");
            Debug.Assert(baseAnnotation != null, "baseAnnotation != null");

            ProjectionPathSegment memberSegment;

            Expression baseSourceExpression = m.Expression;
            Expression result = this.pathBuilder.GetRewrite(baseSourceExpression);

            if (result != null)
            {
                Expression            baseTypeExpression = Expression.Constant(baseSourceExpression.Type, typeof(Type));
                ProjectionPath        nestedPath         = new ProjectionPath(result as ParameterExpression, baseTypeExpression, result);
                ProjectionPathSegment nestedSegment      = new ProjectionPathSegment(nestedPath, m.Member.Name, m.Type);
                nestedPath.Add(nestedSegment);
                result = this.CallValueForPathWithType(result, baseTypeExpression, nestedPath, m.Type);
            }
            else
            {
                memberSegment = new ProjectionPathSegment(baseAnnotation.Segment.StartPath, m.Member.Name, m.Type);
                baseAnnotation.Segment.StartPath.Add(memberSegment);
                result = this.CallValueForPathWithType(
                    baseAnnotation.Segment.StartPath.RootEntry,
                    baseAnnotation.Segment.StartPath.ExpectedRootType,
                    baseAnnotation.Segment.StartPath,
                    m.Type);
            }

            return(result);
        }
Example #2
0
        private Expression RebindParameter(Expression expression, ExpressionAnnotation annotation)
        {
            Debug.Assert(expression != null, "expression != null");
            Debug.Assert(annotation != null, "annotation != null");

            Expression result;

            result = this.CallValueForPathWithType(
                annotation.Segment.StartPath.RootEntry,
                annotation.Segment.StartPath.ExpectedRootType,
                annotation.Segment.StartPath,
                expression.Type);

            ProjectionPath parameterPath = new ProjectionPath(
                annotation.Segment.StartPath.Root,
                annotation.Segment.StartPath.ExpectedRootType,
                annotation.Segment.StartPath.RootEntry);
            ProjectionPathSegment parameterSegment = new ProjectionPathSegment(parameterPath, null, null);

            parameterPath.Add(parameterSegment);
            this.annotations[expression] = new ExpressionAnnotation()
            {
                Segment = parameterSegment
            };

            return(result);
        }
 internal override Expression VisitLambda(LambdaExpression lambda)
 {
     if (!this.topLevelProjectionFound || ((lambda.Parameters.Count == 1) && ClientTypeUtil.TypeOrElementTypeIsEntity(lambda.Parameters[0].Type)))
     {
         this.topLevelProjectionFound = true;
         ParameterExpression expectedType = Expression.Parameter(typeof(Type), "type" + this.identifierId);
         ParameterExpression entry        = Expression.Parameter(typeof(object), "entry" + this.identifierId);
         this.identifierId++;
         this.pathBuilder.EnterLambdaScope(lambda, entry, expectedType);
         ProjectionPath        startPath = new ProjectionPath(lambda.Parameters[0], expectedType, entry);
         ProjectionPathSegment item      = new ProjectionPathSegment(startPath, null, null);
         startPath.Add(item);
         ExpressionAnnotation annotation = new ExpressionAnnotation {
             Segment = item
         };
         this.annotations[lambda.Parameters[0]] = annotation;
         Expression expression4 = this.Visit(lambda.Body);
         if (expression4.Type.IsValueType)
         {
             expression4 = Expression.Convert(expression4, typeof(object));
         }
         Expression expression = Expression.Lambda <Func <object, object, Type, object> >(expression4, new ParameterExpression[] { this.materializerExpression, entry, expectedType });
         this.pathBuilder.LeaveLambdaScope();
         return(expression);
     }
     return(base.VisitLambda(lambda));
 }
        private Expression RebindParameter(Expression expression, ExpressionAnnotation annotation)
        {
            Expression            expression2 = this.CallValueForPathWithType(annotation.Segment.StartPath.RootEntry, annotation.Segment.StartPath.ExpectedRootType, annotation.Segment.StartPath, expression.Type);
            ProjectionPath        startPath   = new ProjectionPath(annotation.Segment.StartPath.Root, annotation.Segment.StartPath.ExpectedRootType, annotation.Segment.StartPath.RootEntry);
            ProjectionPathSegment item        = new ProjectionPathSegment(startPath, null, null);

            startPath.Add(item);
            ExpressionAnnotation annotation2 = new ExpressionAnnotation {
                Segment = item
            };

            this.annotations[expression] = annotation2;
            return(expression2);
        }
Example #5
0
        internal override Expression VisitLambda(LambdaExpression lambda)
        {
            Debug.Assert(lambda != null, "lambda != null");

            Expression result;

            if (!this.topLevelProjectionFound || lambda.Parameters.Count == 1 && ClientType.CheckElementTypeIsEntity(lambda.Parameters[0].Type))
            {
                this.topLevelProjectionFound = true;

                ParameterExpression expectedTypeParameter = Expression.Parameter(typeof(Type), "type" + this.identifierId);
                ParameterExpression entryParameter        = Expression.Parameter(typeof(object), "entry" + this.identifierId);
                this.identifierId++;

                this.pathBuilder.EnterLambdaScope(lambda, entryParameter, expectedTypeParameter);
                ProjectionPath        parameterPath    = new ProjectionPath(lambda.Parameters[0], expectedTypeParameter, entryParameter);
                ProjectionPathSegment parameterSegment = new ProjectionPathSegment(parameterPath, null, null);
                parameterPath.Add(parameterSegment);
                this.annotations[lambda.Parameters[0]] = new ExpressionAnnotation()
                {
                    Segment = parameterSegment
                };

                Expression body = this.Visit(lambda.Body);

                if (body.Type.IsValueType)
                {
                    body = Expression.Convert(body, typeof(object));
                }

                result = Expression.Lambda <Func <object, object, Type, object> >(
                    body,
                    this.materializerExpression,
                    entryParameter,
                    expectedTypeParameter);

                this.pathBuilder.LeaveLambdaScope();
            }
            else
            {
                result = base.VisitLambda(lambda);
            }

            return(result);
        }
        private Expression RebindMemberAccess(MemberExpression m, ExpressionAnnotation baseAnnotation)
        {
            Expression expression = m.Expression;
            Expression rewrite    = this.pathBuilder.GetRewrite(expression);

            if (rewrite != null)
            {
                Expression            expectedRootType = Expression.Constant(expression.Type, typeof(Type));
                ProjectionPath        startPath        = new ProjectionPath(rewrite as ParameterExpression, expectedRootType, rewrite);
                ProjectionPathSegment segment2         = new ProjectionPathSegment(startPath, m);
                startPath.Add(segment2);
                return(this.CallValueForPathWithType(rewrite, expectedRootType, startPath, m.Type));
            }
            ProjectionPathSegment item = new ProjectionPathSegment(baseAnnotation.Segment.StartPath, m);

            baseAnnotation.Segment.StartPath.Add(item);
            return(this.CallValueForPathWithType(baseAnnotation.Segment.StartPath.RootEntry, baseAnnotation.Segment.StartPath.ExpectedRootType, baseAnnotation.Segment.StartPath, m.Type));
        }