private TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList)
{
TypeMapping mapping = (TypeMapping)base.ImportedMappings[dataType];
if (mapping != null)
{
return(mapping);
}
XmlSchemaSimpleType type = this.FindDataType(dataType.DerivedFrom);
TypeDesc typeDesc = base.Scope.GetTypeDesc(type);
if ((typeDesc != null) && (typeDesc != base.Scope.GetTypeDesc(typeof(string))))
{
return(this.ImportPrimitiveDataType(dataType));
}
identifier = Accessor.UnescapeName(identifier);
string name = base.GenerateUniqueTypeName(identifier);
EnumMapping mapping2 = new EnumMapping {
IsReference = base.Schemas.IsReference(dataType),
TypeDesc = new TypeDesc(name, name, TypeKind.Enum, null, TypeFlags.None),
TypeName = identifier,
Namespace = typeNs,
IsFlags = isList
};
CodeIdentifiers identifiers = new CodeIdentifiers();
if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
{
throw new InvalidOperationException(Res.GetString("XmlInvalidEnumContent", new object[] { dataType.Content.GetType().Name, identifier }));
}
XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)dataType.Content;
for (int i = 0; i < content.Facets.Count; i++)
{
object obj2 = content.Facets[i];
if (obj2 is XmlSchemaEnumerationFacet)
{
XmlSchemaEnumerationFacet facet = (XmlSchemaEnumerationFacet)obj2;
ConstantMapping mapping3 = new ConstantMapping();
string str2 = CodeIdentifier.MakeValid(facet.Value);
mapping3.Name = identifiers.AddUnique(str2, mapping3);
mapping3.XmlName = facet.Value;
mapping3.Value = i;
}
}
mapping2.Constants = (ConstantMapping[])identifiers.ToArray(typeof(ConstantMapping));
if (isList && (mapping2.Constants.Length > 0x3f))
{
mapping = new PrimitiveMapping {
TypeDesc = base.Scope.GetTypeDesc(typeof(string)),
TypeName = mapping.TypeDesc.DataType.Name
};
base.ImportedMappings.Add(dataType, mapping);
return(mapping);
}
base.ImportedMappings.Add(dataType, mapping2);
base.Scope.AddTypeMapping(mapping2);
return(mapping2);
}