It makes implementing the Dispose pattern as simple as possible.
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 |
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
}