BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

Add CodeFix to dispose local variables via Dispose after last usage #79

Closed BADF00D closed 6 years ago

BADF00D commented 6 years ago

Prerequisites

Description

On a local undisposed variable there should be a codeFix available, that disposes the variable after the last usage. See code for example.

Source Code

This code:

using System.IO;

namespace SomeNamespace {
    internal class SomeClass {
        public void SomeMethod() {
            var memoryStream = new MemoryStream();
            var x = 0;
            var y = 1;
            memoryStream.Seek(0, SeekOrigin.Begin);
            var z = 2;
        }
    }
}

Should become:

using System.IO;

namespace SomeNamespace {
    internal class SomeClass {
        public void SomeMethod() {
            var memoryStream = new MemoryStream();
            var x = 0;
            var y = 1;
            memoryStream.Seek(0, SeekOrigin.Begin);
            memoryStream.Dispose();
            var z = 2;
        }
    }
}

Screenshot

BADF00D commented 6 years ago

Will be part of release 1.1.0