Benutomo.AutomaticDisposeImpl.SourceGenerator 0.0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Benutomo.AutomaticDisposeImpl.SourceGenerator --version 0.0.0.1
NuGet\Install-Package Benutomo.AutomaticDisposeImpl.SourceGenerator -Version 0.0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Benutomo.AutomaticDisposeImpl.SourceGenerator" Version="0.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Benutomo.AutomaticDisposeImpl.SourceGenerator --version 0.0.0.1
#r "nuget: Benutomo.AutomaticDisposeImpl.SourceGenerator, 0.0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Benutomo.AutomaticDisposeImpl.SourceGenerator as a Cake Addin
#addin nuget:?package=Benutomo.AutomaticDisposeImpl.SourceGenerator&version=0.0.0.1

// Install Benutomo.AutomaticDisposeImpl.SourceGenerator as a Cake Tool
#tool nuget:?package=Benutomo.AutomaticDisposeImpl.SourceGenerator&version=0.0.0.1

A simple example of use

This is an experimental library, so there is no detailed documentation. Here is a simple example of how to use it.

SampleCode


namespace SampleCode
{
    class ConsoleOutputDisposable : IDisposable
    {
        public void Dispose()
        {
            Console.WriteLine("    Called Dispose() of ConsoleOutputDisposable.");
        }
    }

    class ConsoleOutputAsyncDisposable : IDisposable, IAsyncDisposable
    {
        public void Dispose()
        {
            Console.WriteLine("    Called Dispose() of ConsoleOutputAsyncDisposable.");
        }

        public ValueTask DisposeAsync()
        {
            Console.WriteLine("    Called DisposeAsync() of ConsoleOutputAsyncDisposable.");
            return default;
        }
    }

    [Benutomo.AutomaticDisposeImpl(ReleaseUnmanagedResourcesMethod = nameof(ReleaseUnmanagedResources))]
    public partial class DisposeableTest : IDisposable, IAsyncDisposable
    {
        ConsoleOutputDisposable consoleOutputDisposable = new();

        ConsoleOutputAsyncDisposable consoleOutputAsyncDisposable = new();

        public DisposeableTest()
        {
            Console.WriteLine("Created new DisposeableTest");
        }

        void ReleaseUnmanagedResources()
        {
            Console.WriteLine("    Called ReleaseUnmanagedResources() of DisposeableTest.");
        }
    }

    class Program
    {
        public static async Task Main()
        {
            await DiposeTestAsync();

            Console.WriteLine("Begin GC.Collect()");
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Console.WriteLine("End GC.Collect()");
            Console.WriteLine();
        }

        static async Task DiposeTestAsync()
        {
            var disposeTestInstance = new DisposeableTest();

            Console.WriteLine("Begin disposeTestInstance.Dispose()");
            disposeTestInstance.Dispose();
            Console.WriteLine("End disposeTestInstance.Dispose()");
            Console.WriteLine();

            var asyncDisposeTestInstance = new DisposeableTest();

            Console.WriteLine("Begin disposeTestInstance.DisposeAsync()");
            await asyncDisposeTestInstance.DisposeAsync();
            Console.WriteLine("End disposeTestInstance.DisposeAsync()");
            Console.WriteLine();

            var garbegeCollectionTestInstance = new DisposeableTest();
        }
    }
}

Output example of above

Created new DisposeableTest
Begin disposeTestInstance.Dispose()
    Called Dispose() of ConsoleOutputDisposable.
    Called Dispose() of ConsoleOutputAsyncDisposable.
    Called ReleaseUnmanagedResources() of DisposeableTest.
End disposeTestInstance.Dispose()

Created new DisposeableTest
Begin disposeTestInstance.DisposeAsync()
    Called DisposeAsync() of ConsoleOutputAsyncDisposable.
    Called Dispose() of ConsoleOutputDisposable.
    Called ReleaseUnmanagedResources() of DisposeableTest.
End disposeTestInstance.DisposeAsync()

Created new DisposeableTest
Begin GC.Collect()
    Called ReleaseUnmanagedResources() of DisposeableTest. <-- Will be called by the finalizer even if Dispose is missed.
End GC.Collect()
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.3-alpha8 420 11/4/2022
2.1.3-alpha7 264 10/2/2022
2.1.3-alpha4 264 8/8/2022
2.0.1 593 7/12/2022
2.0.0 401 6/4/2022
1.0.1 387 5/20/2022
1.0.0 417 2/12/2022
0.0.0.9 585 12/11/2021
0.0.0.8 260 12/10/2021
0.0.0.6 329 9/3/2021
0.0.0.5 298 9/2/2021
0.0.0.4 294 9/1/2021
0.0.0.3 301 9/1/2021
0.0.0.2 309 8/29/2021
0.0.0.1 306 8/18/2021