[x] I have verified that I am running the latest version of DisposableFixer: 1.1.2
[x] I have searched open and closed issues to ensure it has not already been reported
Description
When using CodeFix that disposes a member in Dispose method, a compilation error is introduced into the code. The Problem is that the implementation of the member is IDisposable, but the interface the member has does not.
Source Code
"Source" Soucecode
using System;
namespace SelectManyTest
{
internal class DisposeInDisposeMethod : IDisposable
{
private readonly ISomeInterface _sameInstance;
public DisposeInDisposeMethod()
{
_sameInstance = new SomeImplementation();//not disposed
}
public void Dispose()
{
}
}
public interface ISomeInterface
{
}
public class SomeImplementation : ISomeInterface, IDisposable
{
public void Dispose()
{
}
}
}
Becomes:
using System;
namespace SelectManyTest
{
internal class DisposeInDisposeMethod : IDisposable
{
private readonly ISomeInterface _sameInstance;
public DisposeInDisposeMethod()
{
_sameInstance = new SomeImplementation();
}
public void Dispose() {
_sameInstance?.Dispose();//compilation error
}
}
public interface ISomeInterface
{
}
public class SomeImplementation : ISomeInterface, IDisposable
{
public void Dispose()
{
}
}
}
But should become:
using System;
namespace SelectManyTest
{
internal class DisposeInDisposeMethod : IDisposable
{
private readonly ISomeInterface _sameInstance;
public DisposeInDisposeMethod()
{
_sameInstance = new SomeImplementation();
}
public void Dispose() {
(_sameInstance as IDisposable)?.Dispose();
}
}
public interface ISomeInterface
{
}
public class SomeImplementation : ISomeInterface, IDisposable
{
public void Dispose()
{
}
}
}
Prerequisites
Description
When using CodeFix that disposes a member in Dispose method, a compilation error is introduced into the code. The Problem is that the implementation of the member is IDisposable, but the interface the member has does not.
Source Code
"Source" Soucecode
Becomes:
But should become:
Screenshot