public override void VisitWhileStatement(WhileStatement node) { if (foundEnumeratorAssignment && insideTry) { if (IsForeach(node)) { BlockStatement tryParent = theTry.Parent as BlockStatement; if (tryParent == null || tryParent != enumeratorAssignmentStatement.Parent || tryParent.Statements.IndexOf(enumeratorAssignmentStatement) + 1 != tryParent.Statements.IndexOf(theTry)) { ClearState(); base.VisitWhileStatement(node); return; } foreachConditionInstructions = node.Condition.UnderlyingSameMethodInstructions; foundWhile = true; shouldAdd = true; foreach (Statement st in node.Body.Statements) { if (!(st is ExpressionStatement)) { foreachBody.AddStatement(st); //TODO: Must traverse the statement tree, in order to find GetCurrent method and obtain the type of the foreach } else { VisitExpressionStatement(st as ExpressionStatement); } if (foreachVariableType == null) { ForeachElementTypeFinder fet = new ForeachElementTypeFinder(theEnumerator); fet.Visit(st); foreachVariableType = fet.ResultingType; } } if (foreachVariableType != null) { AttachForeach(); if (isEnumeratorUsedInsideForEach) { ClearState(); base.VisitWhileStatement(node); } } else { //this can happen if enumerator.get_Current is not called anywhere in the loop. //in this case there is no foreach. //think of a better way to ClearState(); base.VisitWhileStatement(node); } } else { ClearState(); base.VisitWhileStatement(node); } } else { base.VisitWhileStatement(node); } }
public override void VisitWhileStatement(WhileStatement node) { if (foundEnumeratorAssignment && insideTry) { if (IsForeach(node)) { BlockStatement tryParent = theTry.Parent as BlockStatement; if (tryParent == null || tryParent != enumeratorAssignmentStatement.Parent || tryParent.Statements.IndexOf(enumeratorAssignmentStatement) + 1 != tryParent.Statements.IndexOf(theTry)) { ClearState(); base.VisitWhileStatement(node); return; } foreachConditionInstructions = node.Condition.UnderlyingSameMethodInstructions; foundWhile = true; shouldAdd = true; foreach (Statement st in node.Body.Statements) { if (!(st is ExpressionStatement)) { foreachBody.AddStatement(st); //TODO: Must traverse the statement tree, in order to find GetCurrent method and obtain the type of the foreach } else { VisitExpressionStatement(st as ExpressionStatement); } if (foreachVariableType == null) { ForeachElementTypeFinder fet = new ForeachElementTypeFinder(theEnumerator); fet.Visit(st); foreachVariableType = fet.ResultingType; } } if (foreachVariableType != null) { AttachForeach(); if (isEnumeratorUsedInsideForEach) { ClearState(); base.VisitWhileStatement(node); } } else { //this can happen if enumerator.get_Current is not called anywhere in the loop. //in this case there is no foreach. //think of a better way to ClearState(); base.VisitWhileStatement(node); } } else { ClearState(); base.VisitWhileStatement(node); } } else { base.VisitWhileStatement(node); } }