XmlQualifiedName ExportEnumMapping(EnumMapping mapping, string ns) {
XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)types[mapping];
if (dataType == null) {
CheckForDuplicateType(mapping.TypeName, mapping.Namespace);
dataType = new XmlSchemaSimpleType();
dataType.Name = mapping.TypeName;
types.Add(mapping, dataType);
AddSchemaItem(dataType, mapping.Namespace, ns);
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
for (int i = 0; i < mapping.Constants.Length; i++) {
ConstantMapping constant = mapping.Constants[i];
XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
enumeration.Value = constant.XmlName;
restriction.Facets.Add(enumeration);
}
if (!mapping.IsFlags) {
dataType.Content = restriction;
}
else {
XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
XmlSchemaSimpleType enumType = new XmlSchemaSimpleType();
enumType.Content = restriction;
list.ItemType = enumType;
dataType.Content = list;
}
}
else {
AddSchemaImport(mapping.Namespace, ns);
}
return new XmlQualifiedName(mapping.TypeName, mapping.Namespace);
}
}