Example #1
0
        private void LoadFromJObject(TypeScriptPackage package, JObject jobject)
        {
            if (jobject.TryGetValue("name", out var nameToken))
            {
                package.Name = nameToken.ToString();
            }


            if (jobject.TryGetValue("children", out var childrenToken))
            {
                //expects here extenral modules
                var children = childrenToken.ToObject <List <JObject> >();


                foreach (var child in children)
                {
                    var childKind = child["kind"].ToObject <TypeScriptTokenKind>();
                    if (childKind == TypeScriptTokenKind.Class)
                    {
                        var @class = new TypeScriptClass(package);
                        LoadFromJObject(@class, child);
                        package.Classes.Add(@class);
                    }
                    else if (childKind == TypeScriptTokenKind.Interface)
                    {
                        var @interface = new TypeScriptInterface(package);
                        LoadFromJObject(@interface, child);
                        package.Interfaces.Add(@interface);
                    }
                    else if (childKind == TypeScriptTokenKind.Function)
                    {
                        var function = new TypeScriptFunction(package);
                        LoadFromJObject(function, child);
                        package.Functions.Add(function);
                    }
                    else if (childKind == TypeScriptTokenKind.Namespace)
                    {
                        var @namespace = new TypeScriptNamespace(package);
                        LoadFromJObject(@namespace, child);
                        package.Namespaces.Add(@namespace);
                    }
                    else if (childKind == TypeScriptTokenKind.Enumeration)
                    {
                        var @enum = new TypeScriptEnumeration(package);
                        LoadFromJObject(@enum, child);
                        package.Enumerations.Add(@enum);
                    }
                    else if (childKind == TypeScriptTokenKind.Varialbe)
                    {
                        var @var = new TypeScriptVariable(package);
                        LoadFromJObject(var, child);
                        package.Variables.Add(@var);
                    }
                }


                if (jobject.TryGetValue("comment", out var commentToken))
                {
                    package.Comment = new TypeScriptComment();
                    LoadFromJObject(package.Comment, commentToken.ToObject <JObject>());
                }
            }
        }
Example #2
0
        private void LoadFromJObject(TypeScriptNamespace @namespace, JObject jobject)
        {
            if (jobject.TryGetValue("name", out var nameToken))
            {
                @namespace.Name = nameToken.ToString();;
            }

            if (jobject.TryGetValue("flags", out var flagsToken))
            {
                var flagsObj = flagsToken.ToObject <JObject>();

                if (flagsObj.TryGetValue("isExported", out var isExportedToken))
                {
                    @namespace.IsExported = isExportedToken.ToObject <bool>();
                }
            }

            if (jobject.TryGetValue("children", out var childrenToken))
            {
                var children = childrenToken.ToObject <List <JObject> >();

                foreach (var child in children)
                {
                    var childKind = child["kind"].ToObject <TypeScriptTokenKind>();
                    if (childKind == TypeScriptTokenKind.Class)
                    {
                        var @class = new TypeScriptClass(@namespace);
                        LoadFromJObject(@class, child);
                        @namespace.Classes.Add(@class);
                    }
                    else if (childKind == TypeScriptTokenKind.Interface)
                    {
                        var @interface = new TypeScriptInterface(@namespace);
                        LoadFromJObject(@interface, child);
                        @namespace.Interfaces.Add(@interface);
                    }
                    else if (childKind == TypeScriptTokenKind.Function)
                    {
                        var function = new TypeScriptFunction(@namespace);
                        LoadFromJObject(function, child);
                        @namespace.Functions.Add(function);
                    }
                    else if (childKind == TypeScriptTokenKind.Namespace)
                    {
                        var nspace = new TypeScriptNamespace(@namespace);
                        LoadFromJObject(nspace, child);
                        @namespace.Namespaces.Add(nspace);
                    }
                    else if (childKind == TypeScriptTokenKind.Enumeration)
                    {
                        var @enum = new TypeScriptEnumeration(@namespace);
                        LoadFromJObject(@enum, child);
                        @namespace.Enumerations.Add(@enum);
                    }
                    else if (childKind == TypeScriptTokenKind.Varialbe)
                    {
                        var @var = new TypeScriptVariable(@namespace);
                        LoadFromJObject(var, child);
                        @namespace.Variables.Add(@var);
                    }
                }
            }

            if (jobject.TryGetValue("comment", out var commentToken))
            {
                @namespace.Comment = new TypeScriptComment();
                LoadFromJObject(@namespace.Comment, commentToken.ToObject <JObject>());
            }
        }