Esempio 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
        }
 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));
     }
 }
 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;
 }
 /// <summary>
 /// Visits a TypeBinaryExpression.
 /// </summary>
 /// <param name="node">The TypeBinaryExpression.</param>
 /// <returns>The TypeBinaryExpression.</returns>
 protected override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     throw new NotImplementedException();
 }
 public TypeBinaryExpressionMutator(TypeBinaryExpression expression)
 {
     TypeBinaryExpression = expression;
 }
Esempio n. 7
0
 private static string VisitTypeBinary(TypeBinaryExpression node)
 {
     throw new NotImplementedException();
 }
Esempio n. 8
0
 protected TypeBinaryExpression UpdateTypeIs(TypeBinaryExpression binary, Expression expression, Type typeOperand)
 {
     if (expression != binary.Expression || typeOperand != binary.TypeOperand)
     {
         return Expression.TypeIs(expression, typeOperand);
     }
     return binary;
 }
Esempio n. 9
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 VisitTypeBinaryExpression(TypeBinaryExpression expression)
 {
     return expression;
 }
        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);
        }
Esempio n. 12
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);
 }
Esempio n. 13
0
 internal override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     throw new NotSupportedException(Strings.ALinq_ExpressionNotSupportedInProjectionToEntity(this.type, b.ToString()));
 }
 /// <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;
 }
Esempio n. 15
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");
        }
Esempio n. 16
0
 protected virtual bool CompareTypeIs(TypeBinaryExpression a, TypeBinaryExpression b)
 {
     return a.TypeOperand == b.TypeOperand
         && this.Compare(a.Expression, b.Expression);
 }
		protected virtual Expression VisitTypeIs (TypeBinaryExpression type)
		{
			Expression e = Visit (type.Expression);
			if (e != type.Expression)
				return Expression.TypeIs (e, type.TypeOperand);

			return type;
		}
 protected override Expression VisitTypeBinaryExpression(TypeBinaryExpression expression) => expression;
Esempio n. 19
0
 protected virtual Expression VisitTypeIs(TypeBinaryExpression binary)
 {
     Expression expr = this.Visit(binary.Expression);
     return this.UpdateTypeIs(binary, expr, binary.TypeOperand);
 }
Esempio n. 20
0
 protected virtual Expression VisitTypeIs(TypeBinaryExpression b)
 {
     Expression expr = Visit(b.Expression);
     return UpdateTypeIs(b, expr, b.TypeOperand);
 }
Esempio n. 21
0
 protected override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     this.Visit(b.Expression);
     this.Write(" is ");
     this.Write(this.GetTypeName(b.TypeOperand));
     return b;
 }
Esempio n. 22
0
 internal override Expression VisitTypeIs(TypeBinaryExpression b)
 {
     throw new NotSupportedException(Strings.ALinq_TypeBinaryNotSupported);
 }
 /// <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;
 }
 /// <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;
 }
 /// <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>
 /// 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);
 }
        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);
        }
		private HqlTreeNode VisitTypeBinaryExpression(TypeBinaryExpression expression)
		{
			return _hqlTreeBuilder.Equality(
				_hqlTreeBuilder.Dot(Visit(expression.Expression).AsExpression(), _hqlTreeBuilder.Class()),
				_hqlTreeBuilder.Ident(expression.TypeOperand.FullName));
		}
 /// <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;
 }
 /// <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;
 }