public void AddSymbolDocItem(DocItem item, List <Tuple <string, XElement> > namespaces, string[] namespaceNames) { var lastNamespace = namespaces.LastOrDefault(); AddSymbolDocItem(item, (lastNamespace == null ? null : lastNamespace.Item2), namespaceNames); }
static void BuildItems(DocItem docItem, XElement docXml, List <Tuple <string, XElement> > namespaces) { switch (docXml.Name.ToString()) { case "cppdoc": { foreach (var subXml in docXml.Elements()) { BuildItems(docItem, subXml, namespaces); } } break; case "namespace": { namespaces.Add(Tuple.Create(docXml.Attribute("name").Value, docXml)); foreach (var subXml in docXml.Elements()) { BuildItems(docItem, subXml, namespaces); } namespaces.RemoveAt(namespaces.Count - 1); } break; case "enum": { string typeName = docXml.Attribute("name").Value; string fullName = docXml.Attribute("fullName").Value; string[] namespaceNames = null; Tuple <string, XElement> lastNamespace = null; if (typeName == "Type" && namespaces.Count > 0) { var siblings = docXml.Parent.Elements().ToArray(); if (siblings.Length != 1 && siblings[0] != docXml) { throw new ArgumentException(); } typeName = namespaces.Last().Item1 + "::" + typeName; lastNamespace = namespaces.Take(namespaces.Count - 1).LastOrDefault(); namespaceNames = namespaces.Take(namespaces.Count - 1).Select(t => t.Item1).ToArray(); } else { lastNamespace = namespaces.LastOrDefault(); namespaceNames = namespaces.Select(t => t.Item1).ToArray(); } DocItem typeItem = new DocItem() { Name = "enum_" + fullName.Replace("::", "_"), UniqueId = "enum:" + fullName, Title = "enum " + typeName, Content = docXml, }; docItem.AddSymbolDocItem(typeItem, (lastNamespace == null ? null : lastNamespace.Item2), namespaceNames); } break; case "type": { string typeName = docXml.Attribute("name").Value; string fullName = docXml.Attribute("fullName").Value; string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray(); DocItem typeItem = new DocItem() { Name = "type_" + fullName.Replace("::", "_"), UniqueId = "type:" + fullName, Title = "class " + typeName, Content = docXml, }; docItem.AddSymbolDocItem(typeItem, namespaces, namespaceNames); foreach (var subXml in docXml.Elements()) { BuildItems(typeItem, subXml, namespaces); } } break; case "functionGroup": { var functions = docXml.Elements().ToArray(); if (functions.Length == 1) { BuildItems(docItem, functions[0], namespaces); } else { if (functions.Length == 0) { throw new ArgumentException(); } string functionName = docXml.Attribute("name").Value; string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray(); string nameBody = ""; string uniqueIdBody = ""; if (docItem.Parent == null) { string[] names = namespaceNames.Where(s => s != "").ToArray(); if (names.Length > 0) { nameBody = names.Aggregate((a, b) => a + "_" + b); uniqueIdBody = names.Aggregate((a, b) => a + "::" + b); } } else { nameBody = docItem.NameBody; uniqueIdBody = docItem.UniqueIdBody; } DocItem functionItem = new DocItem() { Name = "functionGroup_" + nameBody + "_" + functionName, UniqueId = "functionGroup:" + uniqueIdBody + "::" + functionName, Title = "overloaded functions " + functionName, Content = docXml, }; docItem.AddSymbolDocItem(functionItem, namespaces, namespaceNames); foreach (var subXml in functions) { BuildItems(functionItem, subXml, namespaces); } } } break; case "function": { string functionName = docXml.Attribute("name").Value; string fullName = docXml.Attribute("fullName").Value; string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray(); if (functionName == fullName && docItem.Parent != null) { fullName = docItem.UniqueIdBody + "::" + functionName; } DocItem functionItem = new DocItem() { Name = "function_" + fullName.Replace("::", "_"), UniqueId = "function:" + fullName, Title = "function " + functionName, Content = docXml, }; docItem.AddSymbolDocItem(functionItem, namespaces, namespaceNames); } break; case "document": { if (docItem.Document != null) { throw new ArgumentException(); } if (!docItem.UniqueId.StartsWith("enum:") && !docItem.UniqueId.StartsWith("type:") && !docItem.UniqueId.StartsWith("function:")) { throw new ArgumentException(); } docItem.Document = docXml; } break; case "baseType": break; default: throw new ArgumentException(); } }