Exemplo n.º 1
0
 internal static TypeEqual TypeEqual(TypeBinaryExpression expression)
 {
     return new TypeEqual()
     {
         Expression = Serialize(expression.Expression),
         TypeOperand = TypeRef.Serialize(expression.TypeOperand),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
        /// <summary>
        /// Constructor with an <see cref="TypeBinaryExpression"/> and an <see cref="ExpressionConverter"/>.
        /// </summary>
        /// <param name="expression">The original, not serializable <see cref="Expression"/>.</param>
        /// <param name="expConverter">The <see cref="ExpressionConverter"/> to convert contained <see cref="Expression">Expressions</see>.</param>
        public SerializableTypeBinaryExpression(TypeBinaryExpression expression, ExpressionConverter expConverter)
            : base(expression, expConverter)
        {
            Expression = expression.Expression.MakeSerializable(expConverter);
#if !NETFX_CORE
            TypeOperand = InterLinqTypeSystem.Instance.GetInterLinqVersionOf<InterLinqType>(expression.TypeOperand);
#else
            TypeOperand = InterLinqTypeSystem.Instance.GetInterLinqVersionOf<InterLinqType>(expression.TypeOperand.GetTypeInfo());
#endif
        }
Exemplo n.º 3
0
 static Node ParseExpression(TypeBinaryExpression e)
 {
     switch (e.NodeType)
     {
         case ExpressionType.TypeIs:
             return new BinaryNode
                 {
                     Left = Parse(e.Expression),
                     Operator = "is",
                     Right = new ConstantNode() { Text = NameOfType(e.TypeOperand) },
                     Value = GetValue(e)
                 };
         default:
             throw new NotImplementedException(string.Format(CultureInfo.CurrentCulture,
                                                             "Can't handle TypeBinaryExpression of type {0}",
                                                             e.NodeType));
     }
 }
 /// <summary>
 /// Visits a TypeBinaryExpression.
 /// </summary>
 /// <param name="node">The TypeBinaryExpression.</param>
 /// <returns>The TypeBinaryExpression.</returns>
 protected override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     _sb.Append("(");
     Visit(node.Expression);
     _sb.Append(" is ");
     _sb.Append(FriendlyTypeName(node.TypeOperand));
     _sb.Append(")");
     return node;
 }
Exemplo n.º 5
0
 protected virtual Expression VisitTypeIs(TypeBinaryExpression b)
 {
     Expression expr = Visit(b.Expression);
     return UpdateTypeIs(b, expr, b.TypeOperand);
 }
 protected override Expression VisitTypeBinaryExpression(TypeBinaryExpression expression)
 {
     return expression;
 }
Exemplo n.º 7
0
 internal override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     if (ClientType.CheckElementTypeIsEntity(b.Expression.Type) || IsCollectionProducingExpression(b.Expression))
     {
         throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjection(this.type, b.ToString()));
     }
     
     return base.VisitTypeIs(b);
 }
 protected virtual System.Linq.Expressions.Expression VisitTypeIs(TypeBinaryExpression b)
 {
     System.Linq.Expressions.Expression expr = Visit(b.Expression);
     if(expr != b.Expression)
     {
         return System.Linq.Expressions.Expression.TypeIs(expr, b.TypeOperand);
     }
     return b;
 }
 protected internal virtual new Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     return(default(Expression));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Serializes an TypeBinaryExpression to a string
        /// </summary>
        /// <param name="b">TypeBinaryExpression to serialize</param>
        /// <returns>serialized expression</returns>
        internal override Expression VisitTypeIs(TypeBinaryExpression b)
        {
            this.builder.Append(UriHelper.ISOF);
            this.builder.Append(UriHelper.LEFTPAREN);

            if (!this.IsImplicitInputReference(b.Expression))
            {
                this.Visit(b.Expression);
                this.builder.Append(UriHelper.COMMA);
                this.builder.Append(UriHelper.SPACE);
            }

            this.builder.Append(UriHelper.QUOTE);
            this.builder.Append(UriHelper.GetTypeNameForUri(b.TypeOperand, this.context));
            this.builder.Append(UriHelper.QUOTE);
            this.builder.Append(UriHelper.RIGHTPAREN);

            return b;
        }
        protected override Expression VisitTypeBinary(TypeBinaryExpression node)
        {
            var expr = Visit(node.Expression);

            return(Push(node, new XAttribute(nameof(node.TypeOperand), node.TypeOperand), new XElement(nameof(node.Expression), expr)));
        }
