System.Xml.Serialization.XmlSchemaImporter.ImportDataType C# (CSharp) Method

ImportDataType() private method

private ImportDataType ( XmlSchemaSimpleType dataType, string typeNs, string identifier, Type baseType, TypeFlags flags, bool isList ) : TypeMapping
dataType System.Xml.Schema.XmlSchemaSimpleType
typeNs string
identifier string
baseType Type
flags TypeFlags
isList bool
return TypeMapping
        private TypeMapping ImportDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, Type baseType, TypeFlags flags, bool isList)
        {
            if (baseType != null)
                return ImportStructDataType(dataType, typeNs, identifier, baseType);

            TypeMapping mapping = ImportNonXsdPrimitiveDataType(dataType, typeNs, flags);
            if (mapping != null)
                return mapping;

            if (dataType.Content is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content;
                foreach (object o in restriction.Facets)
                {
                    if (o is XmlSchemaEnumerationFacet)
                    {
                        return ImportEnumeratedDataType(dataType, typeNs, identifier, flags, isList);
                    }
                }
                if (restriction.BaseType != null)
                {
                    return ImportDataType(restriction.BaseType, typeNs, identifier, null, flags, false);
                }
                else
                {
                    AddReference(restriction.BaseTypeName, TypesInUse, SR.XmlCircularTypeReference);
                    mapping = ImportDataType(FindDataType(restriction.BaseTypeName, flags), restriction.BaseTypeName.Namespace, identifier, null, flags, false);
                    if (restriction.BaseTypeName.Namespace != XmlSchema.Namespace)
                        RemoveReference(restriction.BaseTypeName, TypesInUse);
                    return mapping;
                }
            }
            else if (dataType.Content is XmlSchemaSimpleTypeList || dataType.Content is XmlSchemaSimpleTypeUnion)
            {
                if (dataType.Content is XmlSchemaSimpleTypeList)
                {
                    // check if we have enumeration list
                    XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)dataType.Content;
                    if (list.ItemType != null)
                    {
                        mapping = ImportDataType(list.ItemType, typeNs, identifier, null, flags, true);
                        if (mapping != null)
                        {
                            mapping.TypeName = dataType.Name;
                            return mapping;
                        }
                    }
                    else if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty)
                    {
                        mapping = ImportType(list.ItemTypeName, typeof(TypeMapping), null, TypeFlags.CanBeAttributeValue, true);
                        if (mapping != null && mapping is PrimitiveMapping)
                        {
                            ((PrimitiveMapping)mapping).IsList = true;
                            return mapping;
                        }
                    }
                }
                return GetDefaultMapping(flags);
            }
            return ImportPrimitiveDataType(dataType, flags);
        }