public static MappedTypeScriptClass Convert( Type type, ICollection <Type> currentTypes, ICollection <Type> referencedTypes, ICollection <Type> unMappedDependencies) { var output = new MappedTypeScriptClass(); var properties = type .GetProperties( BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); output.Name = type.Name; output.Members = properties .Select(o => Convert(o, currentTypes, referencedTypes, unMappedDependencies)); var imports = new List <MappedImport>(); foreach (var imported in output.Members.Where(o => o.IsImport)) { imports.Add(new MappedImport(imported.Type)); } output.Imports = imports; return(output); }
public static StringBuilder BuildTypeScriptClass(MappedTypeScriptClass source) { var output = new StringBuilder(); foreach (var import in source.Imports) { output.AppendLine($"import {{ {import.Name} }} from './{import.Name}';"); } if (source.Imports.Any()) { output.AppendLine(); } output.AppendLine($"export class {source.Name} {{"); foreach (var property in source.Members) { var alternates = string.Join(" | ", property.AlternateTypes); output.Append(DefaultIndent); output.Append($"{property.Scope} "); output.Append($"{property.Name}"); output.Append($"{(property.IsNullable ? "?" : "")}: "); output.Append($"{property.Type}"); output.Append($"{(alternates.Length > 0 ? " | " + alternates : null)}"); output.Append($"{(property.IsArray ? "[]" : "")}"); output.Append($" = "); output.Append($"{property.Initialiser};"); output.AppendLine(); } output.AppendLine($"}}"); return(output); }