Exemplo n.º 1
0
        protected override void EmitRead(CompilerContext ctx, Local valueFrom)
        {
            bool flag;

            SanityCheck(ctx.Model, this.property, base.Tail, out flag, ctx.NonPublic, ctx.AllowInternal(this.property));
            if (this.ExpectedType.IsValueType && (valueFrom == null))
            {
                throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
            }
            ctx.LoadAddress(valueFrom, this.ExpectedType);
            if (flag && base.Tail.RequiresOldValue)
            {
                ctx.CopyValue();
            }
            if (base.Tail.RequiresOldValue)
            {
                ctx.LoadValue(this.property);
            }
            Type propertyType = this.property.PropertyType;

            ctx.ReadNullCheckedTail(propertyType, base.Tail, null);
            if (flag)
            {
                CodeLabel label  = new CodeLabel();
                CodeLabel label2 = new CodeLabel();
                if (!propertyType.IsValueType)
                {
                    ctx.CopyValue();
                    label  = ctx.DefineLabel();
                    label2 = ctx.DefineLabel();
                    ctx.BranchIfFalse(label, true);
                }
                if (this.shadowSetter == null)
                {
                    ctx.StoreValue(this.property);
                }
                else
                {
                    ctx.EmitCall(this.shadowSetter);
                }
                if (!propertyType.IsValueType)
                {
                    ctx.Branch(label2, true);
                    ctx.MarkLabel(label);
                    ctx.DiscardValue();
                    ctx.DiscardValue();
                    ctx.MarkLabel(label2);
                }
            }
            else if (base.Tail.ReturnsValue)
            {
                ctx.DiscardValue();
            }
        }
Exemplo n.º 2
0
        void IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
        {
            bool copyValue = false;

            if (this.CanHaveInheritance)
            {
                for (int i = 0; i < this.serializers.Length; i++)
                {
                    IProtoSerializer serializer = this.serializers[i];
                    if ((serializer.ExpectedType != this.forType) && ((IProtoTypeSerializer)serializer).HasCallbacks(callbackType))
                    {
                        copyValue = true;
                    }
                }
            }
            MethodInfo method = (this.callbacks == null) ? null : this.callbacks[callbackType];

            if ((method != null) || copyValue)
            {
                ctx.LoadAddress(valueFrom, this.ExpectedType);
                EmitInvokeCallback(ctx, method, copyValue, null, this.forType);
                if (copyValue)
                {
                    CodeLabel label = ctx.DefineLabel();
                    for (int j = 0; j < this.serializers.Length; j++)
                    {
                        IProtoTypeSerializer serializer3;
                        IProtoSerializer     serializer2 = this.serializers[j];
                        Type expectedType = serializer2.ExpectedType;
                        if ((expectedType != this.forType) && (serializer3 = (IProtoTypeSerializer)serializer2).HasCallbacks(callbackType))
                        {
                            CodeLabel label2 = ctx.DefineLabel();
                            CodeLabel label3 = ctx.DefineLabel();
                            ctx.CopyValue();
                            ctx.TryCast(expectedType);
                            ctx.CopyValue();
                            ctx.BranchIfTrue(label2, true);
                            ctx.DiscardValue();
                            ctx.Branch(label3, false);
                            ctx.MarkLabel(label2);
                            serializer3.EmitCallback(ctx, null, callbackType);
                            ctx.Branch(label, false);
                            ctx.MarkLabel(label3);
                        }
                    }
                    ctx.MarkLabel(label);
                    ctx.DiscardValue();
                }
            }
        }
Exemplo n.º 3
0
 void IRuntimeProtoSerializerNode.EmitWrite(CompilerContext ctx, Local valueFrom)
 {
     // burn the value off the stack if needed
     if (valueFrom == null)
     {
         ctx.DiscardValue();
     }
 }
