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

Disposables in using within Action yield an error, but should not in version 0.22 #44

Closed dscopra closed 7 years ago

dscopra commented 7 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace Disposeables {
    class Program {
        static void Main(string[] args) {
            Func<MemoryStream> openStream = () => new MemoryStream();
            Action action = () => {
                using (var stream = CreateDisposable()) {}
            };
            Action action2 = () => {
                using (var stream2 = new MemoryStream()) {}
            };
            Action action3 = () => {
                using (new MemoryStream()) { }
            };
            Action action4 = () => {
                var stream4 = CreateDisposable();
                stream4.Dispose();
            };
        }

        private static MemoryStream CreateDisposable() {
            return new MemoryStream();
        }
    }
}

image