/// <summary> /// /// </summary> /// <param name="translationUnit"></param> public void AddInterface(ITranslationUnit translationUnit) { if (translationUnit == null) { throw new ArgumentNullException(nameof(translationUnit)); } if (translationUnit as NestedElementTranslationUnit != null) { ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1; } // Interfaces need injection for observing indentation if (translationUnit as ITranslationInjector != null) { ((ITranslationInjector)translationUnit).InjectedTranslationUnitBefore = IdentifierTranslationUnit.Create(Lexems.ExportKeyword); } ((List <ITranslationUnit>) this.interfaces).Add(translationUnit); }
/// <summary> /// Translate the unit into TypeScript. /// </summary> /// <returns></returns> public string Translate() { FormatWriter writer = new FormatWriter() { Formatter = this.Formatter }; // Opening declaration writer.WriteLine("{0} {1} {2} {3}", text => ClassDeclarationCodePerfect.RefineDeclaration(text), Lexems.ExportKeyword, Lexems.ModuleKeyword, this.name.Translate(), Lexems.OpenCurlyBracket); // We render classes first foreach (ITranslationUnit translationUnit in this.classes) { if (translationUnit as NestedElementTranslationUnit != null) { ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1; } // Classes need injection for observing indentation if (translationUnit as ITranslationInjector != null) { ((ITranslationInjector)translationUnit).InjectedTranslationUnitBefore = IdentifierTranslationUnit.Create(Lexems.ExportKeyword); } writer.WriteLine(translationUnit.Translate()); } // Then, interfaces foreach (ITranslationUnit translationUnit in this.interfaces) { if (translationUnit as NestedElementTranslationUnit != null) { ((NestedElementTranslationUnit)translationUnit).NestingLevel = this.NestingLevel + 1; } writer.WriteLine("{0} {1}", Lexems.ExportKeyword, translationUnit.Translate()); } // Closing declaration writer.WriteLine("{0}", Lexems.CloseCurlyBracket); return(writer.ToString()); }