Skip to content

hamedsabzian/Generators.Dispose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Generators.Dispose

It makes implementing the Dispose pattern as simple as possible.

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

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 source generation, just use IgnoreGeneration attribute.

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

About

Implementing Dispose pattern automatically using Source Generator feature.

Topics

Resources

Stars

Watchers

Forks