Esempio n. 1
0
        public string Expand()
        {
            var tryStatements = _statement.TryStatements.GetStatementsFromCollection(_statementFactory, _options);
            var tryClause     = $"try {{{tryStatements}{Environment.NewLine}}}";

            var catchClauses = _statement.CatchClauses
                               .OfType <CodeCatchClause>()
                               .Select(clause =>
            {
                var type            = _typescriptTypeMapper.GetTypeOutput(clause.CatchExceptionType);
                var catchStatements = clause.Statements.GetStatementsFromCollection(_statementFactory, _options);
                return($"catch({clause.LocalName}: {type}){{{catchStatements}{Environment.NewLine}}}");
            })
                               .Aggregate((previous, current) => $"{previous}{Environment.NewLine}{current}");

            string finallyClause = string.Empty;

            if (_statement.FinallyStatements != null && _statement.FinallyStatements.Count > 1)
            {
                var finallyStatements = _statement.FinallyStatements.GetStatementsFromCollection(_statementFactory,
                                                                                                 _options);
                finallyClause = $"finally {{{finallyStatements}{Environment.NewLine}}}";
            }

            return($"{tryClause}{catchClauses}{finallyClause}");
        }
Esempio n. 2
0
        public string Expand()
        {
            var type = _typescriptTypeMapper.GetTypeOutput(_statement.Type);
            var initializationExpression = _expressionFactory.GetExpression(_statement.InitExpression, _options).Evaluate();

            return($"{_options.IndentString}{_options.IndentString}{_options.IndentString}var {_statement.Name}: {type} = {initializationExpression};}}");
        }