Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.41 KB

README.md

File metadata and controls

57 lines (46 loc) · 1.41 KB

How to use?

You can install its latest version using your IDE Nuget package manager by using dotnet command as follows:

dotnet add package Generators.Dispose
Package Version
Generators.Dispose NuGet Badge

It generates a partial class for all partial classes that implement IDisposable interface.

public partial class SampleClass : IDisposable
{
}

The generated class declares DisposeManaged partial method that will be called to release managed resources.

public partial class SampleClass : IDisposable
{
    partial void DisposeManaged()
    {
        // Call Dispose method of the managed resources
    }
}

If your class works with unmanaged resources, you need to implement DisposeUnmanaged partial method.

public partial class SampleClass : IDisposable
{
    partial void DisposeManaged()
    {
        // Call Dispose method of the managed resources
    }

    partial void DisposeUnmanaged()
    {
        // Release the managed resources
    }
}

If you have a partial class implements IDisposable interface, but you want to exclude it from generation, just use IgnoreGeneration attribute.

[IgnoreGeneration]
public partial class IgnoredDisposable : IDisposable
{
    // Implement Dispose pattern manually
}