Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Use better checking for special types in PutInsideUsing & IterateViaF…
Browse files Browse the repository at this point in the history
…oreach
  • Loading branch information
Novakov committed Sep 1, 2015
1 parent 74fba28 commit 9c89819
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
Expand Up @@ -28,7 +28,7 @@ protected override IEnumerable<CodeAction> GetActions(Document document, Semanti
if (symbol == null)
yield break;

if (!IsDisposable(semanticModel, symbol.Type))
if (!symbol.Type.ImplementsSpecialTypeInterface(SpecialType.System_IDisposable))
yield break;

var containingBlock = node.GetAncestor<BlockSyntax>();
Expand Down Expand Up @@ -185,20 +185,5 @@ private static bool IsEndingWithDispose(SemanticModel semanticModel, List<Statem

return true;
}

private static bool IsDisposable(SemanticModel semanticModel, ITypeSymbol type)
{
var disposable = semanticModel.Compilation.GetSpecialType(SpecialType.System_IDisposable);

if (type.GetAllInterfacesIncludingThis().Contains(disposable))
return true;

var parameterType = type as ITypeParameterSymbol;

if (parameterType != null && parameterType.ConstraintTypes.Any(x => IsDisposable(semanticModel, x)))
return true;

return false;
}
}
}
4 changes: 2 additions & 2 deletions RefactoringEssentials/Util/ITypeSymbolExtensions.cs
Expand Up @@ -1147,8 +1147,8 @@ public static ITypeSymbol RemoveNullableIfPresent(this ITypeSymbol symbol)
}

public static bool IsIEnumerable(this ITypeSymbol typeSymbol)
{
return typeSymbol.GetAllInterfacesIncludingThis().Any(x => x.SpecialType == SpecialType.System_Collections_IEnumerable);
{
return typeSymbol.ImplementsSpecialTypeInterface(SpecialType.System_Collections_IEnumerable);
}
}
}
Expand Down

0 comments on commit 9c89819

Please sign in to comment.