Browse Source

Fixed bug in UseExplicitTypeAction. Now, anonymous arrays are correctly excluded.

pull/32/merge
Luís Reis 12 years ago
parent
commit
eee49d9d35
  1. 15
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitTypeAction.cs

15
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitTypeAction.cs

@ -51,8 +51,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -51,8 +51,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
type = context.Resolve(foreachStatement.VariableType).Type;
node = foreachStatement;
}
if (!(!type.Equals(SpecialType.NullType) && !type.Equals(SpecialType.UnknownType) && type.Kind != TypeKind.Anonymous)) {
if (!(!type.Equals(SpecialType.NullType) && !type.Equals(SpecialType.UnknownType) && !ContainsAnonymousType(type))) {
yield break;
}
yield return new CodeAction (context.TranslateString("Use explicit type"), script => {
@ -64,7 +64,16 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -64,7 +64,16 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}, node);
}
static bool ContainsAnonymousType (IType type)
{
if (type.Kind == TypeKind.Anonymous)
return true;
var arrayType = type as ArrayType;
return arrayType != null && ContainsAnonymousType (arrayType.ElementType);
}
static readonly AstType varType = new SimpleType ("var");
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context)

Loading…
Cancel
Save