Exemplo n.º 4
0
        protected override void EmitRead(CompilerContext ctx, Local valueFrom)
        {
            bool flag;

            PropertyDecorator.SanityCheck(ctx.Model, this.property, this.Tail, out flag, ctx.NonPublic, ctx.AllowInternal(this.property));
            if (this.ExpectedType.IsValueType && valueFrom == null)
            {
                throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
            }
            using (Local localWithValue = ctx.GetLocalWithValue(this.ExpectedType, valueFrom))
            {
                if (this.Tail.RequiresOldValue)
                {
                    ctx.LoadAddress(localWithValue, this.ExpectedType);
                    ctx.LoadValue(this.property);
                }
                Type propertyType = this.property.PropertyType;
                ctx.ReadNullCheckedTail(propertyType, this.Tail, null);
                if (flag)
                {
                    using (Local local = new Local(ctx, this.property.PropertyType))
                    {
                        ctx.StoreValue(local);
                        CodeLabel codeLabel = new CodeLabel();
                        if (!propertyType.IsValueType)
                        {
                            codeLabel = ctx.DefineLabel();
                            ctx.LoadValue(local);
                            ctx.BranchIfFalse(codeLabel, true);
                        }
                        ctx.LoadAddress(localWithValue, this.ExpectedType);
                        ctx.LoadValue(local);
                        if (this.shadowSetter != null)
                        {
                            ctx.EmitCall(this.shadowSetter);
                        }
                        else
                        {
                            ctx.StoreValue(this.property);
                        }
                        if (!propertyType.IsValueType)
                        {
                            ctx.MarkLabel(codeLabel);
                        }
                    }
                }
                else if (this.Tail.ReturnsValue)
                {
                    ctx.DiscardValue();
                }
            }
        }
Exemplo n.º 5
0
 protected override void EmitRead(CompilerContext ctx, Local valueFrom)
 {
     using (Local local = ctx.GetLocalWithValue(this.ExpectedType, valueFrom))
     {
         ctx.LoadAddress(local, this.ExpectedType);
         if (base.Tail.RequiresOldValue)
         {
             ctx.CopyValue();
             ctx.LoadValue(this.field);
         }
         ctx.ReadNullCheckedTail(this.field.FieldType, base.Tail, null);
         if (base.Tail.ReturnsValue)
         {
             if (this.field.FieldType.IsValueType)
             {
                 ctx.StoreValue(this.field);
             }
             else
             {
                 CodeLabel label  = ctx.DefineLabel();
                 CodeLabel label2 = ctx.DefineLabel();
                 ctx.CopyValue();
                 ctx.BranchIfTrue(label, true);
                 ctx.DiscardValue();
                 ctx.DiscardValue();
                 ctx.Branch(label2, true);
                 ctx.MarkLabel(label);
                 ctx.StoreValue(this.field);
                 ctx.MarkLabel(label2);
             }
         }
         else
         {
             ctx.DiscardValue();
         }
     }
 }
Exemplo n.º 6
0
        protected override void EmitRead(CompilerContext ctx, Local valueFrom)
        {
            base.Tail.EmitRead(ctx, valueFrom);
            ctx.CopyValue();
            CodeLabel label  = ctx.DefineLabel();
            CodeLabel label2 = ctx.DefineLabel();

            ctx.LoadValue(typeof(string).GetProperty("Length"));
            ctx.BranchIfTrue(label, true);
            ctx.DiscardValue();
            ctx.LoadNullRef();
            ctx.Branch(label2, true);
            ctx.MarkLabel(label);
            ctx.EmitCtor(ctx.MapType(typeof(Uri)), new Type[] { ctx.MapType(typeof(string)) });
            ctx.MarkLabel(label2);
        }
Exemplo n.º 7
0
        protected override void EmitRead(CompilerContext ctx, Local valueFrom)
        {
            this.Tail.EmitRead(ctx, valueFrom);
            ctx.CopyValue();
            CodeLabel codeLabel  = ctx.DefineLabel();
            CodeLabel codeLabel1 = ctx.DefineLabel();

            ctx.LoadValue(typeof(string).GetProperty("Length"));
            ctx.BranchIfTrue(codeLabel, true);
            ctx.DiscardValue();
            ctx.LoadNullRef();
            ctx.Branch(codeLabel1, true);
            ctx.MarkLabel(codeLabel);
            Type type = ctx.MapType(typeof(Uri));

            Type[] typeArray = new Type[] { ctx.MapType(typeof(string)) };
            ctx.EmitCtor(type, typeArray);
            ctx.MarkLabel(codeLabel1);
        }
