System.Xml.Serialization.XmlReflectionImporter.GetChoiceIdentifierType C# (CSharp) Method

GetChoiceIdentifierType() private method

private GetChoiceIdentifierType ( XmlChoiceIdentifierAttribute choice, StructModel structModel, bool isArrayLike, string accessorName ) : Type
choice XmlChoiceIdentifierAttribute
structModel StructModel
isArrayLike bool
accessorName string
return System.Type
        private Type GetChoiceIdentifierType(XmlChoiceIdentifierAttribute choice, StructModel structModel, bool isArrayLike, string accessorName)
        {
            // check that the choice field exists

            MemberInfo[] infos = structModel.Type.GetMember(choice.MemberName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            if (infos == null || infos.Length == 0)
            {
                // if we can not find the choice identifier between fields, check proerties
                PropertyInfo info = structModel.Type.GetProperty(choice.MemberName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                if (info == null)
                {
                    // Missing '{0}' needed for serialization of choice '{1}'.
                    throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferMemberMissing, choice.MemberName, accessorName));
                }
                infos = new MemberInfo[] { info };
            }
            else if (infos.Length > 1)
            {
                // Ambiguous choice identifer: there are several members named '{0}'.
                throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferAmbiguous, choice.MemberName));
            }

            FieldModel member = structModel.GetFieldModel(infos[0]);
            if (member == null)
            {
                // Missing '{0}' needed for serialization of choice '{1}'.
                throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferMemberMissing, choice.MemberName, accessorName));
            }
            choice.MemberInfo = member.MemberInfo;
            Type enumType = member.FieldType;
            enumType = CheckChoiceIdentifierType(enumType, isArrayLike, choice.MemberName, accessorName);
            return enumType;
        }

Same methods

XmlReflectionImporter::GetChoiceIdentifierType ( XmlChoiceIdentifierAttribute choice, XmlReflectionMember xmlReflectionMembers, bool isArrayLike, string accessorName ) : Type