Exemplo n.º 12
0
 protected virtual bool VisitTypeIs(TypeBinaryExpression b, TypeBinaryExpression b2)
 {
     return(b.TypeOperand == b2.TypeOperand &&
            Visit(b.Expression, b2.Expression));
 }
        protected virtual Expression VisitTypeBinary(TypeBinaryExpression node)
        {
            var expression = this.Visit(node.Expression);

            return(UpdateTypeBinary(node, expression, node.TypeOperand));
        }
Exemplo n.º 14
0
 protected override string VisitTypeBinary(TypeBinaryExpression node) => GetType(node.TypeOperand);
Exemplo n.º 15
0
        protected internal virtual new Expression VisitTypeBinary(TypeBinaryExpression node)
        {
            Contract.Requires(node != null);

            return(default(Expression));
        }
Exemplo n.º 16
0
 protected virtual Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     throw new NotImplementedException();
 }
		private HqlTreeNode VisitTypeBinaryExpression(TypeBinaryExpression expression)
		{
			return _hqlTreeBuilder.Equality(
				_hqlTreeBuilder.Dot(Visit(expression.Expression).AsExpression(), _hqlTreeBuilder.Class()),
				_hqlTreeBuilder.Ident(expression.TypeOperand.FullName));
		}
Exemplo n.º 18
0
 protected internal override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     Expressions.Add(node);
     return(base.VisitTypeBinary(node));
 }
Exemplo n.º 19
0
 protected virtual bool CompareTypeIs(TypeBinaryExpression a, TypeBinaryExpression b)
 {
     return a.TypeOperand == b.TypeOperand
         && this.Compare(a.Expression, b.Expression);
 }
Exemplo n.º 20
0
 public TypeBinaryExpressionProxy(TypeBinaryExpression node)
 {
     ArgumentNullException.ThrowIfNull(node);
     _node = node;
 }
Exemplo n.º 21
0
 protected TypeBinaryExpression UpdateTypeIs(TypeBinaryExpression binary, Expression expression, Type typeOperand)
 {
     if (expression != binary.Expression || typeOperand != binary.TypeOperand)
     {
         return Expression.TypeIs(expression, typeOperand);
     }
     return binary;
 }
Exemplo n.º 22
0
 private Expression Convert(LinqExp.TypeBinaryExpression linqTypeBinary)
 => Expression.TypeIs(ConvertExp(linqTypeBinary.Expression), linqTypeBinary.TypeOperand);
 /// <summary>
 /// Visits a TypeBinaryExpression.
 /// </summary>
 /// <param name="node">The TypeBinaryExpression.</param>
 /// <returns>The TypeBinaryExpression.</returns>
 protected override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
        protected virtual Expression VisitTypeIs(TypeBinaryExpression b)
        {
            var expr = this.Visit(b.Expression);

            return(expr != b.Expression ? Expression.TypeIs(expr, b.TypeOperand) : b);
        }
Exemplo n.º 25
0
 protected override Expression VisitTypeIs(TypeBinaryExpression b) => InvokeEvent(TypeIsVisited, b, base.VisitTypeIs);
Exemplo n.º 26
0
 /// <summary>
 /// If the result of a TypeBinaryExpression is known statically, this
 /// returns the result, otherwise it returns null, meaning we'll need
 /// to perform the IsInst instruction at runtime.
 ///
 /// The result of this function must be equivalent to IsInst, or
 /// null.
 /// </summary>
 internal static AnalyzeTypeIsResult AnalyzeTypeIs(TypeBinaryExpression typeIs)
 {
     return(AnalyzeTypeIs(typeIs.Expression, typeIs.TypeOperand));
 }
