Skip to main content

IDisposableGenerator by Els_kom Official Organization

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: IDisposableGenerator

Source Generator Generating the Dispose functions in Disposables.

Author: Els_kom Official Organization

NuGet: https://www.nuget.org/packages/IDisposableGenerator/

You can find more details at https://github.com/Elskom/IDisposableGenerator

Source: https://github.com/Elskom/IDisposableGenerator

Original Readme​

note

IDisposableGenerator

Source Generator Generating the Dispose functions in Disposables.

Code Ownership​

All code used is copyright of Elskom org, with the exception of Roslyn which is copyright of the .NET Foundation and it's contributors.

The dependencies of the unit tests are copyright of their respective owners.

Status​

This project is currently actively maintained whenever an issue happens (or whenever major roslyn changes happens that break it).

Purpose​

This project is for easily generating the dispose functions of disposable types using attributes to control the generator on how it writes the generated code. This results in code that is more maintainable and cleaner than if you had to implement the IDisposable interface yourself. Disposable types require marking the type as partial to properly compile the generated code.

Documentation​

It is currently in the works.

Badges​

Codacy Badge Codacy Coverage Badge

PackageVersion
IDisposableGeneratorNuGet Badge

About​

note

Generating disposable

How to use​

Example (source csproj, source files)​

This is the CSharp Project that references IDisposableGenerator

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IDisposableGenerator" Version="1.1.1" OutputItemType="Analyzer" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

// <autogenerated/>
namespace IDisposableGeneratorDemo;

internal partial class DALDB : IDisposable
{
private bool isDisposed;

internal bool IsOwned { get; set; }

/// <summary>
/// Cleans up the resources used by <see cref="DALDB"/>.
/// </summary>
public void Dispose() => this.Dispose(true);

private void Dispose(bool disposing)
{
if (!this.isDisposed && disposing)
{
if (this.IsOwned)
{
this.cn?.Dispose();
this.cn = null;
this.cn1?.Dispose();
this.cn1 = null;
}
this.isDisposed = true;
}
}
}

Useful​

Download Example (.NET C#)​

Share IDisposableGenerator​

https://ignatandrei.github.io/RSCG_Examples/v2/docs/IDisposableGenerator

aaa

Category "Disposer" has the following generators:​

1 BenutomoAutomaticDisposeImplSourceGenerator Nuget GitHub Repo stars 2023-08-15

2 Coplt.Dropping Nuget GitHub Repo stars 2024-08-13

3 Dirge Nuget GitHub Repo stars 2026-07-01

4 DisposableHelpers Nuget GitHub Repo stars 2023-10-09

5 Disposer Nuget GitHub Repo stars 2023-10-03

6 GenerateDispose Nuget GitHub Repo stars 2026-05-13

7 IDisposableGenerator Nuget GitHub Repo stars 2023-10-11

8 ReflectionIT.DisposeGenerator Nuget GitHub Repo stars 2026-08-19

See category​

Disposer