public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            g.BeginAssign(context.Member);
            {
                g.Load(context.DeserializationArgs);
                g.LoadMember("BinaryFormatter");
                g.BeginCall(typeof(BinaryFormatter).ResolveMethod("Deserialize", typeof(Stream)));
                {
                    g.Load(context.Reader);
                    g.LoadMember("BaseStream");
                }
                g.EndCall();
                if (context.Member.Type.IsValueType)
                {
                    g.UnboxAny(context.Member.Type);
                }
                else
                {
                    g.Cast(context.Member.Type);
                }
            }
            g.EndAssign();
        }
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            var key   = g.DeclareLocal(_keyType);
            var value = g.DeclareLocal(_valueType);

            g.BeginScope();
            {
                _keyBuilder.GenerateDeserializePart(context.CreateChild(g.CreateExpression(key)));
            }
            g.EndScope();

            g.BeginScope();
            {
                _valueBuilder.GenerateDeserializePart(context.CreateChild(g.CreateExpression(value)));
            }
            g.EndScope();

            g.BeginAssign(context.Member);
            {
                g.BeginNewObject(_ctor);
                {
                    g.Load(key);
                    g.Load(value);
                }
                g.EndNewObject();
            }
            g.EndAssign();
        }
示例#3
0
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g         = context.Generator;
            var primitive = g.CreateExpression(g.DeclareLocal(_targetType));

            _innerBuilder.GenerateDeserializePart(context.CreateChild(primitive));

            GenerateConvert(g, _fromPrimitiveMethod, primitive, context.Member);
        }
示例#4
0
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            g.Load(context.Instance);
            g.BeginCall(_readMethod);
            {
                g.Load(context.Reader);
            }
            g.EndCall();
        }
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            g.BeginAssign(context.Member);
            {
                g.Load(context.Reader);
                g.Call(MemberResolver.GetReadMethod(_readMethodName, Type));
            }
            g.EndAssign();
        }
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            g.BeginAssign(context.Member);
            {
                g.BeginCall(_deserializeMethod);
                {
                    g.Load(context.Reader);
                }
                g.EndCall();
            }
            g.EndAssign();
        }
示例#7
0
        void IPartBuilder.GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            var buffer = g.DeclareLocal(typeof(byte[]));

            g.BeginAssign(buffer);
            {
                g.BeginNewArray(typeof(byte));
                {
                    g.Load(_guidSize);
                }
                g.EndNewArray();
            }
            g.EndAssign();

            g.If(() =>
            {
                g.Load(context.Reader);
                g.LoadMember("BaseStream");
                g.BeginCall(typeof(Stream).GetMethod("Read", new[] { typeof(byte[]), typeof(int), typeof(int) }));
                {
                    g.Load(buffer);
                    g.Load(0);
                    g.Load(_guidSize);
                }
                g.EndCall();
                g.Load(_guidSize);
                return(BinaryOperator.LessThan);
            });
            {
                g.BeginNewObject(typeof(EndOfStreamException).GetConstructor(Type.EmptyTypes));
                g.EndNewObject();
                g.Throw();
            }
            g.EndIf();

            g.BeginAssign(context.Member);
            {
                g.BeginNewObject(typeof(Guid).GetConstructor(new[] { typeof(byte[]) }));
                {
                    g.Load(buffer);
                }
                g.EndNewObject();
            }
            g.EndAssign();
        }
        void IPartBuilder.GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            g.If(() =>
            {
                g.Load(context.Reader);
                g.Call(MemberResolver.GetReadMethod(typeof(bool)));
                return(BinaryOperator.IsTrue);
            });
            {
                var value = g.DeclareLocal(_innerType);
                g.BeginScope();
                {
                    var innerContext = context.CreateChild(g.CreateExpression(value));
                    _innerBuilder.GenerateDeserializePart(innerContext);
                }
                g.EndScope();

                g.BeginAssign(context.Member);
                {
                    g.BeginNewObject(_ctor);
                    {
                        g.Load(value);
                    }
                    g.EndNewObject();
                }
                g.EndAssign();
            }
            g.Else();
            {
                g.Load(context.Member, LoadOptions.ValueAsAddress);
                g.InitializeValue();
            }
            g.EndIf();
        }
