Exemplo n.º 1
0
        private void ProcessEnum(TypeScriptContext tsc, ModuleDeclaration module, HtmlNode h3, string name)
        {
            var div      = h3.ParentNode;
            var enumType = div.SelectSingleNode("*[@class='type-signature']")?.InnerText.Trim();
            var desc     = div.SelectNodes("p[not(@class)]").SanitizeDocumentation();

            TypeDeclaration td;
            ITypeScriptType ft;
            IList           fs;

            if (!StringEnumAsClass || enumType == null || enumType.Equals("number"))
            {
                var ed = new EnumDeclaration();
                td = ed;
                ft = ed;
                fs = ed.Members;
            }
            else
            {
                var ct = new ClassDeclaration();
                td = ct;
                ft = ResolveType(tsc, enumType).Type;
                fs = ct.Members;
            }
            td.IsExport = true;
            td.Name     = name;
            if (desc != null)
            {
                td.Documentation = new Documentation()
                {
                    Summary = desc
                };
            }
            module.Statements.Add(td);

            var e = new TypeEventArgs(td);

            TypeParsing?.Invoke(this, e);

            var trs = div.SelectNodes("section//table/tbody/tr");

            if (trs != null)
            {
                foreach (var tr in trs)
                {
                    var mn = tr.SelectSingleNode("td[1]")?.InnerText?.Trim();

                    if (mn != null)
                    {
                        var md = tr.SelectNodes("td[2]").SanitizeDocumentation();

                        var f = new FieldDeclaration();
                        f.AccessModifier = AccessModifier.Public;
                        f.IsStatic       = true;
                        f.Name           = mn;
                        f.FieldType      = ft;

                        if (md != null)
                        {
                            f.Documentation = new Documentation()
                            {
                                Summary = md
                            };
                        }

                        fs.Add(f);
                    }
                }
            }
            TypeParsed?.Invoke(this, e);
        }
Exemplo n.º 2
0
        private void ParseClassHtml(TypeScriptContext tsc, string fullName, string desc, HtmlNode section)
        {
            var cl = tsc.FindType(fullName) as ClassDeclaration;

            if (cl == null)
            {
                var i  = fullName.LastIndexOf('.');
                var md = tsc.GetModule(fullName.Substring(0, i));

                cl = new ClassDeclaration()
                {
                    Name     = fullName.Substring(i + 1),
                    IsExport = true
                };

                md.Statements.Add(cl);
            }

            if (cl.Documentation == null && desc != null)
            {
                cl.Documentation = new Documentation()
                {
                    Summary = desc
                };
            }

            var e = new TypeEventArgs(cl);

            TypeParsing?.Invoke(this, e);

            var headers = section.SelectNodes("//h2|//h3[@class='symbol-name']");

            if (headers != null)
            {
                var t = H2.None;
                foreach (var h in headers)
                {
                    if (h.Name.Equals("h2", StringComparison.InvariantCultureIgnoreCase))
                    {
                        switch (h.InnerText.Trim().ToLowerInvariant())
                        {
                        case "constructor":
                            t = H2.Constructor;
                            break;

                        case "enumerations":
                        case "enumeration":
                            t = H2.Enum;
                            break;

                        case "properties":
                        case "property":
                            t = H2.Property;
                            break;

                        case "methods":
                        case "method":
                            t = H2.Method;
                            break;

                        case "namespaces":
                        case "namespace":
                            t = H2.Namespace;
                            break;

                        default:
                            t = H2.None;
                            Debugger.Break();
                            break;
                        }
                    }
                    else
                    {
                        var sn = h.InnerText.Trim();
                        switch (t)
                        {
                        case H2.Constructor:
                            ProcessConstructor(tsc, cl, h, sn);
                            break;

                        case H2.Property:
                            ProcessProperty(tsc, cl, h, sn);
                            break;

                        case H2.Method:
                            ProcessMethod(tsc, cl, h, sn);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            TypeParsed?.Invoke(this, e);
        }