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

ExportArrayMapping() private method

private ExportArrayMapping ( ArrayMapping mapping, string ns, XmlSchemaElement element ) : void
mapping ArrayMapping
ns string
element System.Xml.Schema.XmlSchemaElement
return void
        private void ExportArrayMapping(ArrayMapping mapping, string ns, XmlSchemaElement element)
        {
            // some of the items in the linked list differ only by CLR type. We don't need to
            // export different schema types for these. Look further down the list for another
            // entry with the same elements. If there is one, it will be exported later so
            // just return its name now.

            ArrayMapping currentMapping = mapping;
            while (currentMapping.Next != null)
            {
                currentMapping = currentMapping.Next;
            }
            XmlSchemaComplexType type = (XmlSchemaComplexType)_types[currentMapping];
            if (type == null)
            {
                CheckForDuplicateType(currentMapping, currentMapping.Namespace);
                type = new XmlSchemaComplexType();
                if (!mapping.IsAnonymousType)
                {
                    type.Name = mapping.TypeName;
                    AddSchemaItem(type, mapping.Namespace, ns);
                }
                if (!currentMapping.IsAnonymousType)
                    _types.Add(currentMapping, type);
                XmlSchemaSequence seq = new XmlSchemaSequence();
                ExportElementAccessors(seq, mapping.Elements, true, false, mapping.Namespace);
                if (seq.Items.Count > 0)
                {
#if DEBUG
                        // we can have only one item for the array mapping
                        if (seq.Items.Count != 1) 
                            throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "Type " + mapping.TypeName + " from namespace '" + ns + "' is an invalid array mapping"));
#endif
                    if (seq.Items[0] is XmlSchemaChoice)
                    {
                        type.Particle = (XmlSchemaChoice)seq.Items[0];
                    }
                    else
                    {
                        type.Particle = seq;
                    }
                }
            }
            else
            {
                AddSchemaImport(mapping.Namespace, ns);
            }
            if (element != null)
            {
                if (mapping.IsAnonymousType)
                {
                    element.SchemaType = type;
                }
                else
                {
                    element.SchemaTypeName = new XmlQualifiedName(type.Name, mapping.Namespace);
                }
            }
        }