Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="list"></param>
        /// <param name="inside"></param>
        private static void TraverseNodesEnumItemComments(XElement node, List <EnumItemComment> list, ref bool inside)
        {
            if (node.Name == "h4")
            {
                if (node.Value == "Description")
                {
                    inside = true;
                    var comment = new EnumItemComment();
                    list.Add(comment);
                }
                else if (node.Value == "See Also")
                {
                    inside = false;
                }
            }
            else if (node.Name == "p")
            {
                if (inside)
                {
                    EnumItemComment comment = list[list.Count - 1];
                    string          text    = node.ToString();
                    text = text.Substring("<p>".Length, text.Length - "<p></p>".Length);
                    text = text.Trim();
                    comment.lstComment.Add(text);
                }
            }

            foreach (XElement item in node.Elements())
            {
                TraverseNodesEnumItemComments(item, list, ref inside);
            }
        }
Example #2
0
        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");
        }