Exemplo n.º 27
0
        private IMongoQuery BuildTypeIsQuery(TypeBinaryExpression typeBinaryExpression)
        {
            var nominalType = typeBinaryExpression.Expression.Type;
            var actualType = typeBinaryExpression.TypeOperand;

            var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(nominalType);
            var discriminator = discriminatorConvention.GetDiscriminator(nominalType, actualType);
            if (discriminator == null)
            {
                return new QueryDocument(); // matches everything
            }

            if (discriminator.IsBsonArray)
            {
                discriminator = discriminator.AsBsonArray[discriminator.AsBsonArray.Count - 1];
            }

            return Query.EQ(discriminatorConvention.ElementName, discriminator);
        }
Exemplo n.º 28
0
 public TypeBinaryExpressionProxy(TypeBinaryExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 protected override Expression VisitTypeBinaryExpression(TypeBinaryExpression expression) => expression;
Exemplo n.º 30
0
 /// <inheritdoc />
 protected override Expression VisitTypeIs(TypeBinaryExpression b) => Expression.TypeIs(Visit(b.Expression), b.TypeOperand);
Exemplo n.º 31
0
 internal override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     throw new NotSupportedException(Strings.ALinq_TypeBinaryNotSupported);
 }
Exemplo n.º 32
0
 public TypeBinaryExpressionProxy(TypeBinaryExpression node)
 {
     _node = node;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Constructor with an <see cref="TypeBinaryExpression"/> and an <see cref="ExpressionConverter"/>.
 /// </summary>
 /// <param name="expression">The original, not serializable <see cref="Expression"/>.</param>
 /// <param name="expConverter">The <see cref="ExpressionConverter"/> to convert contained <see cref="Expression">Expressions</see>.</param>
 public SerializableTypeBinaryExpression(TypeBinaryExpression expression, ExpressionConverter expConverter)
     : base(expression, expConverter)
 {
     Expression = expression.Expression.MakeSerializable(expConverter);
     TypeOperand = InterLinqTypeSystem.Instance.GetInterLinqVersionOf<InterLinqType>(expression.TypeOperand);
 }
 protected virtual void VisitTypeIs(TypeBinaryExpression type)
 {
     Visit(type.Expression);
 }
 /// <summary>
 /// TypeBinaryExpression visit method
 /// </summary>
 /// <param name="b">The TypeBinaryExpression expression to visit</param>
 /// <returns>The visited TypeBinaryExpression expression </returns>
 internal override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     writer.WriteStartElement(XmlTypeIs);
     writer.WriteElementString(XmlTypeName, b.TypeOperand.ToString());
     writer.WriteEndElement();
     return b;
 }
Exemplo n.º 36
0
 /// <summary>
 /// Visits the children of the <see cref="TypeBinaryExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified;
 /// otherwise, returns the original expression.</returns>
 protected internal virtual Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     return(node.Update(Visit(node.Expression)));
 }
Exemplo n.º 37
0
		protected virtual Expression VisitTypeIs (TypeBinaryExpression type)
		{
			Expression e = Visit (type.Expression);
			if (e != type.Expression)
				return Expression.TypeIs (e, type.TypeOperand);

			return type;
		}
Exemplo n.º 38
0
 private static string VisitTypeBinary(TypeBinaryExpression node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 39
0
 protected virtual Expression VisitTypeIs(TypeBinaryExpression binary)
 {
     Expression expr = this.Visit(binary.Expression);
     return this.UpdateTypeIs(binary, expr, binary.TypeOperand);
 }
Exemplo n.º 40
0
 public TypeBinaryExpressionMutator(TypeBinaryExpression expression)
 {
     TypeBinaryExpression = expression;
 }
Exemplo n.º 41
0
 protected override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     this.Visit(b.Expression);
     this.Write(" is ");
     this.Write(this.GetTypeName(b.TypeOperand));
     return b;
 }
 internal virtual void VisitTypeIs(TypeBinaryExpression type)
 {
     Visit(type.Expression);
 }
 /// <summary>
 /// Visits a TypeBinaryExpression.
 /// </summary>
 /// <param name="node">The TypeBinaryExpression.</param>
 /// <returns>The TypeBinaryExpression.</returns>
 protected override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     WriteHeader(node);
     using (new Indentation(this))
     {
         WriteLine("TypeOperand={0}", FriendlyClassName(node.TypeOperand));
         WriteLine("Expression:");
         VisitIndented(node.Expression);
     }
     return node;
 }
