private void AttachForeach() { GenerateForeachStatement(); if (!isEnumeratorUsedInsideForEach) { BlockStatement parentBlock = theTry.Parent as BlockStatement; parentBlock.Statements.Remove(enumeratorAssignmentStatement); int tryIndex = parentBlock.Statements.IndexOf(theTry); parentBlock.Statements.RemoveAt(tryIndex); parentBlock.AddStatementAt(tryIndex, @foreach); YieldStateMachineCodeRemover ysmcr = new YieldStateMachineCodeRemover(@foreach, theEnumerator); ysmcr.ProcessForEachStatement(); CopyLabel(); CheckVariable(); ClearState(); VisitForEachStatement(parentBlock.Statements[tryIndex] as ForEachStatement); } }