public void SerializeTypes(IEnumerable<Type> types, TextWriter output)
{
var groupedByAssembly = from type in types
group type by type.Module
into groupedByModule
group groupedByModule by groupedByModule.Key.Assembly;
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateComment(MvcResources.TypeCache_DoNotModify));
XmlElement typeCacheElement = doc.CreateElement("typeCache");
doc.AppendChild(typeCacheElement);
typeCacheElement.SetAttribute("lastModified", CurrentDate.ToString(System.Globalization.CultureInfo.InvariantCulture));
typeCacheElement.SetAttribute("mvcVersionId", _mvcVersionId.ToString());
foreach (var assemblyGroup in groupedByAssembly)
{
XmlElement assemblyElement = doc.CreateElement("assembly");
typeCacheElement.AppendChild(assemblyElement);
assemblyElement.SetAttribute("name", assemblyGroup.Key.FullName);
foreach (var moduleGroup in assemblyGroup)
{
XmlElement moduleElement = doc.CreateElement("module");
assemblyElement.AppendChild(moduleElement);
moduleElement.SetAttribute("versionId", moduleGroup.Key.ModuleVersionId.ToString());
foreach (Type type in moduleGroup)
{
XmlElement typeElement = doc.CreateElement("type");
moduleElement.AppendChild(typeElement);
typeElement.AppendChild(doc.CreateTextNode(type.FullName));
}
}
}
doc.Save(output);
}
}