int ReadMembers(int index, ClassDataContract classContract, BitFlagsGenerator expectedElements, ref int memberIndex)
        {
            int memberCount = (classContract.BaseContract == null) ? 0 : ReadMembers(index, classContract.BaseContract, expectedElements,
                                                                                     ref memberIndex);

            if (memberCount <= index && index < memberCount + classContract.Members.Count)
            {
                DataMember dataMember = classContract.Members [index - memberCount];
                Type       memberType = dataMember.MemberType;

                memberIndex = memberCount;
                if (!expectedElements.Load(index))
                {
                    XmlObjectSerializerReadContextComplexJson.ThrowDuplicateMemberException(objectLocal, memberNames, memberIndex);
                }

                if (dataMember.IsGetOnlyCollection)
                {
                    var value = CodeInterpreter.GetMember(dataMember.MemberInfo, objectLocal);
                    context.StoreCollectionMemberInfo(value);
                    ReadValue(memberType, dataMember.Name);
                }
                else
                {
                    var value = ReadValue(memberType, dataMember.Name);
                    CodeInterpreter.SetMember(dataMember.MemberInfo, objectLocal, value);
                }
                memberIndex = index;
                ResetExpectedElements(expectedElements, index);
            }
            return(memberCount + classContract.Members.Count);
        }
