Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="list"></param>
        /// <param name="inside"></param>
        private static void TraverseItemComments(XElement node, List <PFNItemComment> list, ref bool inside)
        {
            if (node.Name == "h4")
            {
                if (node.Value == "Parameters")
                {
                    inside = true;
                    var comment = new PFNItemComment();
                    list.Add(comment);
                }
                else if (node.Value == "Description")
                {
                    inside = false;
                }
            }
            else if (node.Name == "p")
            {
                if (inside)
                {
                    PFNItemComment 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())
            {
                TraverseItemComments(item, list, ref inside);
            }
        }
Exemple #2
0
        public static void Dump()
        {
            XElement root = XElement.Load(filename);
            var      lstDefinition = new List <PFNDefinition>(); bool inside = false;

            TraverseDefinitions(root, lstDefinition, ref inside);
            var lstItemComment = new List <PFNItemComment>(); inside = false;

            TraverseItemComments(root, lstItemComment, ref inside);
            var lstComment = new List <string>(); inside = false;

            TraverseComments(root, lstComment, ref inside);

            using (var sw = new System.IO.StreamWriter("PFNs.gen.cs")) {
                for (int i = 0; i < lstDefinition.Count; i++)
                {
                    PFNDefinition definition = lstDefinition[i];
                    //sw.WriteLine(definition.raw);
                    string[]       definitionLines           = definition.Dump();
                    PFNItemComment itemComment               = lstItemComment[i];
                    Dictionary <string, string> item2Comment = itemComment.Dump();

                    sw.WriteLine($"// PFN: {i}");
                    string comment = lstComment[i];
                    sw.WriteLine($"/// <summary>{comment}</summary>");
                    {
                        string line = definitionLines[0];
                        sw.WriteLine(line); // public unsafe delegate ...
                    }
                    for (int j = 1; j < definitionLines.Length; 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>");
                            }
                        }
                        {
                            line = line.Trim();
                            var l = line.Replace("const char* ", "IntPtr ");
                            l = l.Replace("const*", "/*-const-*/ *");
                            l = l.Replace("const ", "/*-const-*/ ");
                            l = l.Replace(" const", " /*-const-*/");
                            l = l.Replace("size_t ", "Int32 ");
                            l = l.Replace("uint8_t* ", "byte* ");
                            l = l.Replace("uint8_t ", " byte ");
                            l = l.Replace("uint16_t* ", "UInt16* ");
                            l = l.Replace("uint16_t ", "UInt16 ");
                            l = l.Replace("uint32_t* ", "UInt32* ");
                            l = l.Replace("uint32_t ", "UInt32 ");
                            l = l.Replace("uint64_t* ", "UInt64* ");
                            l = l.Replace("uint64_t ", "UInt64 ");
                            l = l.Replace("int32_t* ", "Int32* ");
                            l = l.Replace("int32_t ", "Int32 ");
                            l = l.Replace("int64_t* ", "Int64* ");
                            l = l.Replace("int64_t ", "Int64 ");
                            l = l.Replace("struct ", "/* struct */ ");
                            l = l.Replace(" object", " _object");
                            l = l.Replace(" event", " _event");
                            l = "    " + l;
                            sw.WriteLine(l);
                        }
                    }
                    if (definitionLines.Length < 2)
                    {
                        sw.WriteLine(");");
                    }
                }
            }
            Console.WriteLine("Done");
        }