System.Xml.Serialization.SoapSchemaImporter.ImportArrayMapping C# (CSharp) Method

ImportArrayMapping() private method

private ImportArrayMapping ( XmlSchemaType type, string ns ) : ArrayMapping
type System.Xml.Schema.XmlSchemaType
ns string
return ArrayMapping
        ArrayMapping ImportArrayMapping(XmlSchemaType type, string ns) {
            ArrayMapping arrayMapping;
            if (type.Name == Soap.Array && ns == Soap.Encoding) {
                arrayMapping = new ArrayMapping();
                TypeMapping mapping = GetRootMapping();
                ElementAccessor itemAccessor = new ElementAccessor();
                itemAccessor.IsSoap = true;
                itemAccessor.Name = Soap.UrType;
                itemAccessor.Namespace = ns;
                itemAccessor.Mapping = mapping;
                itemAccessor.IsNullable = true;
                itemAccessor.Form = XmlSchemaForm.None;

                arrayMapping.Elements = new ElementAccessor[] { itemAccessor };
                arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc();
                arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName);
                return arrayMapping;
            }
            if (!(type.DerivedFrom.Name == Soap.Array && type.DerivedFrom.Namespace == Soap.Encoding)) return null;

            // the type should be a XmlSchemaComplexType
            XmlSchemaContentModel model = ((XmlSchemaComplexType)type).ContentModel;

            // the Content  should be an restriction
            if (!(model.Content is XmlSchemaComplexContentRestriction)) return null;

            arrayMapping = new ArrayMapping();

            XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)model.Content;

            for (int i = 0; i < restriction.Attributes.Count; i++) {
                XmlSchemaAttribute attribute = restriction.Attributes[i] as XmlSchemaAttribute;
                if (attribute != null && attribute.RefName.Name == Soap.ArrayType && attribute.RefName.Namespace == Soap.Encoding) {
                    // read the value of the wsdl:arrayType attribute
                    string arrayType = null;

                    if (attribute.UnhandledAttributes != null) {
                        foreach (XmlAttribute a in attribute.UnhandledAttributes) {
                            if (a.LocalName == Wsdl.ArrayType && a.NamespaceURI == Wsdl.Namespace) {
                                arrayType = a.Value;
                                break;
                            }
                        }
                    }
                    if (arrayType != null) {
                        string dims;
                        XmlQualifiedName typeName = TypeScope.ParseWsdlArrayType(arrayType, out dims, attribute);

                        TypeMapping mapping;
                        TypeDesc td = Scope.GetTypeDesc(typeName.Name, typeName.Namespace);
                        if (td != null && td.IsPrimitive) {
                            mapping = new PrimitiveMapping();
                            mapping.TypeDesc = td;
                            mapping.TypeName = td.DataType.Name;
                        }
                        else {
                            mapping = ImportType(typeName, false);
                        }
                        ElementAccessor itemAccessor = new ElementAccessor();
                        itemAccessor.IsSoap = true;
                        itemAccessor.Name = typeName.Name;
                        itemAccessor.Namespace = ns;
                        itemAccessor.Mapping = mapping;
                        itemAccessor.IsNullable = true;
                        itemAccessor.Form = XmlSchemaForm.None;

                        arrayMapping.Elements = new ElementAccessor[] { itemAccessor };
                        arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc();
                        arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName);

                        return arrayMapping;
                    }
                }
            }

            XmlSchemaParticle particle = restriction.Particle;
            if (particle is XmlSchemaAll || particle is XmlSchemaSequence) {
                XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle;
                if (group.Items.Count != 1 || !(group.Items[0] is XmlSchemaElement))
                    return null;
                XmlSchemaElement itemElement = (XmlSchemaElement)group.Items[0];
                if (!itemElement.IsMultipleOccurrence) return null;
                ElementAccessor itemAccessor = ImportElement(itemElement, ns);
                arrayMapping.Elements = new ElementAccessor[] { itemAccessor };
                arrayMapping.TypeDesc = ((TypeMapping)itemAccessor.Mapping).TypeDesc.CreateArrayTypeDesc();
            }
            else {
                return null;
            }
            return arrayMapping;
        }