Ejemplo n.º 1
0
        private static List <List <StatementSyntax> > GetStatementsInBlocksAfter(StatementSyntax node)
        {
            var collectionOfStatements = new List <List <StatementSyntax> >();
            var method = node.FirstAncestorOrSelf <MethodDeclarationSyntax>();

            if (method?.Body == null)
            {
                return(collectionOfStatements);
            }
            var currentBlock = node.FirstAncestorOfType <BlockSyntax>();

            while (currentBlock != null)
            {
                var statements = new List <StatementSyntax>();
                foreach (var statement in currentBlock.Statements)
                {
                    if (statement.SpanStart > node.SpanStart)
                    {
                        statements.Add(statement);
                    }
                }
                if (statements.Any())
                {
                    collectionOfStatements.Add(statements);
                }
                if (method.Body.Equals(currentBlock))
                {
                    break;
                }
                currentBlock = currentBlock.FirstAncestorOfType <BlockSyntax>();
            }
            return(collectionOfStatements);
        }
 private static List<List<StatementSyntax>> GetStatementsInBlocksAfter(StatementSyntax node)
 {
     var collectionOfStatements = new List<List<StatementSyntax>>();
     var method = node.FirstAncestorOrSelf<MethodDeclarationSyntax>();
     if (method?.Body == null) return collectionOfStatements;
     var currentBlock = node.FirstAncestorOfType<BlockSyntax>();
     while (currentBlock != null)
     {
         var statements = new List<StatementSyntax>();
         foreach (var statement in currentBlock.Statements)
             if (statement.SpanStart > node.SpanStart)
                 statements.Add(statement);
         if (statements.Any()) collectionOfStatements.Add(statements);
         if (method.Body.Equals(currentBlock)) break;
         currentBlock = currentBlock.FirstAncestorOfType<BlockSyntax>();
     }
     return collectionOfStatements;
 }