Exemplo n.º 44
0
        protected override Expression VisitTypeBinary(TypeBinaryExpression b)
        {
            var f = GetField(b.Expression);

            FieldReference fr = f as FieldReference;
            if (fr != null)
            {
                if (b.TypeOperand.IsAssignableFrom(fr.FieldType))
                {
                    sb.Append(fr.Name.SqlEscape() + " IS NOT NULL");
                }
                else
                    throw new InvalidOperationException("A {0} will never be {1}".FormatWith(fr.FieldType.TypeName(), b.TypeOperand.TypeName()));

                return b;
            }

            FieldImplementedBy fib = f as FieldImplementedBy;
            if (fib != null)
            {
                var imp = fib.ImplementationColumns.Where(kvp => b.TypeOperand.IsAssignableFrom(kvp.Key));

                if (imp.Any())
                    sb.Append(imp.ToString(kvp => kvp.Value.Name.SqlEscape() + " IS NOT NULL", " OR "));
                else
                    throw new InvalidOperationException("No implementation ({0}) will never be {1}".FormatWith(fib.ImplementationColumns.Keys.ToString(t=>t.TypeName(), ", "), b.TypeOperand.TypeName()));

                return b;
            }

            throw new NotSupportedException("'is' only works with ImplementedBy or Reference fields");
        }
 /// <summary>
 /// Visit a Is expression.
 /// </summary>
 /// <param name="typeBinaryExp"></param>
 /// <returns></returns>
 protected virtual Expression VisitTypeIs(TypeBinaryExpression typeBinaryExp)
 {
     Expression expr = Visit(typeBinaryExp.Expression);
     return expr != typeBinaryExp.Expression ? Expression.TypeIs(expr, typeBinaryExp.TypeOperand) : typeBinaryExp;
 }
 /// <summary>
 /// Visits a TypeBinaryExpression.
 /// </summary>
 /// <param name="node">The TypeBinaryExpression.</param>
 /// <returns>The TypeBinaryExpression.</returns>
 protected override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     _sb.Append("<TypeBinaryExpression>");
     return node;
 }
        private IMongoQuery BuildTypeIsQuery(TypeBinaryExpression typeBinaryExpression)
        {
            var nominalType = typeBinaryExpression.Expression.Type;
            var actualType = typeBinaryExpression.TypeOperand;

            var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(nominalType);
            var discriminator = discriminatorConvention.GetDiscriminator(nominalType, actualType);
            if (discriminator == null)
            {
                return BuildBooleanQuery(true);
            }

            if (discriminator.IsBsonArray)
            {
                discriminator = discriminator.AsBsonArray[discriminator.AsBsonArray.Count - 1];
            }

            var elementName = discriminatorConvention.ElementName;
            var serializationInfo = _serializationInfoHelper.GetSerializationInfo(typeBinaryExpression.Expression);
            if (serializationInfo.ElementName != null)
            {
                elementName = string.Format("{0}.{1}", serializationInfo.ElementName, elementName);
            }
            return Query.EQ(elementName, discriminator);
        }
Exemplo n.º 48
0
 internal override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, b.ToString()));
 }
 /// <summary>
 /// Visits a TypeBinaryExpression.
 /// </summary>
 /// <param name="b">The TypeBinaryExpression.</param>
 /// <returns>The TypeBinaryExpression (possibly modified).</returns>
 protected virtual Expression VisitTypeIs(TypeBinaryExpression b)
 {
     Expression expr = this.Visit(b.Expression);
     if (expr != b.Expression)
     {
         return Expression.TypeIs(expr, b.TypeOperand);
     }
     return b;
 }
Exemplo n.º 50
0
        private Expression VisitTypeIs(TypeBinaryExpression b)
        {
            var expr = Visit(b.Expression);

            return(expr != b.Expression ? Expression.TypeIs(expr, b.TypeOperand) : b);
        }