System.Xml.Serialization.XmlSchemaExporter.ExportTypeMembers C# (CSharp) Method

ExportTypeMembers() private method

private ExportTypeMembers ( XmlSchemaComplexType type, MemberMapping members, string name, string ns, bool hasSimpleContent, bool openModel ) : void
type System.Xml.Schema.XmlSchemaComplexType
members MemberMapping
name string
ns string
hasSimpleContent bool
openModel bool
return void
        private void ExportTypeMembers(XmlSchemaComplexType type, MemberMapping[] members, string name, string ns, bool hasSimpleContent, bool openModel)
        {
            XmlSchemaGroupBase seq = new XmlSchemaSequence();
            TypeMapping textMapping = null;

            for (int i = 0; i < members.Length; i++)
            {
                MemberMapping member = members[i];
                if (member.Ignore)
                    continue;
                if (member.Text != null)
                {
                    if (textMapping != null)
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlIllegalMultipleText, name));
                    }
                    textMapping = member.Text.Mapping;
                }
                if (member.Elements.Length > 0)
                {
                    bool repeats = member.TypeDesc.IsArrayLike &&
                        !(member.Elements.Length == 1 && member.Elements[0].Mapping is ArrayMapping);

                    bool valueTypeOptional = member.CheckSpecified != SpecifiedAccessor.None || member.CheckShouldPersist;
                    ExportElementAccessors(seq, member.Elements, repeats, valueTypeOptional, ns);
                }
            }

            if (seq.Items.Count > 0)
            {
                if (type.ContentModel != null)
                {
                    if (type.ContentModel.Content is XmlSchemaComplexContentRestriction)
                        ((XmlSchemaComplexContentRestriction)type.ContentModel.Content).Particle = seq;
                    else if (type.ContentModel.Content is XmlSchemaComplexContentExtension)
                        ((XmlSchemaComplexContentExtension)type.ContentModel.Content).Particle = seq;
                    else
                        throw new InvalidOperationException(SR.Format(SR.XmlInvalidContent, type.ContentModel.Content.GetType().Name));
                }
                else
                {
                    type.Particle = seq;
                }
            }
            if (textMapping != null)
            {
                if (hasSimpleContent)
                {
                    if (textMapping is PrimitiveMapping && seq.Items.Count == 0)
                    {
                        PrimitiveMapping pm = (PrimitiveMapping)textMapping;
                        if (pm.IsList)
                        {
                            type.IsMixed = true;
                        }
                        else
                        {
                            if (pm.IsAnonymousType)
                            {
                                throw new InvalidOperationException(SR.Format(SR.XmlAnonymousBaseType, textMapping.TypeDesc.Name, pm.TypeDesc.Name, "AnonymousType", "false"));
                            }
                            // Create simpleContent
                            XmlSchemaSimpleContent model = new XmlSchemaSimpleContent();
                            XmlSchemaSimpleContentExtension ex = new XmlSchemaSimpleContentExtension();
                            model.Content = ex;
                            type.ContentModel = model;
                            ex.BaseTypeName = ExportPrimitiveMapping(pm, ns);
                        }
                    }
                }
                else
                {
                    type.IsMixed = true;
                }
            }
            bool anyAttribute = false;
            for (int i = 0; i < members.Length; i++)
            {
                AttributeAccessor accessor = members[i].Attribute;
                if (accessor != null)
                {
                    ExportAttributeAccessor(type, members[i].Attribute, members[i].CheckSpecified != SpecifiedAccessor.None || members[i].CheckShouldPersist, ns);
                    if (members[i].Attribute.Any)
                        anyAttribute = true;
                }
            }
            if (openModel && !anyAttribute)
            {
                AttributeAccessor any = new AttributeAccessor();
                any.Any = true;
                ExportAttributeAccessor(type, any, false, ns);
            }
        }