public TypeScriptLibrary Parse() { if (_lib == null) { _lib = new TypeScriptLibrary(); JObject jobject; foreach (var file in _files) { if (File.Exists(file)) { jobject = JObject.Parse(File.ReadAllText(file)); var package = new TypeScriptPackage(); LoadFromJObject(package, jobject); _lib.Packages.Add(package); } } } return(_lib); }
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>()); } } }