Example #1
0
        /// <summary>
        /// Translate the unit into TypeScript.
        /// </summary>
        /// <returns></returns>
        public string Translate()
        {
            FormatWriter writer = new FormatWriter()
            {
                Formatter = this.Formatter
            };

            if (this.hasGet)
            {
                // Opening declaration: [<modifiers>] get <name>() : <type> {
                // TODO: Handle case of no visibility specified
                writer.WriteLine("{0}{1}{2} {3} {4}{5}",
                                 this.RenderedModifiers,
                                 this.RenderedGetterMethodName,
                                 Lexems.OpenRoundBracket + Lexems.CloseRoundBracket,
                                 Lexems.Colon,
                                 this.type.Translate(),
                                 this.hasSet ? Lexems.Semicolon : string.Empty); // TODO: Find a better way for this
            }

            if (this.hasSet)
            {
                var valueParameter = ArgumentDefinitionTranslationUnit.Create(
                    this.type, IdentifierTranslationUnit.Create("value"));

                // Opening declaration: [<modifiers>] set <name>(value : <type>) : void {
                // Emitting `void` in order to prevent errors in case of implicitAllowAny
                writer.WriteLine("{0}{1}{2}{3}{4} {5} {6}",
                                 this.RenderedModifiers,
                                 this.RenderedSetterMethodName,
                                 Lexems.OpenRoundBracket,
                                 valueParameter.Translate(),
                                 Lexems.CloseRoundBracket,
                                 Lexems.Colon,
                                 Lexems.VoidReturnType);
            }

            return(writer.ToString());
        }
Example #2
0
            /// <summary>
            /// Following typical scheme.
            /// </summary>
            /// <returns></returns>
            public string Translate()
            {
                FormatWriter writer = new FormatWriter()
                {
                    Formatter = this.Formatter
                };

                // Opening
                writer.WriteLine("{0} {1}",
                                 HeaderLexem,
                                 Lexems.OpenCurlyBracket);

                foreach (var translationUnit in this.innerUnits)
                {
                    writer.WriteLine("{0}",
                                     translationUnit.Translate());
                }

                // Closing
                writer.WriteLine("{0}",
                                 Lexems.CloseCurlyBracket);

                return(writer.ToString());
            }