Esempio n. 1
0
        internal static SerializableMemberInfo FromStream(ZetboxStreamReader binReader)
        {
            var type = binReader.ReadByte();

            switch (type)
            {
            case 0:
                return(new SerializableMemberInfo()
                {
                    Name = binReader.ReadString(),
                    Type = binReader.ReadSerializableType(),
                });

            case 1:
                return(new SerializableConstructorInfo()
                {
                    Name = binReader.ReadString(),
                    Type = binReader.ReadSerializableType(),
                    ParameterTypes = SerializableExpression.ReadTypeArray(binReader)
                });

            default:
                throw new NotImplementedException(String.Format("unrecognized SerializableMemberInfoType [{0}]", type));
            }
        }
Esempio n. 2
0
 internal SerializableConditionalExpression(ZetboxStreamReader binReader, StreamSerializationContext ctx, InterfaceType.Factory iftFactory)
     : base(binReader, ctx, iftFactory)
 {
     Test    = SerializableExpression.FromStream(binReader, ctx, iftFactory);
     IfTrue  = SerializableExpression.FromStream(binReader, ctx, iftFactory);
     IfFalse = SerializableExpression.FromStream(binReader, ctx, iftFactory);
 }
Esempio n. 3
0
 internal SerializableConditionalExpression(ConditionalExpression source, SerializationContext ctx, InterfaceType.Factory iftFactory)
     : base(source, ctx, iftFactory)
 {
     Test    = SerializableExpression.FromExpression(source.Test, ctx, iftFactory);
     IfTrue  = SerializableExpression.FromExpression(source.IfTrue, ctx, iftFactory);
     IfFalse = SerializableExpression.FromExpression(source.IfFalse, ctx, iftFactory);
 }
Esempio n. 4
0
        /// <summary>
        /// Converts a SerializableExpression to a Linq Expression
        /// </summary>
        /// <returns>Linq Expression</returns>
        public static Expression ToExpression(SerializableExpression e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            SerializationContext ctx = new SerializationContext();

            return(e.ToExpressionInternal(ctx));
        }
Esempio n. 5
0
        internal SerializableCompoundExpression(ZetboxStreamReader binReader, StreamSerializationContext ctx, InterfaceType.Factory iftFactory)
            : base(binReader, ctx, iftFactory)
        {
            var children = new List <SerializableExpression>();

            while (binReader.ReadBoolean())
            {
                children.Add(SerializableExpression.FromStream(binReader, ctx, iftFactory));
            }
            this.Children = children.ToArray();
        }
Esempio n. 6
0
        internal SerializableNewExpression(NewExpression source, SerializationContext ctx, InterfaceType.Factory iftFactory)
            : base(source, ctx, iftFactory)
        {
            Constructor = new SerializableConstructorInfo(source.Constructor, iftFactory);
            if (source.Members != null)
            {
                Members = source.Members.Select(i => new SerializableMemberInfo(i, iftFactory)).ToArray();
            }

            Children = source.Arguments.Select(a => SerializableExpression.FromExpression(a, ctx, iftFactory)).ToArray();
        }
Esempio n. 7
0
        public override void ToStream(ZetboxStreamWriter binStream)
        {
            if (binStream == null)
            {
                throw new ArgumentNullException("binStream");
            }

            binStream.Write((byte)1);
            binStream.Write(Name);
            binStream.Write(Type);
            SerializableExpression.WriteTypeArray(binStream, ParameterTypes);
        }
