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

Applying a CodeFix that add a Dispose-Call for a member causes an error #98

Closed BADF00D closed 5 years ago

BADF00D commented 5 years ago

Prerequisites

Description

When applying CodeFix, that adds a Dispose-Call for a member in class ''A'', and the class hat a inner class ''B'' with a Dispose-Method, then the Dispose-Call for the member is added to Dispose-Method in class ''B''

Source Code

using System;
using System.IO;

namespace ExtensionMethodYieldsNotDisposed
{
    internal class Class1
    {
        public IDisposable MemoryStream { get; }

        public Class1()
        {
            MemoryStream = new MemoryStream();
        }

        private class InnerClassWithDisposeMethod
        {
            public void Dispose(){}
        }
    }
}

Becomes:

using System;
using System.IO;

namespace ExtensionMethodYieldsNotDisposed
{
    internal class Class1 : IDisposable {
        public IDisposable MemoryStream { get; }

        public Class1()
        {
            MemoryStream = new MemoryStream();
        }

        private class InnerClassWithDisposeMethod
        {
            public void Dispose() {
                MemoryStream?.Dispose();
            }
        }
    }
}

But should become:

using System;
using System.IO;

namespace ExtensionMethodYieldsNotDisposed
{
    internal class Class1
    {
        public IDisposable MemoryStream { get; }

        public Class1()
        {
            MemoryStream = new MemoryStream();
        }

        private class InnerClassWithDisposeMethod
        {
            public void Dispose(){}
        }

        public void Dispose()
        {
            MemoryStream?.Dispose();
        }
    }
}
BADF00D commented 5 years ago

Will be part of release 1.2.0