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;
}
}
}

Usefull

Download Example (.NET C# )

Share IDisposableGenerator

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

In the same category (Disposer) - 4 other generators

BenutomoAutomaticDisposeImplSourceGenerator

Coplt.Dropping

DisposableHelpers

Disposer