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

Support for Dispose-Pattern with Null-Propagation #71

Closed BADF00D closed 6 years ago

BADF00D commented 6 years ago

Prerequisites

Description

The creation of PortConfiguratorViewModel is marked as not disposed, besides it is disposed.

Source Code

namespace SomeNamespace.ViewModel
{
    internal class MainViewModel : IMainViewModel, IDisposable
    {
        public IPortConfiguratorViewModel PortConfigurator { get; }

        public MainViewModel()
        {
            var path = ConfigurationManager.AppSettings["SomeSetting"];
            var factory = new AppConfigRepositoryFactory();
            var repository = factory.Create(path);
            PortConfigurator = new PortConfiguratorViewModel(repository);
        }

        public void Dispose() {
            (PortConfigurator as IDisposable)?.Dispose();
        }
    }
}

Screenshot

image