void ReadMembers(ClassDataContract classContract, ExtensionDataObject extensionData) { int memberCount = classContract.MemberNames.Length; context.IncrementItemCount(memberCount); int memberIndex = -1; // JSON intrinsic part. BitFlagsGenerator expectedElements = new BitFlagsGenerator(memberCount); byte [] requiredElements = new byte [expectedElements.GetLocalCount()]; SetRequiredElements(classContract, requiredElements); SetExpectedElements(expectedElements, 0 /*startIndex*/); while (XmlObjectSerializerReadContext.MoveToNextElement(xmlReader)) { int idx; // used as in "switch (idx)" in the original source. idx = context.GetJsonMemberIndex(xmlReader, memberNames, memberIndex, extensionData); if (memberCount > 0) { ReadMembers(idx, classContract, expectedElements, ref memberIndex); } } if (!CheckRequiredElements(expectedElements, requiredElements)) { XmlObjectSerializerReadContextComplexJson.ThrowMissingRequiredMembers(objectLocal, memberNames, expectedElements.LoadArray(), requiredElements); } }
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); }
private void SetExpectedElements(BitFlagsGenerator expectedElements, int startIndex) { int memberCount = expectedElements.GetBitCount(); for (int i = startIndex; i < memberCount; i++) { expectedElements.Store(i, true); } }
bool CheckRequiredElements(BitFlagsGenerator expectedElements, byte [] requiredElements) { for (int i = 0; i < requiredElements.Length; i++) { if ((expectedElements.GetLocal(i) & requiredElements[i]) != 0) { return(false); } } return(true); }
private void CheckRequiredElements(BitFlagsGenerator expectedElements, byte[] requiredElements, Label throwMissingRequiredMembersLabel) { for (int i = 0; i < requiredElements.Length; i++) { _ilg.Load(expectedElements.GetLocal(i)); _ilg.Load(requiredElements[i]); _ilg.And(); _ilg.Load(0); _ilg.Ceq(); _ilg.Brfalse(throwMissingRequiredMembersLabel); } }
private void ReadMembers(ClassDataContract classContract, LocalBuilder extensionDataLocal) { int memberCount = classContract.MemberNames.Length; _ilg.Call(_contextArg, XmlFormatGeneratorStatics.IncrementItemCountMethod, memberCount); BitFlagsGenerator expectedElements = new BitFlagsGenerator(memberCount, _ilg, classContract.UnderlyingType.Name + "_ExpectedElements"); byte[] requiredElements = new byte[expectedElements.GetLocalCount()]; SetRequiredElements(classContract, requiredElements); SetExpectedElements(expectedElements, 0 /*startIndex*/); LocalBuilder memberIndexLocal = _ilg.DeclareLocal(Globals.TypeOfInt, "memberIndex", -1); Label throwDuplicateMemberLabel = _ilg.DefineLabel(); Label throwMissingRequiredMembersLabel = _ilg.DefineLabel(); object forReadElements = _ilg.For(null, null, null); _ilg.Call(null, XmlFormatGeneratorStatics.MoveToNextElementMethod, _xmlReaderArg); _ilg.IfFalseBreak(forReadElements); _ilg.Call(_contextArg, JsonFormatGeneratorStatics.GetJsonMemberIndexMethod, _xmlReaderArg, _memberNamesArg, memberIndexLocal, extensionDataLocal); if (memberCount > 0) { Label[] memberLabels = _ilg.Switch(memberCount); ReadMembers(classContract, expectedElements, memberLabels, throwDuplicateMemberLabel, memberIndexLocal); _ilg.EndSwitch(); } else { _ilg.Pop(); } _ilg.EndFor(); CheckRequiredElements(expectedElements, requiredElements, throwMissingRequiredMembersLabel); Label endOfTypeLabel = _ilg.DefineLabel(); _ilg.Br(endOfTypeLabel); _ilg.MarkLabel(throwDuplicateMemberLabel); _ilg.Call(null, JsonFormatGeneratorStatics.ThrowDuplicateMemberExceptionMethod, _objectLocal, _memberNamesArg, memberIndexLocal); _ilg.MarkLabel(throwMissingRequiredMembersLabel); _ilg.Load(_objectLocal); _ilg.ConvertValue(_objectLocal.LocalType, Globals.TypeOfObject); _ilg.Load(_memberNamesArg); expectedElements.LoadArray(); LoadArray(requiredElements, "requiredElements"); _ilg.Call(JsonFormatGeneratorStatics.ThrowMissingRequiredMembersMethod); _ilg.MarkLabel(endOfTypeLabel); }
private int SetRequiredElements(ClassDataContract contract, byte[] requiredElements) { int memberCount = (contract.BaseContract == null) ? 0 : SetRequiredElements(contract.BaseContract, requiredElements); List <DataMember> members = contract.Members; for (int i = 0; i < members.Count; i++, memberCount++) { if (members[i].IsRequired) { BitFlagsGenerator.SetBit(requiredElements, memberCount); } } return(memberCount); }
private int SetRequiredElements(ClassDataContract contract, byte[] requiredElements) { int bitIndex = (contract.BaseContract == null) ? 0 : this.SetRequiredElements(contract.BaseContract, requiredElements); List <DataMember> members = contract.Members; int num2 = 0; while (num2 < members.Count) { if (members[num2].IsRequired) { BitFlagsGenerator.SetBit(requiredElements, bitIndex); } num2++; bitIndex++; } return(bitIndex); }
private void ReadMembers(ClassDataContract classContract, LocalBuilder extensionDataLocal) { int length = classContract.MemberNames.Length; this.ilg.Call(this.contextArg, XmlFormatGeneratorStatics.IncrementItemCountMethod, length); BitFlagsGenerator expectedElements = new BitFlagsGenerator(length, this.ilg, classContract.UnderlyingType.Name + "_ExpectedElements"); byte[] requiredElements = new byte[expectedElements.GetLocalCount()]; this.SetRequiredElements(classContract, requiredElements); this.SetExpectedElements(expectedElements, 0); LocalBuilder builder = this.ilg.DeclareLocal(Globals.TypeOfInt, "memberIndex", -1); Label throwDuplicateMemberLabel = this.ilg.DefineLabel(); Label throwMissingRequiredMembersLabel = this.ilg.DefineLabel(); object forState = this.ilg.For(null, null, null); this.ilg.Call(null, XmlFormatGeneratorStatics.MoveToNextElementMethod, this.xmlReaderArg); this.ilg.IfFalseBreak(forState); this.ilg.Call(this.contextArg, JsonFormatGeneratorStatics.GetJsonMemberIndexMethod, this.xmlReaderArg, this.memberNamesArg, builder, extensionDataLocal); if (length > 0) { Label[] memberLabels = this.ilg.Switch(length); this.ReadMembers(classContract, expectedElements, memberLabels, throwDuplicateMemberLabel, builder); this.ilg.EndSwitch(); } else { this.ilg.Pop(); } this.ilg.EndFor(); this.CheckRequiredElements(expectedElements, requiredElements, throwMissingRequiredMembersLabel); Label label = this.ilg.DefineLabel(); this.ilg.Br(label); this.ilg.MarkLabel(throwDuplicateMemberLabel); this.ilg.Call(null, JsonFormatGeneratorStatics.ThrowDuplicateMemberExceptionMethod, this.objectLocal, this.memberNamesArg, builder); this.ilg.MarkLabel(throwMissingRequiredMembersLabel); this.ilg.Load(this.objectLocal); this.ilg.ConvertValue(this.objectLocal.LocalType, Globals.TypeOfObject); this.ilg.Load(this.memberNamesArg); expectedElements.LoadArray(); this.LoadArray(requiredElements, "requiredElements"); this.ilg.Call(JsonFormatGeneratorStatics.ThrowMissingRequiredMembersMethod); this.ilg.MarkLabel(label); }
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); }
void ResetExpectedElements(BitFlagsGenerator expectedElements, int index) { expectedElements.Store(index, false); }
void SetExpectedElements(BitFlagsGenerator expectedElements, int startIndex) { int memberCount = expectedElements.GetBitCount(); for (int i = startIndex; i < memberCount; i++) { expectedElements.Store(i, true); } }
void CheckRequiredElements(BitFlagsGenerator expectedElements, byte[] requiredElements, Label throwMissingRequiredMembersLabel) { for (int i = 0; i < requiredElements.Length; i++) { ilg.Load(expectedElements.GetLocal(i)); ilg.Load(requiredElements[i]); ilg.And(); ilg.Load(0); ilg.Ceq(); ilg.Brfalse(throwMissingRequiredMembersLabel); } }
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; }
private void ResetExpectedElements(BitFlagsGenerator expectedElements, int index) { expectedElements.Store(index, false); }
bool CheckRequiredElements (BitFlagsGenerator expectedElements, byte [] requiredElements) { for (int i = 0; i < requiredElements.Length; i++) if ((expectedElements.GetLocal(i) & requiredElements[i]) != 0) return false; return true; }
void ReadMembers(ClassDataContract classContract, LocalBuilder extensionDataLocal) { int memberCount = classContract.MemberNames.Length; ilg.Call(contextArg, XmlFormatGeneratorStatics.IncrementItemCountMethod, memberCount); BitFlagsGenerator expectedElements = new BitFlagsGenerator(memberCount, ilg, classContract.UnderlyingType.Name + "_ExpectedElements"); byte[] requiredElements = new byte[expectedElements.GetLocalCount()]; SetRequiredElements(classContract, requiredElements); SetExpectedElements(expectedElements, 0 /*startIndex*/); LocalBuilder memberIndexLocal = ilg.DeclareLocal(Globals.TypeOfInt, "memberIndex", -1); Label throwDuplicateMemberLabel = ilg.DefineLabel(); Label throwMissingRequiredMembersLabel = ilg.DefineLabel(); object forReadElements = ilg.For(null, null, null); ilg.Call(null, XmlFormatGeneratorStatics.MoveToNextElementMethod, xmlReaderArg); ilg.IfFalseBreak(forReadElements); ilg.Call(contextArg, JsonFormatGeneratorStatics.GetJsonMemberIndexMethod, xmlReaderArg, memberNamesArg, memberIndexLocal, extensionDataLocal); if (memberCount > 0) { Label[] memberLabels = ilg.Switch(memberCount); ReadMembers(classContract, expectedElements, memberLabels, throwDuplicateMemberLabel, memberIndexLocal); ilg.EndSwitch(); } else { ilg.Pop(); } ilg.EndFor(); CheckRequiredElements(expectedElements, requiredElements, throwMissingRequiredMembersLabel); Label endOfTypeLabel = ilg.DefineLabel(); ilg.Br(endOfTypeLabel); ilg.MarkLabel(throwDuplicateMemberLabel); ilg.Call(null, JsonFormatGeneratorStatics.ThrowDuplicateMemberExceptionMethod, objectLocal, memberNamesArg, memberIndexLocal); ilg.MarkLabel(throwMissingRequiredMembersLabel); ilg.Load(objectLocal); ilg.ConvertValue(objectLocal.LocalType, Globals.TypeOfObject); ilg.Load(memberNamesArg); expectedElements.LoadArray(); LoadArray(requiredElements, "requiredElements"); ilg.Call(JsonFormatGeneratorStatics.ThrowMissingRequiredMembersMethod); ilg.MarkLabel(endOfTypeLabel); }
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; }
private static bool IsBitSet(byte[] bytes, int bitIndex) { return(BitFlagsGenerator.IsBitSet(bytes, bitIndex)); }
void ReadMembers (ClassDataContract classContract, ExtensionDataObject extensionData) { int memberCount = classContract.MemberNames.Length; context.IncrementItemCount (memberCount); int memberIndex = -1; // JSON intrinsic part. BitFlagsGenerator expectedElements = new BitFlagsGenerator (memberCount); byte [] requiredElements = new byte [expectedElements.GetLocalCount ()]; SetRequiredElements (classContract, requiredElements); SetExpectedElements (expectedElements, 0 /*startIndex*/); while (XmlObjectSerializerReadContext.MoveToNextElement (xmlReader)) { int idx; // used as in "switch (idx)" in the original source. idx = context.GetJsonMemberIndex (xmlReader, memberNames, memberIndex, extensionData); if (memberCount > 0) ReadMembers (idx, classContract, expectedElements, ref memberIndex); } if (!CheckRequiredElements (expectedElements, requiredElements)) XmlObjectSerializerReadContextComplexJson.ThrowMissingRequiredMembers (objectLocal, memberNames, expectedElements.LoadArray (), requiredElements); }