Exemplo n.º 8
0
        protected override void EmitWrite(CompilerContext ctx, Local valueFrom)
        {
            CodeLabel label = ctx.DefineLabel();

            if (valueFrom == null)
            {
                ctx.CopyValue();
                CodeLabel label2 = ctx.DefineLabel();
                this.EmitBranchIfDefaultValue(ctx, label2);
                base.Tail.EmitWrite(ctx, null);
                ctx.Branch(label, true);
                ctx.MarkLabel(label2);
                ctx.DiscardValue();
            }
            else
            {
                ctx.LoadValue(valueFrom);
                this.EmitBranchIfDefaultValue(ctx, label);
                base.Tail.EmitWrite(ctx, valueFrom);
            }
            ctx.MarkLabel(label);
        }
Exemplo n.º 9
0
        private static void EmitReadAndAddItem(CompilerContext ctx, Local list, IProtoSerializer tail, MethodInfo add, bool castListForAdd)
        {
            ctx.LoadAddress(list, list.Type);
            if (castListForAdd)
            {
                ctx.Cast(add.DeclaringType);
            }
            Type expectedType = tail.ExpectedType;
            bool returnsValue = tail.ReturnsValue;

            if (!tail.RequiresOldValue)
            {
                if (!returnsValue)
                {
                    throw new InvalidOperationException();
                }
                tail.EmitRead(ctx, null);
            }
            else if (expectedType.IsValueType || !returnsValue)
            {
                using (Local local = new Local(ctx, expectedType))
                {
                    if (!expectedType.IsValueType)
                    {
                        ctx.LoadNullRef();
                        ctx.StoreValue(local);
                    }
                    else
                    {
                        ctx.LoadAddress(local, expectedType);
                        ctx.EmitCtor(expectedType);
                    }
                    tail.EmitRead(ctx, local);
                    if (!returnsValue)
                    {
                        ctx.LoadValue(local);
                    }
                }
            }
            else
            {
                ctx.LoadNullRef();
                tail.EmitRead(ctx, null);
            }
            Type parameterType = add.GetParameters()[0].ParameterType;

            if (parameterType != expectedType)
            {
                if (parameterType != ctx.MapType(typeof(object)))
                {
                    if (Helpers.GetUnderlyingType(parameterType) != expectedType)
                    {
                        throw new InvalidOperationException("Conflicting item/add type");
                    }
                    Type[] typeArray = new Type[] { expectedType };
                    ctx.EmitCtor(Helpers.GetConstructor(parameterType, typeArray, false));
                }
                else
                {
                    ctx.CastToObject(expectedType);
                }
            }
            ctx.EmitCall(add);
            if (add.ReturnType != ctx.MapType(typeof(void)))
            {
                ctx.DiscardValue();
            }
        }
