Exemplo n.º 1
0
        private void ParseReturnTypes(HtmlDoc html_doc, HtmlNode table, Declaration decl)
        {
            var tr = table.Descendants("tr").FirstOrDefault(x => x.InnerText.StartsWith("Returns:"));

            if (tr == null)
            {
                return;
            }
            foreach (var dt in tr.Descendants("dt"))
            {
                var arg    = new Argument();
                var strong = dt.Descendants("strong").FirstOrDefault();
                if (strong != null)
                {
                    arg.Name = strong.InnerText;
                }
                var type_description = dt.Descendants("span")
                                       .First(span => span.Attributes["class"]?.Value == "classifier").InnerText;
                var type = type_description.Split(",").FirstOrDefault();
                arg.Type = InferType(type, arg);
                var dd = dt.NextSibling?.NextSibling;
                arg.Description = ParseDescription(dd);
                decl.Returns.Add(arg);
            }
        }
Exemplo n.º 2
0
        HtmlDoc GetHtml(string relative_url)
        {
            Console.WriteLine("Loading: " + relative_url);
            var doc = new HtmlDoc();

            doc.Filename = relative_url.Replace("/", "_");
            if (File.Exists(doc.Filename))
            {
                doc.Doc = new HtmlDocument();
                doc.Doc.Load(doc.Filename);
                doc.Text = doc.Doc.Text;
                return(doc);
            }
            var web = new HtmlWeb();

            doc.Doc  = web.Load(BaseUrl + relative_url);
            doc.Text = doc.Doc.Text;
            File.WriteAllText(doc.Filename, doc.Text);
            return(doc);
        }
Exemplo n.º 3
0
        private void ParseArguments(HtmlDoc html_doc, HtmlNode table, Declaration decl)
        {
            var tr = table.Descendants("tr").FirstOrDefault();

            if (tr == null)
            {
                return;
            }
            foreach (var dt in tr.Descendants("dt"))
            {
                var arg    = new Argument();
                var strong = dt.Descendants("strong").FirstOrDefault();
                if (strong == null)
                {
                    continue;
                }
                arg.Name = strong.InnerText;
                var type_description = dt.Descendants("span")
                                       .First(span => span.Attributes["class"]?.Value == "classifier").InnerText;
                var type = type_description.Split(",").FirstOrDefault();
                arg.Type = InferType(type, arg);
                if (type_description.Contains("optional"))
                {
                    arg.IsNamedArg = true;
                    arg.IsNullable = true;
                }
                if (type_description.Contains("default:"))
                {
                    arg.DefaultValue = InferDefaultValue(type_description.Split(",")
                                                         .First(x => x.Contains("default: ")).Replace("default: ", ""));
                }
                var dd = dt.NextSibling?.NextSibling;
                arg.Description = ParseDescription(dd);
                PostProcess(arg);
                decl.Arguments.Add(arg);
            }
        }