void ProcessBlock(BlockStatement node) { for (int i = 0; i < node.Statements.Count - 1; i++) { var matcher = new UsingMatcher(node.Statements[i], node.Statements[i + 1]); if (!matcher.Match()) { continue; } if (matcher.VariableReference != null) { context.MethodContext.RemoveVariable(matcher.VariableReference); } if (matcher.RemoveExpression) { node.Statements.RemoveAt(i); // declaration node.Statements.RemoveAt(i); // try node.AddStatementAt(i, matcher.Using); } else { int index = i + (matcher.HasExpression ? 1 : 0); node.Statements.RemoveAt(index); // try node.AddStatementAt(index, matcher.Using); } ProcessBlock(matcher.Using.Body); } }
void ProcessBlock (BlockStatement node) { for (int i = 0; i < node.Statements.Count - 1; i++) { var matcher = new UsingMatcher(node.Statements[i], node.Statements[i + 1]); if (!matcher.Match ()) continue; if (matcher.VariableReference != null) { context.MethodContext.RemoveVariable(matcher.VariableReference); } if (matcher.RemoveExpression) { node.Statements.RemoveAt(i); // declaration node.Statements.RemoveAt(i); // try node.AddStatementAt(i, matcher.Using); } else { int index = i + (matcher.HasExpression ? 1 : 0); node.Statements.RemoveAt(index); // try node.AddStatementAt(index, matcher.Using); } ProcessBlock(matcher.Using.Body); } }