private void GenerateForeachStatement() { if (foreachVariable == null) { foreachVariable = new VariableDefinition(foreachVariableType, this.methodContext.Method); foreachVariableInstructions.Clear(); this.methodContext.VariablesToRename.Add(foreachVariable); } VariableDeclarationExpression vd = new VariableDeclarationExpression(foreachVariable, foreachVariableInstructions); Expression foreachCollectionExpression = foreachCollection.CloneAndAttachInstructions(foreachCollectionInstructions); if (foreachCollectionExpression is BaseReferenceExpression) { foreachCollectionExpression = new ThisReferenceExpression(this.methodContext.Method.DeclaringType, foreachCollectionExpression.UnderlyingSameMethodInstructions); } @foreach = new ForEachStatement(vd, foreachCollectionExpression, foreachBody, foreachConditionInstructions, theTry.Finally.UnderlyingSameMethodInstructions); GetCurrentFixer gcf = new GetCurrentFixer(theEnumerator, foreachVariable); gcf.Visit(@foreach); IsEnumeratorUsedVisitor enumeratorUsedVisitor = new IsEnumeratorUsedVisitor(theEnumerator); enumeratorUsedVisitor.Visit(@foreach); isEnumeratorUsedInsideForEach = enumeratorUsedVisitor.IsEnumeratorUsed; }
private void GenerateForeachStatement() { if (foreachVariable == null) { foreachVariable = new VariableDefinition(foreachVariableType); foreachVariableInstructions.Clear(); this.methodContext.VariablesToRename.Add(foreachVariable); } VariableDeclarationExpression vd = new VariableDeclarationExpression(foreachVariable, foreachVariableInstructions); Expression foreachCollectionExpression = foreachCollection.CloneAndAttachInstructions(foreachCollectionInstructions); if (foreachCollectionExpression is BaseReferenceExpression) { foreachCollectionExpression = new ThisReferenceExpression(this.methodContext.Method.DeclaringType, foreachCollectionExpression.UnderlyingSameMethodInstructions); } @foreach = new ForEachStatement(vd, foreachCollectionExpression, foreachBody, foreachConditionInstructions, theTry.Finally.UnderlyingSameMethodInstructions); GetCurrentFixer gcf = new GetCurrentFixer(theEnumerator, foreachVariable); gcf.Visit(@foreach); IsEnumeratorUsedVisitor enumeratorUsedVisitor = new IsEnumeratorUsedVisitor(theEnumerator); enumeratorUsedVisitor.Visit(@foreach); isEnumeratorUsedInsideForEach = enumeratorUsedVisitor.IsEnumeratorUsed; }