internal override Expression VisitMemberAccess(MemberExpression m) { PropertyInfo info; Expression expression; Type type = m.Expression.Type; this.leafExpressionIsMemberAccess = true; if (PrimitiveType.IsKnownNullableType(type)) { this.leafExpressionIsMemberAccess = false; return(base.VisitMemberAccess(m)); } if (ProjectionAnalyzer.IsCollectionProducingExpression(m.Expression)) { throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, m.ToString())); } if (!ResourceBinder.PatternRules.MatchNonPrivateReadableProperty(m, out info, out expression)) { throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, m.ToString())); } Expression expression2 = base.VisitMemberAccess(m); if (ClientTypeUtil.TypeOrElementTypeIsEntity(type)) { Type type2; ResourceBinder.StripTo <Expression>(m.Expression, out type2); this.box.AppendPropertyToPath(info, type2, this.context); this.leafExpressionIsMemberAccess = false; } return(expression2); }
internal override Expression VisitTypeIs(TypeBinaryExpression b) { if (ClientTypeUtil.TypeOrElementTypeIsEntity(b.Expression.Type) || ProjectionAnalyzer.IsCollectionProducingExpression(b.Expression)) { throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, b.ToString())); } return(base.VisitTypeIs(b)); }
internal override Expression VisitInvocation(InvocationExpression iv) { if ((ClientTypeUtil.TypeOrElementTypeIsEntity(iv.Expression.Type) || ProjectionAnalyzer.IsCollectionProducingExpression(iv.Expression)) || iv.Arguments.Any <Expression>(delegate(Expression a) { if (!ClientTypeUtil.TypeOrElementTypeIsEntity(a.Type)) { return(ProjectionAnalyzer.IsCollectionProducingExpression(a)); } return(true); })) { throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, iv.ToString())); } return(base.VisitInvocation(iv)); }
internal override Expression VisitUnary(UnaryExpression u) { UnaryExpression expression = (UnaryExpression)base.VisitUnary(u); Expression rewritten = expression; this.RecordRewrite(u, rewritten); if ((expression.NodeType != ExpressionType.Convert) && (expression.NodeType != ExpressionType.TypeAs)) { return(rewritten); } if (!expression.Type.IsAssignableFrom(expression.Operand.Type)) { return(rewritten); } if ((PrimitiveType.IsKnownNullableType(expression.Operand.Type) || PrimitiveType.IsKnownNullableType(expression.Type)) && !(expression.Operand.Type == expression.Type)) { return(rewritten); } if (ClientTypeUtil.TypeOrElementTypeIsEntity(expression.Operand.Type) && ProjectionAnalyzer.IsCollectionProducingExpression(expression.Operand)) { return(rewritten); } return(expression.Operand); }
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)); }
/// <summary> /// CODE: x /// ORIGINAL: Convert(x, t) where t is assignable from typeof(x) /// ORIGINAL: x as t, where t is assignable from typeof(x) /// ORIGINAL: and typeof(x) or t are not known primitives unless typeof(x) == t /// ORIGINAL: and x is not a collection of entity types /// NORMALIZED: x /// </summary> internal override Expression VisitUnary(UnaryExpression u) { UnaryExpression visited = (UnaryExpression)base.VisitUnary(u); Expression result = visited; // Note that typically we would record a potential rewrite // after extracting the conversion, but we avoid doing this // because it breaks undoing the rewrite by making the non-local // change circular, ie: // unary [operand = a] // becomes // a <- unary [operand = a] // So the undoing visits a, then the original unary, then the // operand and again the unary, the operand, etc. this.RecordRewrite(u, result); // Convert(x, t) or x as t, where t is assignable from typeof(x) if ((visited.NodeType == ExpressionType.Convert || visited.NodeType == ExpressionType.TypeAs) && visited.Type.IsAssignableFrom(visited.Operand.Type)) { // typeof(x) or t are not known primitives unless typeof(x) == t if (!ClientConvert.IsKnownNullableType(visited.Operand.Type) && !ClientConvert.IsKnownNullableType(visited.Type) || visited.Operand.Type == visited.Type) { // x is not a collection of entity types if (!(ClientType.CheckElementTypeIsEntity(visited.Operand.Type) && ProjectionAnalyzer.IsCollectionProducingExpression(visited.Operand))) { result = visited.Operand; } } } return(result); }
internal override Expression VisitUnary(UnaryExpression u) { UnaryExpression visited = (UnaryExpression)base.VisitUnary(u); Expression result = visited; this.RecordRewrite(u, result); if ((visited.NodeType == ExpressionType.Convert || visited.NodeType == ExpressionType.TypeAs) && visited.Type.IsAssignableFrom(visited.Operand.Type)) { if (!ClientConvert.IsKnownNullableType(visited.Operand.Type) && !ClientConvert.IsKnownNullableType(visited.Type) || visited.Operand.Type == visited.Type) { if (!(ClientType.CheckElementTypeIsEntity(visited.Operand.Type) && ProjectionAnalyzer.IsCollectionProducingExpression(visited.Operand))) { result = visited.Operand; } } } return(result); }