private string GetCode(UnaryExpression e) { if (e.NodeType == ExpressionType.Convert) { return $"({e.Type}) {e.Operand}"; } return e.ToString(); }
/// <summary> /// Process the not operator. /// </summary> /// <param name="expression">The expression to visit.</param> /// <returns>The visited expression.</returns> protected override Expression VisitUnary(UnaryExpression expression) { if (expression != null) { switch (expression.NodeType) { case ExpressionType.Not: this.filter.Append(" not("); this.Visit(expression.Operand); this.filter.Append(")"); this.MarkVisited(); break; case ExpressionType.Quote: this.Visit(StripUnaryOperator(expression)); this.MarkVisited(); break; case ExpressionType.Convert: // Ignore conversion requests if the conversion will // happen implicitly on the server anyway if (IsConversionImplicit(expression, expression.Operand.Type, expression.Type)) { this.Visit(StripUnaryOperator(expression)); this.MarkVisited(); break; } // Otherwise the conversion isn't supported goto default; default: throw new NotSupportedException( string.Format( CultureInfo.InvariantCulture, Resources.FilterBuildingExpressionVisitor_VisitOperator_Unsupported, expression.NodeType, expression.ToString())); } } return expression; }
protected HqlTreeNode VisitUnaryExpression(UnaryExpression expression) { switch (expression.NodeType) { case ExpressionType.Not: return _hqlTreeBuilder.BooleanNot(VisitExpression(expression.Operand).AsBooleanExpression()); case ExpressionType.Convert: case ExpressionType.ConvertChecked: { if (expression.Operand.Type.IsPrimitive && expression.Type.IsPrimitive) return _hqlTreeBuilder.Cast(VisitExpression(expression.Operand).AsExpression(), expression.Type); return VisitExpression(expression.Operand); } } throw new NotSupportedException(expression.ToString()); }
protected HqlTreeNode VisitUnaryExpression(UnaryExpression expression) { switch (expression.NodeType) { case ExpressionType.Not: return _hqlTreeBuilder.BooleanNot(VisitExpression(expression.Operand).AsBooleanExpression()); case ExpressionType.Convert: case ExpressionType.ConvertChecked: case ExpressionType.TypeAs: if ((expression.Operand.Type.IsPrimitive || expression.Operand.Type == typeof(Decimal)) && (expression.Type.IsPrimitive || expression.Type == typeof(Decimal))) { return _hqlTreeBuilder.Cast(VisitExpression(expression.Operand).AsExpression(), expression.Type); } return VisitExpression(expression.Operand); } throw new NotSupportedException(expression.ToString()); }
private string TranslateUnary(UnaryExpression expression) { string sql = Translate(expression.Operand); switch (expression.NodeType) { case ExpressionType.Negate: case ExpressionType.NegateChecked: return $"(-{sql})"; case ExpressionType.UnaryPlus: case ExpressionType.Unbox: case ExpressionType.Convert: case ExpressionType.ConvertChecked: case ExpressionType.Quote: return sql; case ExpressionType.Not: return $"(NOT {sql})"; } throw new SqlExpressionTranslatorException(expression.ToString()); }
/// <summary>Visits a unary expression while initializing a non-entity type structure.</summary> /// <param name="u">Expression to visit.</param> /// <returns>The visited expression.</returns> internal override Expression VisitUnary(UnaryExpression u) { Debug.Assert(u != null, "u != null"); if (!ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { if (ClientType.CheckElementTypeIsEntity(u.Operand.Type)) { throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjection(this.type, u.ToString())); } } return base.VisitUnary(u); }
internal override Expression VisitUnary(UnaryExpression u) { Debug.Assert(u != null, "u != null"); // Perfectly assignable conversions are OK. VB.NET compilers // inserts these to exactly match method signatures, for example. if (ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { return base.VisitUnary(u); } if ((u.NodeType == ExpressionType.Convert) || (u.NodeType == ExpressionType.ConvertChecked)) { Type sourceType = Nullable.GetUnderlyingType(u.Operand.Type) ?? u.Operand.Type; Type targetType = Nullable.GetUnderlyingType(u.Type) ?? u.Type; // when projecting known entity types, will allow convert expressions of primitive types. if (ClientConvert.IsKnownType(sourceType) && ClientConvert.IsKnownType(targetType)) { return base.Visit(u.Operand); } } throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, u.ToString())); }
internal override Expression VisitUnary(UnaryExpression u) { Debug.Assert(u != null, "u != null"); if (!ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { if (CommonUtil.IsClientType(u.Operand.Type)) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.ALinqExpressionNotSupportedInProjection, this.type, u.ToString())); } } return base.VisitUnary(u); }
internal override Expression VisitUnary(UnaryExpression u) { Debug.Assert(u != null, "u != null"); if (ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { return base.VisitUnary(u); } if ((u.NodeType == ExpressionType.Convert) || (u.NodeType == ExpressionType.ConvertChecked)) { Type sourceType = Nullable.GetUnderlyingType(u.Operand.Type) ?? u.Operand.Type; Type targetType = Nullable.GetUnderlyingType(u.Type) ?? u.Type; if (ClientConvert.IsKnownType(sourceType) && ClientConvert.IsKnownType(targetType)) { return base.Visit(u.Operand); } } throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.ALinqExpressionNotSupportedInProjectionToEntity, this.type, u.ToString())); }
protected HqlTreeNode VisitUnaryExpression(UnaryExpression expression) { switch (expression.NodeType) { case ExpressionType.Not: return _hqlTreeBuilder.BooleanNot(VisitExpression(expression.Operand).AsBooleanExpression()); case ExpressionType.Convert: return VisitExpression(expression.Operand); } throw new NotSupportedException(expression.ToString()); }
internal override Expression VisitUnary(UnaryExpression u) { if (!ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { if ((u.NodeType == ExpressionType.TypeAs) && this.leafExpressionIsMemberAccess) { return base.VisitUnary(u); } if (ClientTypeUtil.TypeOrElementTypeIsEntity(u.Operand.Type)) { throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjection(this.type, u.ToString())); } } return base.VisitUnary(u); }
internal override Expression VisitUnary(UnaryExpression u) { if (ResourceBinder.PatternRules.MatchConvertToAssignable(u) || ((u.NodeType == ExpressionType.TypeAs) && this.leafExpressionIsMemberAccess)) { return base.VisitUnary(u); } if ((u.NodeType == ExpressionType.Convert) || (u.NodeType == ExpressionType.ConvertChecked)) { Type type = Nullable.GetUnderlyingType(u.Operand.Type) ?? u.Operand.Type; Type type2 = Nullable.GetUnderlyingType(u.Type) ?? u.Type; if (PrimitiveType.IsKnownType(type) && PrimitiveType.IsKnownType(type2)) { return base.Visit(u.Operand); } } throw new NotSupportedException(System.Data.Services.Client.Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, u.ToString())); }
/// <summary>Visits a unary expression while initializing a non-entity type structure.</summary> /// <param name="u">Expression to visit.</param> /// <returns>The visited expression.</returns> internal override Expression VisitUnary(UnaryExpression u) { Debug.Assert(u != null, "u != null"); if (!ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { // In V3 while we support TypeAs conversions, we only support TypeAs before a MemberAccess and not TypeAs as the last operation // i.e. we support "Manager = (p as Employee).Manager" (see VisitMemberAccess for detail), but we dont support "Manager = (p as Manager)" // Note that the server also doesn't support a property path which ends with a type identifier. if (u.NodeType == ExpressionType.TypeAs && this.leafExpressionIsMemberAccess) { return base.VisitUnary(u); } if (ClientTypeUtil.TypeOrElementTypeIsEntity(u.Operand.Type)) { throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjection(this.type, u.ToString())); } } return base.VisitUnary(u); }
internal override Expression VisitUnary(UnaryExpression u) { Debug.Assert(u != null, "u != null"); // Perfectly assignable conversions are OK. VB.NET compilers // inserts these to exactly match method signatures, for example. if (ResourceBinder.PatternRules.MatchConvertToAssignable(u) || (u.NodeType == ExpressionType.TypeAs && this.leafExpressionIsMemberAccess)) { return base.VisitUnary(u); } if ((u.NodeType == ExpressionType.Convert) || (u.NodeType == ExpressionType.ConvertChecked)) { Type sourceType = Nullable.GetUnderlyingType(u.Operand.Type) ?? u.Operand.Type; Type targetType = Nullable.GetUnderlyingType(u.Type) ?? u.Type; // when projecting known entity types, will allow convert expressions of primitive types. if (PrimitiveType.IsKnownType(sourceType) && PrimitiveType.IsKnownType(targetType)) { return base.Visit(u.Operand); } } // In V3 while we support TypeAs conversions, we only support TypeAs before a MemberAccess and not TypeAs as the last operation // i.e. we support "Manager = (p as Employee).Manager" (see VisitMemberAccess for detail), but we dont support "Manager = (p as Manager)" // Note that the server also doesn't support a property path which ends with a type identifier. throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, u.ToString())); }
/// <summary> /// Process the not operator. /// </summary> /// <param name="expression"> /// The expression to visit. /// </param> /// <returns> /// The visited expression. /// </returns> private Expression VisitUnary(UnaryExpression expression) { if (expression != null) { switch (expression.NodeType) { case ExpressionType.Not: this.Visit(expression.Operand); this.filterExpression.Push(new UnaryOperatorNode(UnaryOperatorKind.Not, this.filterExpression.Pop())); break; case ExpressionType.Quote: this.Visit(StripUnaryOperator(expression)); break; case ExpressionType.Convert: // Ignore conversion requests if the conversion will // happen implicitly on the server anyway if (IsConversionImplicit(expression, expression.Operand.Type, expression.Type)) { this.Visit(StripUnaryOperator(expression)); break; } // Otherwise the conversion isn't supported goto default; default: throw new NotSupportedException( string.Format( CultureInfo.InvariantCulture, "The operator '{0}' is not supported in the 'Where' Mobile Services query expression '{1}'.", expression.NodeType, expression.ToString())); } } return expression; }
protected override Expression VisitUnary(UnaryExpression node) { Visit(node.Operand); if (node.NodeType == ExpressionType.Not) { _expression.Negated = !_expression.Negated; } else { throw new NotSupportedException(node.ToString()); } return node; }