private static DocumentedAssembly MapAssembly(IAssemblyInfo assembly, XmlDocumentationModel model)
{
var types = new List<DocumentedType>();
// Iterate all types in assembly.
foreach (var type in assembly.Types)
{
var documentedType = MapType(type, model);
types.Add(documentedType);
// Add a reference to the type for every constructor.
foreach (var constructor in documentedType.Constructors)
{
constructor.Type = documentedType;
}
// Add a reference to the type for every method.
foreach (var method in documentedType.Methods)
{
method.Type = documentedType;
}
// Add a reference to the type for every method.
foreach (var @operator in documentedType.Operators)
{
@operator.Type = documentedType;
}
// Add a reference to the type for every property.
foreach (var property in documentedType.Properties)
{
property.Type = documentedType;
}
// Add a reference to the type for every method.
foreach (var field in documentedType.Fields)
{
field.Type = documentedType;
}
}
// Now group all the types in this assembly by their namespace.
var namespaces = new List<DocumentedNamespace>();
var namespaceGroups = types.GroupBy(x => x.Definition.Namespace);
foreach (var namespaceGroup in namespaceGroups)
{
var namespaceTypes = namespaceGroup.ToList();
// Do we have a documentation for this namespace?
var documentation = namespaceGroup.FirstOrDefault(x => x.Definition.Name.EndsWith("NamespaceDoc"));
var summary = documentation?.Summary;
if (documentation != null)
{
namespaceTypes.Remove(documentation);
}
// Create a namespace for each grouping.
var @namespace = new DocumentedNamespace(namespaceGroup.Key, namespaceGroup.Key, namespaceTypes, summary, assembly.Metadata);
namespaces.Add(@namespace);
// Connect the types in this namespace to the namespace.
foreach (var documentedType in namespaceGroup)
{
documentedType.Namespace = @namespace;
}
}
// Create an documented assembly out of it.
var documentedAssembly = new DocumentedAssembly(assembly, namespaces, assembly.Metadata);
// Add the documented assembly as a parent of all namespaces.
foreach (var @namespace in namespaces)
{
@namespace.Assembly = documentedAssembly;
}
// Return the documented assembly.
return documentedAssembly;
}