private static void TraverseNodesEnumDefinitions(XElement node, List <EnumDefinetion> list, ref bool inside) { if (node.Name == "h4") { if (node.Value == "C Specification") { inside = true; } } else if (node.Name == "code") { if (inside) { XAttribute attrClass = node.Attribute("class"); if (attrClass != null && attrClass.Value == "language-c++") { string v = node.Value; var item = new EnumDefinetion() { raw = v, }; list.Add(item); inside = false; } } } foreach (XElement item in node.Elements()) { TraverseNodesEnumDefinitions(item, list, ref inside); } }
public static void Dump() { XElement root = XElement.Load(filename); var lstDefinition = new List <EnumDefinetion>(); bool inside = false; TraverseNodesEnumDefinitions(root, lstDefinition, ref inside); var listEnumItemComment = new List <EnumItemComment>(); inside = false; TraverseNodesEnumItemComments(root, listEnumItemComment, ref inside); var lstEnumComment = new List <string>(); inside = false; TraverseNodesEnumComments(root, lstEnumComment, ref inside); using (var sw = new System.IO.StreamWriter("Enums.gen.cs")) { for (int i = 0; i < lstDefinition.Count; i++) { EnumDefinetion definition = lstDefinition[i]; //sw.WriteLine(definition.raw); string[] definitionLines = definition.Dump(); EnumItemComment itemComment = listEnumItemComment[i]; Dictionary <string, string> item2Comment = itemComment.Dump(); sw.WriteLine($"// Enum: {i}"); string enumComment = lstEnumComment[i]; sw.WriteLine($"/// <summary>{enumComment}</summary>"); { string line = definitionLines[0]; if (line.Contains("FlagBits")) { sw.WriteLine("[Flags]"); } sw.WriteLine(line); } for (int j = 1; j < definitionLines.Length - 1; j++) { string line = definitionLines[j]; if (item2Comment != null) { string strComment = ParseItemComment(line, item2Comment); if (strComment != string.Empty) { strComment = strComment.Replace("\r\n", "\n"); strComment = strComment.Replace("\r", "\n"); strComment = strComment.Replace("\n", $"{Environment.NewLine} /// "); strComment = Helper.RemoveBraces(strComment); sw.WriteLine($" /// <summary>{strComment}</summary>"); } } { string[] parts = line.Split("//", StringSplitOptions.RemoveEmptyEntries); sw.WriteLine(parts[0]); } } { string line = definitionLines[definitionLines.Length - 1]; sw.WriteLine(line); // } } } } Console.WriteLine("Done"); }