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

Error when Dispose is called on a MethodInvokation that delivers an IDisposable #40

Closed dscopra closed 7 years ago

dscopra commented 7 years ago
//somewhere in code
Box.AsDisposable().Dispose();

internal static class ObjectExtension {
        public static IDisposable AsDisposable(this object @object) {
        return new DisposableWrapper(@object);
    }
    private class DisposableWrapper : IDisposable {
        private readonly IDisposable _disposeable;

        public DisposableWrapper(object @object) {
            _disposeable = @object as IDisposable;
        }

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

image

BADF00D commented 7 years ago

Fixed in release 0.22