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();
        }
예제 #2
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);
        }
예제 #3
0
        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();
        }
예제 #4
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();
        }
예제 #5
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();
            }
        }
예제 #6
0
 public void GenerateDeserializePart(GenDeserializeContext context)
 {
     _innerBuilder.GenerateDeserializePart(context.CreateChild(context.Member));
 }