示例#9
0
        void IPartBuilder.GenerateDeserializePart(GenDeserializeContext context)
        {
            var g     = context.Generator;
            var count = g.DeclareLocal(typeof(int));

            g.BeginAssign(count);
            {
                g.Load(context.Reader);
                g.Call(MemberResolver.GetReadMethod("ReadVarInt32", typeof(int)));
            }
            g.EndAssign();

            g.If(() =>
            {
                g.Load(count);
                g.Load(-1);
                return(BinaryOperator.AreEqual);
            });
            {
                g.BeginAssign(context.Member);
                {
                    g.LoadNull();
                }
                g.EndAssign();
            }
            g.Else();
            {
                g.BeginAssign(context.Member);
                {
                    g.BeginNewArray(_elementType);
                    {
                        g.Load(count);
                    }
                    g.EndNewArray();
                }
                g.EndAssign();

                var i = g.DeclareLocal(typeof(int));
                i.Initialize();

                g.While(() =>
                {
                    g.Load(i);
                    g.Load(count);
                    return(BinaryOperator.LessThan);
                },
                        () =>
                {
                    var element = g.DeclareLocal(_elementType);
                    g.BeginScope();
                    {
                        _elementBuilder.GenerateDeserializePart(context.CreateChild(g.CreateExpression(element)));
                    }
                    g.EndScope();

                    g.Load(context.Member);
                    g.BeginStoreElement();
                    {
                        g.Load(i);
                        g.Load(element);
                    }
                    g.EndStoreElement();

                    g.BeginAssign(i);
                    {
                        g.Load(i);
                        g.Increment();
                    }
                    g.EndAssign();
                });
            }
            g.EndIf();
        }
示例#10
0
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g = context.Generator;

            if (!context.Member.IsReadOnly)
            {
                context.Member.Initialize();
            }

            if (context.IsBaseType)
            {
                Debug.Assert(!_type.IsValueType, "Value types shouldn't be able to get here.");
                g.If(() =>
                {
                    g.Load(context.Member);
                    return(BinaryOperator.IsNull);
                });
                {
                    g.BeginNewObject(typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) }));
                    {
                        g.Load("Base type not initialized before attempting to deserialize.");
                    }
                    g.EndNewObject();
                    g.Throw();
                }
                g.EndIf();
                g.BeginCall(_readMethod);
                {
                    g.Load(context.Member, LoadOptions.Default);
                    g.Load(context.DeserializationArgs);
                    g.Load((int)_flags);
                }
                g.EndCall();
            }
            else
            {
                g.BeginScope();

                var member = context.Member.CanStore
                                        ? context.Member
                                        : g.DeclareLocal(context.Member.Type);

                member.Initialize();

                g.BeginCall(_readMethodByRef);
                {
                    g.Load(member, LoadOptions.AnyAsAddress);
                    g.Load(context.DeserializationArgs);
                    g.Load((int)_flags);
                }
                g.EndCall();

                if (context.Member != member)
                {
                    g.BeginAssign(context.Member);
                    {
                        g.Load(member);
                    }
                    g.EndAssign();
                }

                g.EndScope();
            }
        }
示例#11
0
        public void GenerateDeserializePart(GenDeserializeContext context)
        {
            var g          = context.Generator;
            var count      = g.DeclareLocal(typeof(int));
            var collection = context.Member.IsReadOnly
                                ? context.Member
                                : g.DeclareLocal(_collectionType);

            g.BeginAssign(count);
            {
                g.Load(context.Reader);
                g.Call(MemberResolver.GetReadMethod("ReadVarInt32", typeof(int)));
            }
            g.EndAssign();

            g.If(() =>
            {
                g.Load(count);
                g.Load(0);
                return(BinaryOperator.LessThan);
            });
            {
                if (context.Member.IsReadOnly)
                {
                    context.GenerateRaiseInvalidData(_collectionType);
                }
                else
                {
                    g.BeginAssign(collection);
                    {
                        g.LoadDefaultOf(_collectionType);
                    }
                    g.EndAssign();
                }
            }
            g.Else();
            {
                if (!context.Member.IsReadOnly)
                {
                    g.BeginAssign(collection);
                    g.BeginNewObject(_ctor);
                    {
                        if (_ctorType == CtorType.Capacity)
                        {
                            g.Load(count);
                        }
                    }
                    g.EndNewObject();
                    g.EndAssign();
                }

                g.While(() =>
                {
                    g.Load(count);
                    g.Load(0);
                    return(BinaryOperator.GreaterThan);
                },
                        () =>
                {
                    var element = g.DeclareLocal(_elementType);

                    g.BeginScope();
                    {
                        var innerContext = context.CreateChild(g.CreateExpression(element));
                        _innerBuilder.GenerateDeserializePart(innerContext);
                    }
                    g.EndScope();

                    g.Load(collection);
                    g.BeginCall(_add);
                    {
                        g.Load(element);
                    }
                    g.EndCall();

                    g.BeginAssign(count);
                    {
                        g.Load(count);
                        g.Decrement();
                    }
                    g.EndAssign();
                });
            }
            g.EndIf();

            if (!context.Member.IsReadOnly)
            {
                g.BeginAssign(context.Member);
                {
                    g.Load(collection);
                }
                g.EndAssign();
            }
        }
示例#12
0
 public void GenerateDeserializePart(GenDeserializeContext context)
 {
     _innerBuilder.GenerateDeserializePart(context.CreateChild(context.Member));
 }