private void ExportType(TypeMapping mapping, string name, string ns, ElementAccessor rootElement, bool checkReference)
{
if ((!mapping.IsReference || (mapping.Namespace == "http://schemas.xmlsoap.org/soap/encoding/")) && ((!(mapping is StructMapping) || !checkReference) || (!((StructMapping)mapping).ReferencedByTopLevelElement || (rootElement != null))))
{
if (((mapping is ArrayMapping) && (rootElement != null)) && (rootElement.IsTopLevelInSchema && (((ArrayMapping)mapping).TopLevelMapping != null)))
{
mapping = ((ArrayMapping)mapping).TopLevelMapping;
}
CodeTypeDeclaration declaration = null;
if (base.ExportedMappings[mapping] == null)
{
base.ExportedMappings.Add(mapping, mapping);
if (mapping.TypeDesc.IsMappedType)
{
declaration = mapping.TypeDesc.ExtendedType.ExportTypeDefinition(base.CodeNamespace, base.CodeCompileUnit);
}
else if (mapping is EnumMapping)
{
declaration = base.ExportEnum((EnumMapping)mapping, typeof(XmlEnumAttribute));
}
else if (mapping is StructMapping)
{
declaration = this.ExportStruct((StructMapping)mapping);
}
else if (mapping is ArrayMapping)
{
this.EnsureTypesExported(((ArrayMapping)mapping).Elements, ns);
}
if (declaration != null)
{
if (!mapping.TypeDesc.IsMappedType)
{
declaration.CustomAttributes.Add(base.GeneratedCodeAttribute);
declaration.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(SerializableAttribute).FullName));
if (!declaration.IsEnum)
{
declaration.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DebuggerStepThroughAttribute).FullName));
declaration.CustomAttributes.Add(new CodeAttributeDeclaration(typeof(DesignerCategoryAttribute).FullName, new CodeAttributeArgument[] { new CodeAttributeArgument(new CodePrimitiveExpression("code")) }));
}
base.AddTypeMetadata(declaration.CustomAttributes, typeof(XmlTypeAttribute), mapping.TypeDesc.Name, Accessor.UnescapeName(mapping.TypeName), mapping.Namespace, mapping.IncludeInSchema);
}
else if (CodeExporter.FindAttributeDeclaration(typeof(GeneratedCodeAttribute), declaration.CustomAttributes) == null)
{
declaration.CustomAttributes.Add(base.GeneratedCodeAttribute);
}
base.ExportedClasses.Add(mapping, declaration);
}
}
else
{
declaration = (CodeTypeDeclaration)base.ExportedClasses[mapping];
}
if ((declaration != null) && (rootElement != null))
{
this.AddRootMetadata(declaration.CustomAttributes, mapping, name, ns, rootElement);
}
}
}