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

Assigning an IDisposable to anothers class property should yield an warning #137

Closed BADF00D closed 4 years ago

BADF00D commented 4 years ago

Prerequisites

Description

It should be possible to mark a property as tracking, in order to allow assignments from its public settings from other classes.

Source Code

using System;
using System.IO;

namespace MyNamespace
{
    class ClassWithPublicSetableProperty : IDisposable
    {

        public IDisposable MemoryStream { get; set; }

        public void Dispose()
        {
            MemoryStream?.Dispose();
        }
    }

    class MyClass
    {
        public MyClass()
        {
            using (var instance = new ClassWithPublicSetableProperty())
            {
                instance.MemoryStream = new MemoryStream();//should generate a warning about not disposed property of other object
            }
        }
    }
}

Screenshot

BADF00D commented 4 years ago

There are some new diagnostics that warn about this situation.