void ImportEnum (CodeTypeDeclaration td, XmlSchemaSet schemas, XmlSchemaSimpleTypeRestriction r, XmlSchemaType type, XmlQualifiedName qname, bool isFlag)
{
if (isFlag && !r.BaseTypeName.Equals (new XmlQualifiedName ("string", XmlSchema.Namespace)))
throw new InvalidDataContractException (String.Format ("For flags enumeration '{0}', the base type for the simple type restriction must be XML schema string", qname));
td.IsEnum = true;
AddTypeAttributes (td, type);
if (isFlag)
td.CustomAttributes.Add (new CodeAttributeDeclaration (new CodeTypeReference (typeof (FlagsAttribute))));
foreach (var facet in r.Facets) {
var e = facet as XmlSchemaEnumerationFacet;
if (e == null)
throw new InvalidDataContractException (String.Format ("Invalid simple type restriction (type {0}). Only enumeration is allowed.", qname));
var em = new CodeMemberField () { Name = CodeIdentifier.MakeValid (e.Value) };
var ea = new CodeAttributeDeclaration (enum_member_att_ref);
if (e.Value != em.Name)
ea.Arguments.Add (new CodeAttributeArgument ("Value", new CodePrimitiveExpression (e.Value)));
em.CustomAttributes.Add (ea);
td.Members.Add (em);
}
}