EndCase() private method

private EndCase ( ) : void
return void
Ejemplo n.º 1
0
            private int ReadMembers(ClassDataContract classContract, bool[] requiredMembers, Label[] memberLabels, LocalBuilder memberIndexLocal, LocalBuilder requiredIndexLocal)
            {
                int memberCount = (classContract.BaseContract == null) ? 0 : ReadMembers(classContract.BaseContract, requiredMembers,
                                                                                         memberLabels, memberIndexLocal, requiredIndexLocal);

                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);
                    if (dataMember.IsRequired)
                    {
                        int nextRequiredIndex = memberCount + 1;
                        for (; nextRequiredIndex < requiredMembers.Length; nextRequiredIndex++)
                        {
                            if (requiredMembers[nextRequiredIndex])
                            {
                                break;
                            }
                        }
                        _ilg.Set(requiredIndexLocal, nextRequiredIndex);
                    }

                    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, classContract.StableName.Namespace);
                    }
                    else
                    {
                        _ilg.Call(_contextArg, XmlFormatGeneratorStatics.ResetCollectionMemberInfoMethod);
                        value = ReadValue(memberType, dataMember.Name, classContract.StableName.Namespace);
                        _ilg.LoadAddress(_objectLocal);
                        _ilg.ConvertAddress(_objectLocal.LocalType, _objectType);
                        _ilg.Ldloc(value);
                        _ilg.StoreMember(dataMember.MemberInfo);
                    }

#if FEATURE_LEGACYNETCF
                    // The DataContractSerializer in the full framework doesn't support unordered elements:
                    // deserialization will fail if the data members in the XML are not sorted alphabetically.
                    // But the NetCF DataContractSerializer does support unordered element. To maintain compatibility
                    // with Mango we always search for the member from the beginning of the member list.
                    // We set memberIndexLocal to -1 because GetMemberIndex always starts from memberIndex+1.
                    if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                    {
                        ilg.Set(memberIndexLocal, (int)-1);
                    }
                    else
#endif // FEATURE_LEGACYNETCF
                    _ilg.Set(memberIndexLocal, memberCount);

                    _ilg.EndCase();
                }
                return(memberCount);
            }