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

ImportArrayLikeMapping() private method

private ImportArrayLikeMapping ( ArrayModel model, string ns, RecursionLimiter limiter ) : ArrayMapping
model ArrayModel
ns string
limiter RecursionLimiter
return ArrayMapping
        private ArrayMapping ImportArrayLikeMapping(ArrayModel model, string ns, RecursionLimiter limiter)
        {
            ArrayMapping mapping = new ArrayMapping();
            mapping.TypeDesc = model.TypeDesc;

            if (_savedArrayItemAttributes == null)
                _savedArrayItemAttributes = new XmlArrayItemAttributes();
            if (CountAtLevel(_savedArrayItemAttributes, _arrayNestingLevel) == 0)
                _savedArrayItemAttributes.Add(CreateArrayItemAttribute(_typeScope.GetTypeDesc(model.Element.Type), _arrayNestingLevel));
            CreateArrayElementsFromAttributes(mapping, _savedArrayItemAttributes, model.Element.Type, _savedArrayNamespace == null ? ns : _savedArrayNamespace, limiter);
            SetArrayMappingType(mapping, ns, model.Type);

            // reconcile accessors now that we have the ArrayMapping namespace
            for (int i = 0; i < mapping.Elements.Length; i++)
            {
                mapping.Elements[i] = ReconcileLocalAccessor(mapping.Elements[i], mapping.Namespace);
            }

            IncludeTypes(model.Type.GetTypeInfo());

            // in the case of an ArrayMapping we can have more that one mapping correspond to a type
            // examples of that are ArrayList and object[] both will map tp ArrayOfur-type
            // so we create a link list for all mappings of the same XSD type
            ArrayMapping existingMapping = (ArrayMapping)_types[mapping.TypeName, mapping.Namespace];
            if (existingMapping != null)
            {
                ArrayMapping first = existingMapping;
                while (existingMapping != null)
                {
                    if (existingMapping.TypeDesc == model.TypeDesc)
                        return existingMapping;
                    existingMapping = existingMapping.Next;
                }
                mapping.Next = first;
                if (!mapping.IsAnonymousType)
                    _types[mapping.TypeName, mapping.Namespace] = mapping;
                else
                    _anonymous[model.Type] = mapping;
                return mapping;
            }
            _typeScope.AddTypeMapping(mapping);
            if (!mapping.IsAnonymousType)
                _types.Add(mapping.TypeName, mapping.Namespace, mapping);
            else
                _anonymous[model.Type] = mapping;
            return mapping;
        }