Esempio n. 8
0
 /// <summary>
 /// Deserialize a Linq Expression Tree.
 /// </summary>
 /// <param name="iftFactory">InterfaceType.Factory to pass on the the read SerializableExpressions</param>
 public SerializableExpression ReadSerializableExpression(InterfaceType.Factory iftFactory)
 {
     TraceCurrentPos();
     if (_source.ReadBoolean())
     {
         return(SerializableExpression.FromStream(this, iftFactory));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Serialize a SerializableExpression
 /// </summary>
 /// <param name="e">SerializableExpression to serialize.</param>
 public void Write(SerializableExpression e)
 {
     TraceCurrentPos();
     if (e != null)
     {
         _dest.Write(true);
         e.ToStream(this);
     }
     else
     {
         _dest.Write(false);
     }
 }
Esempio n. 10
0
        internal SerializableMethodCallExpression(ZetboxStreamReader binReader, StreamSerializationContext ctx, InterfaceType.Factory iftFactory)
            : base(binReader, ctx, iftFactory)
        {
            var hasObject = binReader.ReadBoolean();

            if (hasObject)
            {
                ObjectExpression = SerializableExpression.FromStream(binReader, ctx, iftFactory);
            }

            MethodName             = binReader.ReadString();
            SerializableMethodType = binReader.ReadSerializableType();
            ParameterTypes         = ReadTypeArray(binReader);
            GenericArguments       = ReadTypeArray(binReader);
        }
Esempio n. 11
0
            public TResult Visit(SerializableExpression expr)
            {
                if (expr == null)
                {
                    return(VisitNull());
                }

                if (expr is SerializableBinaryExpression)
                {
                    return(VisitExpression((SerializableBinaryExpression)expr));
                }
                else if (expr is SerializableConditionalExpression)
                {
                    return(VisitExpression((SerializableConditionalExpression)expr));
                }
                else if (expr is SerializableConstantExpression)
                {
                    return(VisitExpression((SerializableConstantExpression)expr));
                }
                else if (expr is SerializableLambdaExpression)
                {
                    return(VisitExpression((SerializableLambdaExpression)expr));
                }
                else if (expr is SerializableMemberExpression)
                {
                    return(VisitExpression((SerializableMemberExpression)expr));
                }
                else if (expr is SerializableMethodCallExpression)
                {
                    return(VisitExpression((SerializableMethodCallExpression)expr));
                }
                else if (expr is SerializableNewExpression)
                {
                    return(VisitExpression((SerializableNewExpression)expr));
                }
                else if (expr is SerializableParameterExpression)
                {
                    return(VisitExpression((SerializableParameterExpression)expr));
                }
                else if (expr is SerializableUnaryExpression)
                {
                    return(VisitExpression((SerializableUnaryExpression)expr));
                }
                else
                {
                    return(VisitUnknown(expr));
                }
            }
Esempio n. 12
0
        internal SerializableMethodCallExpression(MethodCallExpression e, SerializationContext ctx, InterfaceType.Factory iftFactory)
            : base(e, ctx, iftFactory)
        {
            if (e.Object != null)
            {
                ObjectExpression = SerializableExpression.FromExpression(e.Object, ctx, iftFactory);
            }

            MethodName             = e.Method.Name;
            SerializableMethodType = iftFactory(e.Method.DeclaringType).ToSerializableType();
            ParameterTypes         = e.Method.GetParameters().Select(p => iftFactory(p.ParameterType).ToSerializableType()).ToArray();
            GenericArguments       = e.Method.GetGenericArguments().Select(p => iftFactory(p).ToSerializableType()).ToArray();

            if (e.Arguments != null)
            {
                Children = e.Arguments.Select(a => SerializableExpression.FromExpression(a, ctx, iftFactory)).ToArray();
            }
        }
Esempio n. 13
0
 internal SerializableUnaryExpression(UnaryExpression e, SerializableExpression.SerializationContext ctx, InterfaceType.Factory iftFactory)
     : base(e, ctx, iftFactory)
 {
     Children = new[] { SerializableExpression.FromExpression(e.Operand, ctx, iftFactory) };
 }
Esempio n. 14
0
 /// <summary>
 /// convert a unknown expression type. throws a NotImplementedException by default.
 /// </summary>
 protected virtual TResult VisitUnknown(SerializableExpression expr)
 {
     throw new NotSupportedException(string.Format("Type {0} is not supported: {1}", expr.GetType(), expr.ToString()));
 }
Esempio n. 15
0
 internal SerializableBinaryExpression(BinaryExpression e, SerializableExpression.SerializationContext ctx, InterfaceType.Factory iftFactory)
     : base(e, ctx, iftFactory)
 {
     Children = new[] { SerializableExpression.FromExpression(e.Left, ctx, iftFactory), SerializableExpression.FromExpression(e.Right, ctx, iftFactory) };
 }
Esempio n. 16
0
 internal SerializableLambdaExpression(LambdaExpression e, SerializationContext ctx, InterfaceType.Factory iftFactory)
     : base(e, ctx, iftFactory)
 {
     Children = new[] { SerializableExpression.FromExpression(e.Body, ctx, iftFactory) }
     .Union(e.Parameters.Select(p => SerializableExpression.FromExpression(p, ctx, iftFactory))).ToArray();
 }
Esempio n. 17
0
 /// <summary>
 /// Deserialize a Linq Expression Tree.
 /// </summary>
 /// <param name="e">Expression Tree.</param>
 /// <param name="iftFactory">InterfaceType.Factory to pass on the the read SerializableExpressions</param>
 public void Read(out SerializableExpression e, InterfaceType.Factory iftFactory)
 {
     e = ReadSerializableExpression(iftFactory);
 }
Esempio n. 18
0
 internal SerializableMemberExpression(MemberExpression e, SerializationContext ctx, InterfaceType.Factory iftFactory)
     : base(e, ctx, iftFactory)
 {
     MemberName = e.Member.Name;
     Children   = new[] { SerializableExpression.FromExpression(e.Expression, ctx, iftFactory) };
 }