DisposeGenerator is a C# source generator that automatically implements IDisposable and IAsyncDisposable for you.
Manually implementing proper IDisposable and IAsyncDisposable patterns tends to bring a lot of boilerplate code. This source generator aims to alleviate that problem so that you don't have to think about this pattern anymore.
Keep in mind that this project is in an early stage, and that bugs may occur.
- Other source generators that add additional members to a partial class, are not detected
- Nested IDisposable/IAsyncDisposable classes are not supported
- Inheritance is done on best effort, which means that the generator expects the base class to properly implement Microsoft's IDisposable and IAsyncDisposable and/or IAsyncDisposable pattern.
- Probably more that I have overlooked...
You can find the library on NuGet. Or, alternatively, you can install it by running dotnet add package DisposeGenerator
in a console, or Install-Package DisposeGenerator
in the package manager console.
TODO
This project has been developed and tested in Visual Studio 2019 (16.10).
Because a proper IDisposable or IAsyncDisposable pattern is quite complicated, any contribution that adds features or fixes bugs are very much welcome.