|
|
|
|
@ -53,29 +53,37 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -53,29 +53,37 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
var id2 = id1.Clone(); |
|
|
|
|
var id3 = id1.Clone(); |
|
|
|
|
|
|
|
|
|
var variableDeclarationStatement = new VariableDeclarationStatement( |
|
|
|
|
foreachStatement.VariableType.Clone(), |
|
|
|
|
foreachStatement.VariableName, |
|
|
|
|
new IndexerExpression(foreachStatement.InExpression.Clone(), id3) |
|
|
|
|
); |
|
|
|
|
var forStatement = new ForStatement() { |
|
|
|
|
Initializers = { initializer }, |
|
|
|
|
Condition = new BinaryOperatorExpression (id1, BinaryOperatorType.LessThan, new MemberReferenceExpression (foreachStatement.InExpression.Clone (), countProperty)), |
|
|
|
|
Iterators = { new ExpressionStatement (new UnaryOperatorExpression (UnaryOperatorType.PostIncrement, id2)) }, |
|
|
|
|
EmbeddedStatement = new BlockStatement { |
|
|
|
|
new VariableDeclarationStatement (foreachStatement.VariableType.Clone (), foreachStatement.VariableName, new IndexerExpression (foreachStatement.InExpression.Clone (), id3)) |
|
|
|
|
variableDeclarationStatement |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (foreachStatement.EmbeddedStatement is BlockStatement) { |
|
|
|
|
foreach (var child in ((BlockStatement)foreachStatement.EmbeddedStatement).Statements) { |
|
|
|
|
forStatement.EmbeddedStatement.AddChild (child.Clone (), BlockStatement.StatementRole); |
|
|
|
|
variableDeclarationStatement.Remove(); |
|
|
|
|
var oldBlock = (BlockStatement)foreachStatement.EmbeddedStatement.Clone(); |
|
|
|
|
if (oldBlock.Statements.Any()) { |
|
|
|
|
oldBlock.Statements.InsertBefore(oldBlock.Statements.First(), variableDeclarationStatement); |
|
|
|
|
} else { |
|
|
|
|
oldBlock.Statements.Add(variableDeclarationStatement); |
|
|
|
|
} |
|
|
|
|
forStatement.EmbeddedStatement = oldBlock; |
|
|
|
|
} else { |
|
|
|
|
forStatement.EmbeddedStatement.AddChild (foreachStatement.EmbeddedStatement.Clone (), BlockStatement.StatementRole); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
script.Replace (foreachStatement, forStatement); |
|
|
|
|
script.Link (initializer.Variables.First ().NameToken, id1, id2, id3); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static string GetCountProperty(IType type) |
|
|
|
|
{ |
|
|
|
|
if (type.Kind == TypeKind.Array) { |
|
|
|
|
|