private void CheckRequiredElements(BitFlagsGenerator expectedElements, byte[] requiredElements, Label throwMissingRequiredMembersLabel)
 {
     for (int i = 0; i < requiredElements.Length; i++)
     {
         this.ilg.Load(expectedElements.GetLocal(i));
         this.ilg.Load(requiredElements[i]);
         this.ilg.And();
         this.ilg.Load(0);
         this.ilg.Ceq();
         this.ilg.Brfalse(throwMissingRequiredMembersLabel);
     }
 }
 private void SetExpectedElements(BitFlagsGenerator expectedElements, int startIndex)
 {
     int bitCount = expectedElements.GetBitCount();
     for (int i = startIndex; i < bitCount; i++)
     {
         expectedElements.Store(i, true);
     }
 }
 private void ResetExpectedElements(BitFlagsGenerator expectedElements, int index)
 {
     expectedElements.Store(index, false);
 }
 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;
 }
 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 static bool IsBitSet(byte[] bytes, int bitIndex)
 {
     return(BitFlagsGenerator.IsBitSet(bytes, bitIndex));
 }