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

Missing CodeFix: Introduce field for local objects to dispose them. #75

Closed BADF00D closed 6 years ago

BADF00D commented 6 years ago

Prerequisites

Description

I want to have a CodeFix, that created a field/property for a local variable/anonymous object and dispose is in Dispose()-method.

Source Code

This code:

using System.IO;
namespace MyNamespace
{
    class MyClass
    {
        public MyClass()
        {
            var localVariable = new MemoryStream();
        }
    }
}

Should become:

using System;
using System.IO;

namespace MyNamespace
{
    class MyClass : IDisposable
    {
        private MemoryStream _field;

        public MyClass()
        {
            _field = new MemoryStream();
        }
        public void Dispose()
        {
            _field.Dispose();
        }
    }
}

Screenshot

none

BADF00D commented 6 years ago

Part of release 0.40.0