Exemplo n.º 10
0
        public void EmitRead(CompilerContext ctx, Local incoming)
        {
            using (Local local = ctx.GetLocalWithValue(this.ExpectedType, incoming))
            {
                Local[] localArray = new Local[this.members.Length];
                try
                {
                    for (int i = 0; i < localArray.Length; i++)
                    {
                        Type memberType = this.GetMemberType(i);
                        bool flag       = true;
                        localArray[i] = new Local(ctx, memberType);
                        if (this.ExpectedType.IsValueType)
                        {
                            continue;
                        }
                        if (memberType.IsValueType)
                        {
                            switch (Helpers.GetTypeCode(memberType))
                            {
                            case ProtoTypeCode.Boolean:
                            case ProtoTypeCode.SByte:
                            case ProtoTypeCode.Byte:
                            case ProtoTypeCode.Int16:
                            case ProtoTypeCode.UInt16:
                            case ProtoTypeCode.Int32:
                            case ProtoTypeCode.UInt32:
                                ctx.LoadValue(0);
                                goto Label_0108;

                            case ProtoTypeCode.Int64:
                            case ProtoTypeCode.UInt64:
                                ctx.LoadValue((long)0L);
                                goto Label_0108;

                            case ProtoTypeCode.Single:
                                ctx.LoadValue((float)0f);
                                goto Label_0108;

                            case ProtoTypeCode.Double:
                                ctx.LoadValue((double)0.0);
                                goto Label_0108;

                            case ProtoTypeCode.Decimal:
                                ctx.LoadValue((decimal)0M);
                                goto Label_0108;

                            case ProtoTypeCode.Guid:
                                ctx.LoadValue(Guid.Empty);
                                goto Label_0108;
                            }
                            ctx.LoadAddress(localArray[i], memberType);
                            ctx.EmitCtor(memberType);
                            flag = false;
                        }
                        else
                        {
                            ctx.LoadNullRef();
                        }
Label_0108:
                        if (flag)
                        {
                            ctx.StoreValue(localArray[i]);
                        }
                    }
                    CodeLabel label = this.ExpectedType.IsValueType ? new CodeLabel() : ctx.DefineLabel();
                    if (!this.ExpectedType.IsValueType)
                    {
                        ctx.LoadAddress(local, this.ExpectedType);
                        ctx.BranchIfFalse(label, false);
                    }
                    for (int j = 0; j < this.members.Length; j++)
                    {
                        ctx.LoadAddress(local, this.ExpectedType);
                        switch (this.members[j].MemberType)
                        {
                        case MemberTypes.Field:
                            ctx.LoadValue((FieldInfo)this.members[j]);
                            break;

                        case MemberTypes.Property:
                            ctx.LoadValue((PropertyInfo)this.members[j]);
                            break;
                        }
                        ctx.StoreValue(localArray[j]);
                    }
                    if (!this.ExpectedType.IsValueType)
                    {
                        ctx.MarkLabel(label);
                    }
                    using (Local local2 = new Local(ctx, ctx.MapType(typeof(int))))
                    {
                        CodeLabel label2 = ctx.DefineLabel();
                        CodeLabel label3 = ctx.DefineLabel();
                        CodeLabel label4 = ctx.DefineLabel();
                        ctx.Branch(label2, false);
                        CodeLabel[] jumpTable = new CodeLabel[this.members.Length];
                        for (int m = 0; m < this.members.Length; m++)
                        {
                            jumpTable[m] = ctx.DefineLabel();
                        }
                        ctx.MarkLabel(label3);
                        ctx.LoadValue(local2);
                        ctx.LoadValue(1);
                        ctx.Subtract();
                        ctx.Switch(jumpTable);
                        ctx.Branch(label4, false);
                        for (int n = 0; n < jumpTable.Length; n++)
                        {
                            ctx.MarkLabel(jumpTable[n]);
                            IProtoSerializer tail      = this.tails[n];
                            Local            valueFrom = tail.RequiresOldValue ? localArray[n] : null;
                            ctx.ReadNullCheckedTail(localArray[n].Type, tail, valueFrom);
                            if (tail.ReturnsValue)
                            {
                                if (localArray[n].Type.IsValueType)
                                {
                                    ctx.StoreValue(localArray[n]);
                                }
                                else
                                {
                                    CodeLabel label5 = ctx.DefineLabel();
                                    CodeLabel label6 = ctx.DefineLabel();
                                    ctx.CopyValue();
                                    ctx.BranchIfTrue(label5, true);
                                    ctx.DiscardValue();
                                    ctx.Branch(label6, true);
                                    ctx.MarkLabel(label5);
                                    ctx.StoreValue(localArray[n]);
                                    ctx.MarkLabel(label6);
                                }
                            }
                            ctx.Branch(label2, false);
                        }
                        ctx.MarkLabel(label4);
                        ctx.LoadReaderWriter();
                        ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
                        ctx.MarkLabel(label2);
                        ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
                        ctx.CopyValue();
                        ctx.StoreValue(local2);
                        ctx.LoadValue(0);
                        ctx.BranchIfGreater(label3, false);
                    }
                    for (int k = 0; k < localArray.Length; k++)
                    {
                        ctx.LoadValue(localArray[k]);
                    }
                    ctx.EmitCtor(this.ctor);
                    ctx.StoreValue(local);
                }
                finally
                {
                    for (int num6 = 0; num6 < localArray.Length; num6++)
                    {
                        if (localArray[num6] != null)
                        {
                            localArray[num6].Dispose();
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
        {
            Type expectedType = this.ExpectedType;

            using (Local local = ctx.GetLocalWithValue(expectedType, valueFrom))
            {
                this.EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.BeforeSerialize);
                CodeLabel label = ctx.DefineLabel();
                if (!this.CanHaveInheritance)
                {
                    goto Label_0206;
                }
                for (int i = 0; i < this.serializers.Length; i++)
                {
                    IProtoSerializer serializer = this.serializers[i];
                    Type             type       = serializer.ExpectedType;
                    if (type != this.forType)
                    {
                        CodeLabel label2 = ctx.DefineLabel();
                        CodeLabel label3 = ctx.DefineLabel();
                        ctx.LoadValue(local);
                        ctx.TryCast(type);
                        ctx.CopyValue();
                        ctx.BranchIfTrue(label2, true);
                        ctx.DiscardValue();
                        ctx.Branch(label3, true);
                        ctx.MarkLabel(label2);
                        serializer.EmitWrite(ctx, null);
                        ctx.Branch(label, false);
                        ctx.MarkLabel(label3);
                    }
                }
                if ((this.constructType != null) && (this.constructType != this.forType))
                {
                    using (Local local2 = new Local(ctx, ctx.MapType(typeof(Type))))
                    {
                        ctx.LoadValue(local);
                        ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
                        ctx.CopyValue();
                        ctx.StoreValue(local2);
                        ctx.LoadValue(this.forType);
                        ctx.BranchIfEqual(label, true);
                        ctx.LoadValue(local2);
                        ctx.LoadValue(this.constructType);
                        ctx.BranchIfEqual(label, true);
                        goto Label_01B1;
                    }
                }
                ctx.LoadValue(local);
                ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
                ctx.LoadValue(this.forType);
                ctx.BranchIfEqual(label, true);
Label_01B1:
                ctx.LoadValue(this.forType);
                ctx.LoadValue(local);
                ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
                ctx.EmitCall(ctx.MapType(typeof(TypeModel)).GetMethod("ThrowUnexpectedSubtype", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static));
Label_0206:
                ctx.MarkLabel(label);
                for (int j = 0; j < this.serializers.Length; j++)
                {
                    IProtoSerializer serializer2 = this.serializers[j];
                    if (serializer2.ExpectedType == this.forType)
                    {
                        serializer2.EmitWrite(ctx, local);
                    }
                }
                if (this.isExtensible)
                {
                    ctx.LoadValue(local);
                    ctx.LoadReaderWriter();
                    ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("AppendExtensionData"));
                }
                this.EmitCallbackIfNeeded(ctx, local, TypeModel.CallbackType.AfterSerialize);
            }
        }
Exemplo n.º 12
0
        void ProtoBuf.Serializers.IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType)
        {
            MethodInfo item;
            bool       flag = false;

            if (this.CanHaveInheritance)
            {
                for (int i = 0; i < (int)this.serializers.Length; i++)
                {
                    IProtoSerializer protoSerializer = this.serializers[i];
                    if (protoSerializer.ExpectedType != this.forType && ((IProtoTypeSerializer)protoSerializer).HasCallbacks(callbackType))
                    {
                        flag = true;
                    }
                }
            }
            if (this.callbacks == null)
            {
                item = null;
            }
            else
            {
                item = this.callbacks[callbackType];
            }
            MethodInfo methodInfo = item;

            if (methodInfo == null && !flag)
            {
                return;
            }
            ctx.LoadAddress(valueFrom, this.ExpectedType);
            TypeSerializer.EmitInvokeCallback(ctx, methodInfo, flag, null, this.forType);
            if (flag)
            {
                CodeLabel codeLabel = ctx.DefineLabel();
                for (int j = 0; j < (int)this.serializers.Length; j++)
                {
                    IProtoSerializer protoSerializer1 = this.serializers[j];
                    Type             expectedType     = protoSerializer1.ExpectedType;
                    if (expectedType != this.forType)
                    {
                        IProtoTypeSerializer protoTypeSerializer  = (IProtoTypeSerializer)protoSerializer1;
                        IProtoTypeSerializer protoTypeSerializer1 = protoTypeSerializer;
                        if (protoTypeSerializer.HasCallbacks(callbackType))
                        {
                            CodeLabel codeLabel1 = ctx.DefineLabel();
                            CodeLabel codeLabel2 = ctx.DefineLabel();
                            ctx.CopyValue();
                            ctx.TryCast(expectedType);
                            ctx.CopyValue();
                            ctx.BranchIfTrue(codeLabel1, true);
                            ctx.DiscardValue();
                            ctx.Branch(codeLabel2, false);
                            ctx.MarkLabel(codeLabel1);
                            protoTypeSerializer1.EmitCallback(ctx, null, callbackType);
                            ctx.Branch(codeLabel, false);
                            ctx.MarkLabel(codeLabel2);
                        }
                    }
                }
                ctx.MarkLabel(codeLabel);
                ctx.DiscardValue();
            }
        }
Exemplo n.º 13
0
 void ProtoBuf.Serializers.IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
 {
     using (Local localWithValue = ctx.GetLocalWithValue(this.ExpectedType, valueFrom))
     {
         this.EmitCallbackIfNeeded(ctx, localWithValue, TypeModel.CallbackType.BeforeSerialize);
         CodeLabel codeLabel = ctx.DefineLabel();
         if (this.CanHaveInheritance)
         {
             for (int i = 0; i < (int)this.serializers.Length; i++)
             {
                 IProtoSerializer protoSerializer = this.serializers[i];
                 Type             expectedType    = protoSerializer.ExpectedType;
                 if (expectedType != this.forType)
                 {
                     CodeLabel codeLabel1 = ctx.DefineLabel();
                     CodeLabel codeLabel2 = ctx.DefineLabel();
                     ctx.LoadValue(localWithValue);
                     ctx.TryCast(expectedType);
                     ctx.CopyValue();
                     ctx.BranchIfTrue(codeLabel1, true);
                     ctx.DiscardValue();
                     ctx.Branch(codeLabel2, true);
                     ctx.MarkLabel(codeLabel1);
                     protoSerializer.EmitWrite(ctx, null);
                     ctx.Branch(codeLabel, false);
                     ctx.MarkLabel(codeLabel2);
                 }
             }
             if (this.constructType == null || this.constructType == this.forType)
             {
                 ctx.LoadValue(localWithValue);
                 ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
                 ctx.LoadValue(this.forType);
                 ctx.BranchIfEqual(codeLabel, true);
             }
             else
             {
                 using (Local local = new Local(ctx, ctx.MapType(typeof(Type))))
                 {
                     ctx.LoadValue(localWithValue);
                     ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
                     ctx.CopyValue();
                     ctx.StoreValue(local);
                     ctx.LoadValue(this.forType);
                     ctx.BranchIfEqual(codeLabel, true);
                     ctx.LoadValue(local);
                     ctx.LoadValue(this.constructType);
                     ctx.BranchIfEqual(codeLabel, true);
                 }
             }
             ctx.LoadValue(this.forType);
             ctx.LoadValue(localWithValue);
             ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("GetType"));
             ctx.EmitCall(ctx.MapType(typeof(TypeModel)).GetMethod("ThrowUnexpectedSubtype", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
         }
         ctx.MarkLabel(codeLabel);
         for (int j = 0; j < (int)this.serializers.Length; j++)
         {
             IProtoSerializer protoSerializer1 = this.serializers[j];
             if (protoSerializer1.ExpectedType == this.forType)
             {
                 protoSerializer1.EmitWrite(ctx, localWithValue);
             }
         }
         if (this.isExtensible)
         {
             ctx.LoadValue(localWithValue);
             ctx.LoadReaderWriter();
             ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("AppendExtensionData"));
         }
         this.EmitCallbackIfNeeded(ctx, localWithValue, TypeModel.CallbackType.AfterSerialize);
     }
 }
        protected override void EmitRead(CompilerContext ctx, Local valueFrom)
        {
            MethodInfo methodInfo;
            MethodInfo methodInfo1;
            Local      localWithValue;

            if (base.AppendToCollection)
            {
                localWithValue = ctx.GetLocalWithValue(this.ExpectedType, valueFrom);
            }
            else
            {
                localWithValue = null;
            }
            using (Local local = localWithValue)
            {
                using (Local local1 = new Local(ctx, this.builderFactory.ReturnType))
                {
                    ctx.EmitCall(this.builderFactory);
                    ctx.StoreValue(local1);
                    if (base.AppendToCollection)
                    {
                        CodeLabel codeLabel = ctx.DefineLabel();
                        if (!this.ExpectedType.IsValueType)
                        {
                            ctx.LoadValue(local);
                            ctx.BranchIfFalse(codeLabel, false);
                        }
                        PropertyInfo property = Helpers.GetProperty(this.ExpectedType, "Length", false) ?? Helpers.GetProperty(this.ExpectedType, "Count", false) ?? Helpers.GetProperty(ImmutableCollectionDecorator.ResolveIReadOnlyCollection(this.ExpectedType, this.Tail.ExpectedType), "Count", false);
                        ctx.LoadAddress(local, local.Type);
                        ctx.EmitCall(Helpers.GetGetMethod(property, false, false));
                        ctx.BranchIfFalse(codeLabel, false);
                        Type type = ctx.MapType(typeof(void));
                        if (this.addRange == null)
                        {
                            MethodInfo enumeratorInfo = base.GetEnumeratorInfo(ctx.Model, out methodInfo, out methodInfo1);
                            Type       returnType     = enumeratorInfo.ReturnType;
                            using (Local local2 = new Local(ctx, returnType))
                            {
                                ctx.LoadAddress(local, this.ExpectedType);
                                ctx.EmitCall(enumeratorInfo);
                                ctx.StoreValue(local2);
                                using (IDisposable disposable = ctx.Using(local2))
                                {
                                    CodeLabel codeLabel1 = ctx.DefineLabel();
                                    CodeLabel codeLabel2 = ctx.DefineLabel();
                                    ctx.Branch(codeLabel2, false);
                                    ctx.MarkLabel(codeLabel1);
                                    ctx.LoadAddress(local1, local1.Type);
                                    ctx.LoadAddress(local2, returnType);
                                    ctx.EmitCall(methodInfo1);
                                    ctx.EmitCall(this.@add);
                                    if ([email protected] != null && [email protected] != type)
                                    {
                                        ctx.DiscardValue();
                                    }
                                    ctx.MarkLabel(codeLabel2);
                                    ctx.LoadAddress(local2, returnType);
                                    ctx.EmitCall(methodInfo);
                                    ctx.BranchIfTrue(codeLabel1, false);
                                }
                            }
                        }
                        else
                        {
                            ctx.LoadValue(local1);
                            ctx.LoadValue(local);
                            ctx.EmitCall(this.addRange);
                            if (this.addRange.ReturnType != null && [email protected] != type)
                            {
                                ctx.DiscardValue();
                            }
                        }
                        ctx.MarkLabel(codeLabel);
                    }
                    ListDecorator.EmitReadList(ctx, local1, this.Tail, this.@add, this.packedWireType, false);
                    ctx.LoadAddress(local1, local1.Type);
                    ctx.EmitCall(this.finish);
                    if (this.ExpectedType != this.finish.ReturnType)
                    {
                        ctx.Cast(this.ExpectedType);
                    }
                }
            }
        }
        public void EmitRead(CompilerContext ctx, Local incoming)
        {
            Local local;

            using (Local localWithValue = ctx.GetLocalWithValue(this.ExpectedType, incoming))
            {
                Local[] localArray = new Local[(int)this.members.Length];
                try
                {
                    for (int i = 0; i < (int)localArray.Length; i++)
                    {
                        Type memberType = this.GetMemberType(i);
                        bool flag       = true;
                        localArray[i] = new Local(ctx, memberType);
                        if (!this.ExpectedType.IsValueType)
                        {
                            if (!memberType.IsValueType)
                            {
                                ctx.LoadNullRef();
                            }
                            else
                            {
                                ProtoTypeCode typeCode = Helpers.GetTypeCode(memberType);
                                switch (typeCode)
                                {
                                case ProtoTypeCode.Boolean:
                                case ProtoTypeCode.SByte:
                                case ProtoTypeCode.Byte:
                                case ProtoTypeCode.Int16:
                                case ProtoTypeCode.UInt16:
                                case ProtoTypeCode.Int32:
                                case ProtoTypeCode.UInt32:
                                {
                                    ctx.LoadValue(0);
                                    break;
                                }

                                case ProtoTypeCode.Char:
                                {
                                    ctx.LoadAddress(localArray[i], memberType);
                                    ctx.EmitCtor(memberType);
                                    flag = false;
                                    break;
                                }

                                case ProtoTypeCode.Int64:
                                case ProtoTypeCode.UInt64:
                                {
                                    ctx.LoadValue((long)0);
                                    break;
                                }

                                case ProtoTypeCode.Single:
                                {
                                    ctx.LoadValue(0f);
                                    break;
                                }

                                case ProtoTypeCode.Double:
                                {
                                    ctx.LoadValue(0);
                                    break;
                                }

                                case ProtoTypeCode.Decimal:
                                {
                                    ctx.LoadValue(new decimal(0));
                                    break;
                                }

                                default:
                                {
                                    if (typeCode == ProtoTypeCode.Guid)
                                    {
                                        ctx.LoadValue(Guid.Empty);
                                        break;
                                    }
                                    else
                                    {
                                        goto case ProtoTypeCode.Char;
                                    }
                                }
                                }
                            }
                            if (flag)
                            {
                                ctx.StoreValue(localArray[i]);
                            }
                        }
                    }
                    CodeLabel codeLabel = (this.ExpectedType.IsValueType ? new CodeLabel() : ctx.DefineLabel());
                    if (!this.ExpectedType.IsValueType)
                    {
                        ctx.LoadAddress(localWithValue, this.ExpectedType);
                        ctx.BranchIfFalse(codeLabel, false);
                    }
                    for (int j = 0; j < (int)this.members.Length; j++)
                    {
                        ctx.LoadAddress(localWithValue, this.ExpectedType);
                        MemberTypes memberType1 = this.members[j].MemberType;
                        if (memberType1 == MemberTypes.Field)
                        {
                            ctx.LoadValue((FieldInfo)this.members[j]);
                        }
                        else if (memberType1 == MemberTypes.Property)
                        {
                            ctx.LoadValue((PropertyInfo)this.members[j]);
                        }
                        ctx.StoreValue(localArray[j]);
                    }
                    if (!this.ExpectedType.IsValueType)
                    {
                        ctx.MarkLabel(codeLabel);
                    }
                    using (Local local1 = new Local(ctx, ctx.MapType(typeof(int))))
                    {
                        CodeLabel codeLabel1 = ctx.DefineLabel();
                        CodeLabel codeLabel2 = ctx.DefineLabel();
                        CodeLabel codeLabel3 = ctx.DefineLabel();
                        ctx.Branch(codeLabel1, false);
                        CodeLabel[] codeLabelArray = new CodeLabel[(int)this.members.Length];
                        for (int k = 0; k < (int)this.members.Length; k++)
                        {
                            codeLabelArray[k] = ctx.DefineLabel();
                        }
                        ctx.MarkLabel(codeLabel2);
                        ctx.LoadValue(local1);
                        ctx.LoadValue(1);
                        ctx.Subtract();
                        ctx.Switch(codeLabelArray);
                        ctx.Branch(codeLabel3, false);
                        for (int l = 0; l < (int)codeLabelArray.Length; l++)
                        {
                            ctx.MarkLabel(codeLabelArray[l]);
                            IProtoSerializer protoSerializer = this.tails[l];
                            if (protoSerializer.RequiresOldValue)
                            {
                                local = localArray[l];
                            }
                            else
                            {
                                local = null;
                            }
                            ctx.ReadNullCheckedTail(localArray[l].Type, protoSerializer, local);
                            if (protoSerializer.ReturnsValue)
                            {
                                if (!localArray[l].Type.IsValueType)
                                {
                                    CodeLabel codeLabel4 = ctx.DefineLabel();
                                    CodeLabel codeLabel5 = ctx.DefineLabel();
                                    ctx.CopyValue();
                                    ctx.BranchIfTrue(codeLabel4, true);
                                    ctx.DiscardValue();
                                    ctx.Branch(codeLabel5, true);
                                    ctx.MarkLabel(codeLabel4);
                                    ctx.StoreValue(localArray[l]);
                                    ctx.MarkLabel(codeLabel5);
                                }
                                else
                                {
                                    ctx.StoreValue(localArray[l]);
                                }
                            }
                            ctx.Branch(codeLabel1, false);
                        }
                        ctx.MarkLabel(codeLabel3);
                        ctx.LoadReaderWriter();
                        ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
                        ctx.MarkLabel(codeLabel1);
                        ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
                        ctx.CopyValue();
                        ctx.StoreValue(local1);
                        ctx.LoadValue(0);
                        ctx.BranchIfGreater(codeLabel2, false);
                    }
                    for (int m = 0; m < (int)localArray.Length; m++)
                    {
                        ctx.LoadValue(localArray[m]);
                    }
                    ctx.EmitCtor(this.ctor);
                    ctx.StoreValue(localWithValue);
                }
                finally
                {
                    for (int n = 0; n < (int)localArray.Length; n++)
                    {
                        if (localArray[n] != null)
                        {
                            localArray[n].Dispose();
                        }
                    }
                }
            }
        }