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)); } }
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); }
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); }
/// <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)); }
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(); }
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(); }
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); }
/// <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); } }
/// <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); } }
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); }
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)); } }
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(); } }
internal SerializableUnaryExpression(UnaryExpression e, SerializableExpression.SerializationContext ctx, InterfaceType.Factory iftFactory) : base(e, ctx, iftFactory) { Children = new[] { SerializableExpression.FromExpression(e.Operand, ctx, iftFactory) }; }
/// <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())); }
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) }; }
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(); }
/// <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); }
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) }; }