void DoImport (XmlSchemaSet schemas, XmlSchemaType type, XmlQualifiedName qname)
{
CodeNamespace cns = null;
CodeTypeReference clrRef;
cns = GetCodeNamespace (qname);
clrRef = new CodeTypeReference (cns.Name.Length > 0 ? cns.Name + "." + qname.Name : qname.Name);
var td = new CodeTypeDeclaration () {
Name = GetUniqueName (CodeIdentifier.MakeValid (qname.Name), cns),
TypeAttributes = GenerateInternal ? TypeAttributes.NotPublic : TypeAttributes.Public };
cns.Types.Add (td);
var info = new TypeImportInfo () { ClrType = clrRef, XsdType = type, XsdTypeName = qname };
imported_types.Add (info);
var st = type as XmlSchemaSimpleType;
if (st != null) {
ImportSimpleType (td, schemas, st, qname);
} else {
var ct = (XmlSchemaComplexType) type;
var sc = ct.ContentModel as XmlSchemaSimpleContent;
if (sc != null) {
if (sc.Content is XmlSchemaSimpleContentExtension)
throw new InvalidDataContractException (String.Format ("complex type '{0}' with simple content extension is not supported", type.QualifiedName));
}
if (!ImportComplexType (td, schemas, ct, qname)) {
cns.Types.Remove (td);
if (cns.Types.Count == 0)
CodeCompileUnit.Namespaces.Remove (cns);
}
foreach (var impinfo in imported_types)
for (; impinfo.KnownTypeOutputIndex < impinfo.KnownClrTypes.Count; impinfo.KnownTypeOutputIndex++)
td.CustomAttributes.Add (new CodeAttributeDeclaration (
new CodeTypeReference (typeof (KnownTypeAttribute)),
new CodeAttributeArgument (new CodeTypeOfExpression (impinfo.KnownClrTypes [impinfo.KnownTypeOutputIndex]))));
}
}