private XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element)
{
if (mapping.TypeDesc.IsRoot)
{
_needToExportRoot = true;
return XmlQualifiedName.Empty;
}
if (mapping.IsAnonymousType)
{
if (_references[mapping] != null)
throw new InvalidOperationException(SR.Format(SR.XmlCircularReference2, mapping.TypeDesc.Name, "AnonymousType", "false"));
_references[mapping] = mapping;
}
XmlSchemaComplexType type = (XmlSchemaComplexType)_types[mapping];
if (type == null)
{
if (!mapping.IncludeInSchema) throw new InvalidOperationException(SR.Format(SR.XmlCannotIncludeInSchema, mapping.TypeDesc.Name));
CheckForDuplicateType(mapping, mapping.Namespace);
type = new XmlSchemaComplexType();
if (!mapping.IsAnonymousType)
{
type.Name = mapping.TypeName;
AddSchemaItem(type, mapping.Namespace, ns);
_types.Add(mapping, type);
}
type.IsAbstract = mapping.TypeDesc.IsAbstract;
bool openModel = mapping.IsOpenModel;
if (mapping.BaseMapping != null && mapping.BaseMapping.IncludeInSchema)
{
if (mapping.BaseMapping.IsAnonymousType)
{
throw new InvalidOperationException(SR.Format(SR.XmlAnonymousBaseType, mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false"));
}
if (mapping.HasSimpleContent)
{
XmlSchemaSimpleContent model = new XmlSchemaSimpleContent();
XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null);
model.Content = extension;
type.ContentModel = model;
}
else
{
XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null);
XmlSchemaComplexContent model = new XmlSchemaComplexContent();
model.Content = extension;
model.IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType)_types[mapping.BaseMapping]);
type.ContentModel = model;
}
openModel = false;
}
ExportTypeMembers(type, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, openModel);
ExportDerivedMappings(mapping);
if (mapping.XmlnsMember != null)
{
AddXmlnsAnnotation(type, mapping.XmlnsMember.Name);
}
}
else
{
AddSchemaImport(mapping.Namespace, ns);
}
if (mapping.IsAnonymousType)
{
_references[mapping] = null;
if (element != null)
element.SchemaType = type;
return XmlQualifiedName.Empty;
}
else
{
XmlQualifiedName qname = new XmlQualifiedName(type.Name, mapping.Namespace);
if (element != null) element.SchemaTypeName = qname;
return qname;
}
}