private EnumMapping ImportEnumMapping(EnumModel model, string ns, bool repeats)
{
XmlAttributes a = GetAttributes(model.Type, false);
string typeNs = ns;
if (a.XmlType != null && a.XmlType.Namespace != null)
typeNs = a.XmlType.Namespace;
string typeName = IsAnonymousType(a, ns) ? null : XsdTypeName(model.Type, a, model.TypeDesc.Name);
typeName = XmlConvert.EncodeLocalName(typeName);
EnumMapping mapping = (EnumMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc, _types, model.Type);
if (mapping == null)
{
mapping = new EnumMapping();
mapping.TypeDesc = model.TypeDesc;
mapping.TypeName = typeName;
mapping.Namespace = typeNs;
mapping.IsFlags = model.Type.GetTypeInfo().IsDefined(typeof(FlagsAttribute), false);
if (mapping.IsFlags && repeats)
throw new InvalidOperationException(SR.Format(SR.XmlIllegalAttributeFlagsArray, model.TypeDesc.FullName));
mapping.IsList = repeats;
mapping.IncludeInSchema = a.XmlType == null ? true : a.XmlType.IncludeInSchema;
if (!mapping.IsAnonymousType)
_types.Add(typeName, typeNs, mapping);
else
_anonymous[model.Type] = mapping;
ArrayList constants = new ArrayList();
for (int i = 0; i < model.Constants.Length; i++)
{
ConstantMapping constant = ImportConstantMapping(model.Constants[i]);
if (constant != null) constants.Add(constant);
}
if (constants.Count == 0)
{
throw new InvalidOperationException(SR.Format(SR.XmlNoSerializableMembers, model.TypeDesc.FullName));
}
mapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
_typeScope.AddTypeMapping(mapping);
}
return mapping;
}