internal override Expression VisitConditional(ConditionalExpression conditional)
        {
            Expression expressionBeforeNormalization = this.GetExpressionBeforeNormalization(conditional);

            if (expressionBeforeNormalization != conditional)
            {
                return(this.Visit(expressionBeforeNormalization));
            }
            ResourceBinder.PatternRules.MatchNullCheckResult nullCheck = ResourceBinder.PatternRules.MatchNullCheck(this.pathBuilder.LambdaParameterInScope, conditional);
            if (!nullCheck.Match || !ClientTypeUtil.TypeOrElementTypeIsEntity(ResourceBinder.StripConvertToAssignable(nullCheck.TestToNullExpression).Type))
            {
                Expression test = null;
                if (nullCheck.Match)
                {
                    Expression left = this.Visit(nullCheck.TestToNullExpression);
                    if (left.NodeType == ExpressionType.Convert)
                    {
                        left = ((UnaryExpression)left).Operand;
                    }
                    test = Expression.MakeBinary(ExpressionType.Equal, left, Expression.Constant(null));
                }
                if (test == null)
                {
                    test = this.Visit(conditional.Test);
                }
                Expression ifTrue  = this.Visit(conditional.IfTrue);
                Expression ifFalse = this.Visit(conditional.IfFalse);
                if (((test != conditional.Test) || (ifTrue != conditional.IfTrue)) || (ifFalse != conditional.IfFalse))
                {
                    return(Expression.Condition(test, ifTrue, ifFalse, ifTrue.Type.IsAssignableFrom(ifFalse.Type) ? ifTrue.Type : ifFalse.Type));
                }
            }
            return(this.RebindConditionalNullCheck(conditional, nullCheck));
        }
 internal override Expression VisitConditional(ConditionalExpression c)
 {
     ResourceBinder.PatternRules.MatchNullCheckResult result = ResourceBinder.PatternRules.MatchNullCheck(this.box.ParamExpressionInScope, c);
     if (!result.Match)
     {
         throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, c.ToString()));
     }
     this.Visit(result.AssignExpression);
     return(c);
 }
Beispiel #3
0
 internal override Expression VisitConditional(ConditionalExpression c)
 {
     ResourceBinder.PatternRules.MatchNullCheckResult matchNullCheckResult = ResourceBinder.PatternRules.MatchNullCheck(box.ParamExpressionInScope, c);
     if (matchNullCheckResult.Match)
     {
         Visit(matchNullCheckResult.AssignExpression);
         return(c);
     }
     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", type, c.ToString()));
 }
Beispiel #4
0
 internal override Expression VisitConditional(ConditionalExpression c)
 {
     ResourceBinder.PatternRules.MatchNullCheckResult matchNullCheckResult = ResourceBinder.PatternRules.MatchNullCheck(entity, c);
     if (matchNullCheckResult.Match)
     {
         Visit(matchNullCheckResult.AssignExpression);
         return(c);
     }
     return(base.VisitConditional(c));
 }
 internal override Expression VisitConditional(ConditionalExpression c)
 {
     ResourceBinder.PatternRules.MatchNullCheckResult result = ResourceBinder.PatternRules.MatchNullCheck(this.box.ParamExpressionInScope, c);
     if (result.Match)
     {
         this.Visit(result.AssignExpression);
         return(c);
     }
     if (((ClientTypeUtil.TypeOrElementTypeIsEntity(c.Test.Type) || ClientTypeUtil.TypeOrElementTypeIsEntity(c.IfTrue.Type)) || (ClientTypeUtil.TypeOrElementTypeIsEntity(c.IfFalse.Type) || ProjectionAnalyzer.IsCollectionProducingExpression(c.Test))) || (ProjectionAnalyzer.IsCollectionProducingExpression(c.IfTrue) || ProjectionAnalyzer.IsCollectionProducingExpression(c.IfFalse)))
     {
         throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, c.ToString()));
     }
     return(base.VisitConditional(c));
 }
Beispiel #6
0
 internal override Expression VisitConditional(ConditionalExpression c)
 {
     ResourceBinder.PatternRules.MatchNullCheckResult matchNullCheckResult = ResourceBinder.PatternRules.MatchNullCheck(box.ParamExpressionInScope, c);
     if (matchNullCheckResult.Match)
     {
         Visit(matchNullCheckResult.AssignExpression);
         return(c);
     }
     if (CommonUtil.IsClientType(c.Test.Type) || CommonUtil.IsClientType(c.IfTrue.Type) || CommonUtil.IsClientType(c.IfFalse.Type))
     {
         throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, c.ToString()));
     }
     return(base.VisitConditional(c));
 }
Beispiel #7
0
        private Expression RebindConditionalNullCheck(ConditionalExpression conditional, ResourceBinder.PatternRules.MatchNullCheckResult nullCheck)
        {
            Debug.Assert(conditional != null, "conditional != null");
            Debug.Assert(nullCheck.Match, "nullCheck.Match -- otherwise no reason to call this rebind method");

            Expression           testToNullForProjection = this.Visit(nullCheck.TestToNullExpression);
            Expression           assignForProjection     = this.Visit(nullCheck.AssignExpression);
            ExpressionAnnotation testToNullAnnotation;

            if (!this.annotations.TryGetValue(testToNullForProjection, out testToNullAnnotation))
            {
                return(base.VisitConditional(conditional));
            }

            ProjectionPathSegment testToNullSegment = testToNullAnnotation.Segment;

            Expression testToNullThroughMethod = this.CallCheckValueForPathIsNull(
                testToNullSegment.StartPath.RootEntry,
                testToNullSegment.StartPath.ExpectedRootType,
                testToNullSegment.StartPath);

            Expression test    = testToNullThroughMethod;
            Expression iftrue  = Expression.Constant(null, assignForProjection.Type);
            Expression iffalse = assignForProjection;
            Expression result  = Expression.Condition(test, iftrue, iffalse);

            return(result);
        }
        private Expression RebindConditionalNullCheck(ConditionalExpression conditional, ResourceBinder.PatternRules.MatchNullCheckResult nullCheck)
        {
            ExpressionAnnotation annotation;
            Expression           key         = this.Visit(nullCheck.TestToNullExpression);
            Expression           expression2 = this.Visit(nullCheck.AssignExpression);

            if (!this.annotations.TryGetValue(key, out annotation))
            {
                return(base.VisitConditional(conditional));
            }
            ProjectionPathSegment segment = annotation.Segment;
            Expression            test    = this.CallCheckValueForPathIsNull(segment.StartPath.RootEntry, segment.StartPath.ExpectedRootType, segment.StartPath);
            Expression            ifTrue  = Expression.Constant(null, expression2.Type);
            Expression            ifFalse = expression2;

            return(Expression.Condition(test, ifTrue, ifFalse));
        }