Exemplo n.º 2
0
            private int ReadMembers(ClassDataContract classContract, BitFlagsGenerator expectedElements,
                                    Label[] memberLabels, Label throwDuplicateMemberLabel, LocalBuilder memberIndexLocal)
            {
                int memberCount = (classContract.BaseContract == null) ? 0 :
                                  ReadMembers(classContract.BaseContract, expectedElements, memberLabels, throwDuplicateMemberLabel, memberIndexLocal);

                for (int i = 0; i < classContract.Members.Count; i++, memberCount++)
                {
                    DataMember dataMember = classContract.Members[i];
                    Type       memberType = dataMember.MemberType;
                    _ilg.Case(memberLabels[memberCount], dataMember.Name);
                    _ilg.Set(memberIndexLocal, memberCount);
                    expectedElements.Load(memberCount);
                    _ilg.Brfalse(throwDuplicateMemberLabel);
                    LocalBuilder value = null;
                    if (dataMember.IsGetOnlyCollection)
                    {
                        _ilg.LoadAddress(_objectLocal);
                        _ilg.LoadMember(dataMember.MemberInfo);
                        value = _ilg.DeclareLocal(memberType, dataMember.Name + "Value");
                        _ilg.Stloc(value);
                        _ilg.Call(_contextArg, XmlFormatGeneratorStatics.StoreCollectionMemberInfoMethod, value);
                        ReadValue(memberType, dataMember.Name);
                    }
                    else
                    {
                        _ilg.Call(_contextArg, XmlFormatGeneratorStatics.ResetCollectionMemberInfoMethod);
                        value = ReadValue(memberType, dataMember.Name);
                        _ilg.LoadAddress(_objectLocal);
                        _ilg.ConvertAddress(_objectLocal.LocalType, _objectType);
                        _ilg.Ldloc(value);
                        _ilg.StoreMember(dataMember.MemberInfo);
                    }
                    ResetExpectedElements(expectedElements, memberCount);
                    _ilg.EndCase();
                }
                return(memberCount);
            }
            private int ReadMembers(ClassDataContract classContract, BitFlagsGenerator expectedElements, Label[] memberLabels, Label throwDuplicateMemberLabel, LocalBuilder memberIndexLocal)
            {
                int index = (classContract.BaseContract == null) ? 0 : this.ReadMembers(classContract.BaseContract, expectedElements, memberLabels, throwDuplicateMemberLabel, memberIndexLocal);
                int num2  = 0;

                while (num2 < classContract.Members.Count)
                {
                    DataMember member     = classContract.Members[num2];
                    Type       memberType = member.MemberType;
                    this.ilg.Case(memberLabels[index], member.Name);
                    this.ilg.Set(memberIndexLocal, index);
                    expectedElements.Load(index);
                    this.ilg.Brfalse(throwDuplicateMemberLabel);
                    LocalBuilder local = null;
                    if (member.IsGetOnlyCollection)
                    {
                        this.ilg.LoadAddress(this.objectLocal);
                        this.ilg.LoadMember(member.MemberInfo);
                        local = this.ilg.DeclareLocal(memberType, member.Name + "Value");
                        this.ilg.Stloc(local);
                        this.ilg.Call(this.contextArg, XmlFormatGeneratorStatics.StoreCollectionMemberInfoMethod, local);
                        this.ReadValue(memberType, member.Name);
                    }
                    else
                    {
                        local = this.ReadValue(memberType, member.Name);
                        this.ilg.LoadAddress(this.objectLocal);
                        this.ilg.ConvertAddress(this.objectLocal.LocalType, this.objectType);
                        this.ilg.Ldloc(local);
                        this.ilg.StoreMember(member.MemberInfo);
                    }
                    this.ResetExpectedElements(expectedElements, index);
                    this.ilg.EndCase();
                    num2++;
                    index++;
                }
                return(index);
            }
            int ReadMembers(ClassDataContract classContract, BitFlagsGenerator expectedElements,
                Label[] memberLabels, Label throwDuplicateMemberLabel, LocalBuilder memberIndexLocal)
            {
                int memberCount = (classContract.BaseContract == null) ? 0 :
                    ReadMembers(classContract.BaseContract, expectedElements, memberLabels, throwDuplicateMemberLabel, memberIndexLocal);

                for (int i = 0; i < classContract.Members.Count; i++, memberCount++)
                {
                    DataMember dataMember = classContract.Members[i];
                    Type memberType = dataMember.MemberType;
                    ilg.Case(memberLabels[memberCount], dataMember.Name);
                    ilg.Set(memberIndexLocal, memberCount);
                    expectedElements.Load(memberCount);
                    ilg.Brfalse(throwDuplicateMemberLabel);
                    LocalBuilder value = null;
                    if (dataMember.IsGetOnlyCollection)
                    {
                        ilg.LoadAddress(objectLocal);
                        ilg.LoadMember(dataMember.MemberInfo);
                        value = ilg.DeclareLocal(memberType, dataMember.Name + "Value");
                        ilg.Stloc(value);
                        ilg.Call(contextArg, XmlFormatGeneratorStatics.StoreCollectionMemberInfoMethod, value);
                        ReadValue(memberType, dataMember.Name);
                    }
                    else
                    {
                        value = ReadValue(memberType, dataMember.Name);
                        ilg.LoadAddress(objectLocal);
                        ilg.ConvertAddress(objectLocal.LocalType, objectType);
                        ilg.Ldloc(value);
                        ilg.StoreMember(dataMember.MemberInfo);
                    }
                    ResetExpectedElements(expectedElements, memberCount);
                    ilg.EndCase();
                }
                return memberCount;
            }
		int ReadMembers (int index, ClassDataContract classContract, BitFlagsGenerator expectedElements, ref int memberIndex)
		{
			int memberCount = (classContract.BaseContract == null) ? 0 : ReadMembers (index, classContract.BaseContract, expectedElements,
			ref memberIndex);
			
			if (memberCount <= index && index < memberCount + classContract.Members.Count) {
				DataMember dataMember = classContract.Members [index - memberCount];
				Type memberType = dataMember.MemberType;
				
				memberIndex = memberCount;
				if (!expectedElements.Load (index))
					XmlObjectSerializerReadContextComplexJson.ThrowDuplicateMemberException (objectLocal, memberNames, memberIndex);

				if (dataMember.IsGetOnlyCollection) {
					var value = CodeInterpreter.GetMember (dataMember.MemberInfo, objectLocal);
					context.StoreCollectionMemberInfo (value);
					ReadValue (memberType, dataMember.Name);
				} else {
					var value = ReadValue (memberType, dataMember.Name);
					CodeInterpreter.SetMember (dataMember.MemberInfo, objectLocal, value);
				}
				memberIndex = index;
				ResetExpectedElements (expectedElements, index);
			}
			return memberCount + classContract.Members.Count;
		}