public override SyntaxList <StatementSyntax> VisitForEachBlock(VBSyntax.ForEachBlockSyntax node) { var stmt = node.ForEachStatement; TypeSyntax type = null; SyntaxToken id; if (stmt.ControlVariable is VBSyntax.VariableDeclaratorSyntax) { var v = (VBSyntax.VariableDeclaratorSyntax)stmt.ControlVariable; var declaration = CommonConversions.SplitVariableDeclarations(v).Values.Single(); type = declaration.Type; id = declaration.Variables[0].Identifier; } else { var v = (IdentifierNameSyntax)stmt.ControlVariable.Accept(_nodesVisitor); id = v.Identifier; type = SyntaxFactory.ParseTypeName("var"); } var block = SyntaxFactory.Block(node.Statements.SelectMany(s => s.Accept(CommentConvertingVisitor))); return(SingleStatement(SyntaxFactory.ForEachStatement( type, id, (ExpressionSyntax)stmt.Expression.Accept(_nodesVisitor), block.UnpackNonNestedBlock() ))); }
/// <summary> /// Yields a foreach(var loopVariable in loopedVariable) Statement /// </summary> /// <param name="loopVariable"></param> /// <param name="loopedVariable"></param> /// <param name="block"></param> /// <returns></returns> internal static ForEachStatementSyntax ForLoop(string loopVariable, string loopedVariable, List <StatementSyntax> block) { return (SF.ForEachStatement( SF.ParseTypeName("var"), loopVariable, SF.ParseExpression(loopedVariable), SF.Block(block) )); }
public override void Exit() { List <StatementSyntax> loopStatements = new List <StatementSyntax>(); //loopStatements.Add(StateHelper.MakeStatePushStatement()); loopStatements.Add(SF.ExpressionStatement( SF.AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, VariableHelper.MakeStateVariableExpression(_asVariableName), SF.IdentifierName(_iteratorVariableName) ) ) ); if (_hookName != null) { loopStatements.Add(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(_hookName, true))); } //loopStatements.Add(StateHelper.MakeStatePopWriteStatement()); var forEachStatement = SF.ForEachStatement(SF.ParseTypeName("var"), _iteratorVariableName, _expression, SF.Block(loopStatements)); _exitHandler(forEachStatement); }