Helper for accessing return statements.
Inheritance: Helper
コード例 #1
0
        private static ExpressionStatementTranslationUnit CreateReturnStatement(ReturnStatement helper, SemanticModel semanticModel)
        {
            if (helper.Expression == null)
            {
                // Void return
                return ExpressionStatementTranslationUnit.CreateReturn();
            }

            var expression = new ExpressionTranslationUnitBuilder(helper.Expression, semanticModel).Build();
            return ExpressionStatementTranslationUnit.CreateReturn(expression as ExpressionTranslationUnit);
        }
コード例 #2
0
        /// <summary>
        /// Factory method for class <see cref="ExpressionStatementASTWalker"/>.
        /// </summary>
        /// <param name="node"><see cref="CSharpSyntaxNode"/> Used to initialize the walker.</param>
        /// <param name="semanticModel">The semantic model.</param>
        /// <returns></returns>
        public static ExpressionStatementASTWalker Create(CSharpSyntaxNode node, SemanticModel semanticModel = null)
        {
            // TODO: Use TranslationUnitFactory in order to have AST walkers decoupled from helpers
            //       via factories (which will be using helpers)

            ExpressionStatementTranslationUnit statement;

            // Return statement
            if (node as ReturnStatementSyntax != null)
            {
                var helper = new ReturnStatement(node as ReturnStatementSyntax, semanticModel);
                statement = CreateReturnStatement(helper, semanticModel);
            }
            // Throw statement
            else if (node as ThrowStatementSyntax != null)
            {
                var helper = new ThrowStatement(node as ThrowStatementSyntax, semanticModel);
                statement = CreateThrowStatement(helper, semanticModel);
            }
            // Other
            else if (node as ExpressionStatementSyntax != null)
            {
                var helper = new ExpressionStatement(node as ExpressionStatementSyntax, semanticModel);
                var expression = new ExpressionTranslationUnitBuilder(helper.Expression, semanticModel).Build();
                statement = ExpressionStatementTranslationUnit.Create(expression as ExpressionTranslationUnit);
            }
            else
            {
                throw new InvalidOperationException("Unrecognized statement!");
            }

            return new ExpressionStatementASTWalker(node, statement, semanticModel);
        }