private async Task<string> GenerateTypesAsync(Document document, SyntaxNode node, CancellationToken cancellationToken) { // Track the types that have already been exported var exportedNodes = new List<INamedTypeSymbol>(); var nodes = node.Traverse().Where(n => { return n is TypeDeclarationSyntax; //|| n is InterfaceDeclarationSyntax; }); //var interfaces = nodes.OfType<InterfaceDeclarationSyntax>().ToArray(); var types = nodes.OfType<TypeDeclarationSyntax>().ToArray(); var sb = new System.Text.StringBuilder(); var comp = await document.Project.GetCompilationAsync(); foreach (var typeDec in types) { var NamespaceDec = typeDec.BottomUpFirstOfType<NamespaceDeclarationSyntax>(); sb.AppendLine($"declare module {NamespaceDec.GetFullName()} {{"); var si = comp.GetTypeByMetadataName(NamespaceDec.GetFullName() + "." + typeDec.Identifier.Text); exportedNodes.Add(si); exportedNodes.Add(si.BaseType); exportedNodes.AddRange(si.Interfaces); sb.Append($"\texport class {typeDec.Identifier.Text}"); if (si.BaseType != null) { sb.Append(" extends "); if (!si.BaseType.CanBeReferencedByName) sb.Append(si.BaseType.ContainingNamespace + "."); sb.Append(si.BaseType.Name); sb.AppendLine(" {{"); } foreach (var member in typeDec.Members) { if (member is FieldDeclarationSyntax) { var field = member as FieldDeclarationSyntax; var fieldIdentifier = field.Declaration.Variables.FirstOrDefault().Identifier; //fieldIdentifier.Value string type = GetTypeScriptEquivalentType(field.Declaration.Type); sb.AppendLine($"\t\t{fieldIdentifier.Text}: {type};"); } else if (member is PropertyDeclarationSyntax) { var property = member as PropertyDeclarationSyntax; //var fieldIdentifier = property..FirstOrDefault().Identifier; //fieldIdentifier.Value var accessor = property.Modifiers.Any(z => string.Equals(z.Text, "public")) ? "public" : "private"; string type = GetTypeScriptEquivalentType(property.Type); sb.AppendLine($"\t\t{accessor} {property.Identifier.Text}: {type};"); } } sb.AppendLine("\t}"); sb.AppendLine("}"); } var grouped = exportedNodes.GroupBy(x => x.ContainingNamespace); return sb.ToString(); }