From 2e9171525448506da60cacd51b00ffa88eb1f600 Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Sun, 5 Jul 2026 09:51:34 +0300 Subject: [PATCH 1/4] first iteration --- README.md | 28 ++- v2/Generator/all.csv | 1 + v2/RSCGExamplesData/GeneratorDataRec.json | 6 + v2/rscg_examples/Dirge/description.json | 22 ++ v2/rscg_examples/Dirge/nuget.txt | 1 + v2/rscg_examples/Dirge/readme.txt | 215 ++++++++++++++++++ v2/rscg_examples/Dirge/src/.tours/Dirge.tour | 60 +++++ v2/rscg_examples/Dirge/src/IDisp.sln | 25 ++ .../Dirge/src/IDisp/ConnectionDB.cs | 14 ++ v2/rscg_examples/Dirge/src/IDisp/DALDB.cs | 15 ++ v2/rscg_examples/Dirge/src/IDisp/IDisp.csproj | 20 ++ v2/rscg_examples/Dirge/src/IDisp/Program.cs | 7 + v2/rscg_examples/Dirge/video.json | 39 ++++ .../docs/Authors/Kazuki_Kohzuki.md | 7 + .../docs/Categories/Disposer.md | 12 +- .../docs/Categories/_PrimitiveDisposer.mdx | 10 +- .../docs/RSCG-Examples/index.md | 13 +- v2/rscg_examples_site/docs/about.md | 2 +- v2/rscg_examples_site/docs/indexRSCG.md | 5 +- .../src/components/HomepageFeatures/index.js | 2 +- .../static/exports/RSCG.json | 8 + 21 files changed, 493 insertions(+), 19 deletions(-) create mode 100644 v2/rscg_examples/Dirge/description.json create mode 100644 v2/rscg_examples/Dirge/nuget.txt create mode 100644 v2/rscg_examples/Dirge/readme.txt create mode 100644 v2/rscg_examples/Dirge/src/.tours/Dirge.tour create mode 100644 v2/rscg_examples/Dirge/src/IDisp.sln create mode 100644 v2/rscg_examples/Dirge/src/IDisp/ConnectionDB.cs create mode 100644 v2/rscg_examples/Dirge/src/IDisp/DALDB.cs create mode 100644 v2/rscg_examples/Dirge/src/IDisp/IDisp.csproj create mode 100644 v2/rscg_examples/Dirge/src/IDisp/Program.cs create mode 100644 v2/rscg_examples/Dirge/video.json create mode 100644 v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md diff --git a/README.md b/README.md index 4628d325e..f2c465782 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# RSCG - 273 Examples of Roslyn Source Code Generators / 16 created by Microsoft / +# RSCG - 274 Examples of Roslyn Source Code Generators / 16 created by Microsoft / -The RSCG_Examples repository is a comprehensive documentation system that automatically processes and showcases 273 Roslyn Source Code Generator (RSCG) examples. The system transforms individual RSCG projects into structured documentation with code examples and cross-referenced content with a searchable website and code example exports. +The RSCG_Examples repository is a comprehensive documentation system that automatically processes and showcases 274 Roslyn Source Code Generator (RSCG) examples. The system transforms individual RSCG projects into structured documentation with code examples and cross-referenced content with a searchable website and code example exports. This system serves as both a learning resource for .NET developers interested in source generators and an automated pipeline for maintaining up-to-date documentation about the RSCG ecosystem @@ -24,8 +24,30 @@ If you want to be notified each time I add a new RSCG example , please click htt ## Content -Those are the 273 Roslyn Source Code Generators that I have tested you can see and download source code example. +Those are the 274 Roslyn Source Code Generators that I have tested you can see and download source code example. ( including 16 from Microsoft ) +### 274. [Dirge](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge) , in the [Disposer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#disposer) category + +Generated on : 2023-07-01 => 01 July 2023 + +
+ Expand + + + +Author: Kazuki Kohzuki + +Disposable Implementation Roslyn Generator Extension + +Nuget: [https://www.nuget.org/packages/Dirge/](https://www.nuget.org/packages/Dirge/) + + +Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge) + +Source: [https://github.com/IkuzakIkuzok/Dirge](https://github.com/IkuzakIkuzok/Dirge) + +
+ ### 273. [ScottEncodingGenerator](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ScottEncodingGenerator) , in the [FunctionalProgramming](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#functionalprogramming) category Generated on : 2026-06-30 => 30 June 2026 diff --git a/v2/Generator/all.csv b/v2/Generator/all.csv index 5fab7fc6f..a7e6336bb 100644 --- a/v2/Generator/all.csv +++ b/v2/Generator/all.csv @@ -272,3 +272,4 @@ Nr,Key,Source,Category 271,TypedStateBuilder.Generator, https://github.com/Georgiy-Petrov/TypedStateBuilder.Generator,Builder 272,AlephMapper, https://github.com/Raffinert/AlephMapper,Database 273,ScottEncodingGenerator, https://github.com/Georgiy-Petrov/ScottEncodingGenerator,FunctionalProgramming +274,Dirge, https://github.com/IkuzakIkuzok/Dirge,Disposer diff --git a/v2/RSCGExamplesData/GeneratorDataRec.json b/v2/RSCGExamplesData/GeneratorDataRec.json index 0c101513a..69830e035 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1654,5 +1654,11 @@ "Category": 10, "dtStart": "2026-06-30T00:00:00", "show": true + }, + { + "ID": "Dirge", + "Category": 18, + "dtStart": "2023-07-01T00:00:00", + "show": true } ] \ No newline at end of file diff --git a/v2/rscg_examples/Dirge/description.json b/v2/rscg_examples/Dirge/description.json new file mode 100644 index 000000000..642b070ed --- /dev/null +++ b/v2/rscg_examples/Dirge/description.json @@ -0,0 +1,22 @@ +{ + "generator":{ + "name":"Dirge", + "nuget":[ + "https://www.nuget.org/packages/Dirge/" + ], + "link":"https://github.com/IkuzakIkuzok/Dirge", + "author":"Kazuki Kohzuki", + "source":"https://github.com/IkuzakIkuzok/Dirge" + }, + "data":{ + "goodFor":["Generating disposable"], + "csprojDemo":"IDisp.csproj", + "csFiles":["Program.cs","DALDB.cs","ConnectionDB.cs"], + "excludeDirectoryGenerated":[""], + "includeAdditionalFiles":[""] + }, + "links":{ + "blog":"", + "video":"" + } +} \ No newline at end of file diff --git a/v2/rscg_examples/Dirge/nuget.txt b/v2/rscg_examples/Dirge/nuget.txt new file mode 100644 index 000000000..4b2717b09 --- /dev/null +++ b/v2/rscg_examples/Dirge/nuget.txt @@ -0,0 +1 @@ +Disposable Implementation Roslyn Generator Extension \ No newline at end of file diff --git a/v2/rscg_examples/Dirge/readme.txt b/v2/rscg_examples/Dirge/readme.txt new file mode 100644 index 000000000..7c7315870 --- /dev/null +++ b/v2/rscg_examples/Dirge/readme.txt @@ -0,0 +1,215 @@ + +# Dirge + +[![Test](https://github.com/IkuzakIkuzok/Dirge/actions/workflows/Test.yml/badge.svg)](https://github.com/IkuzakIkuzok/Dirge/actions/workflows/Test.yml) +[![Version](https://img.shields.io/nuget/v/Dirge?styles=flat)](https://www.nuget.org/packages/Dirge/#versions-body-tab) +[![Download](https://img.shields.io/nuget/dt/Dirge?styles=flat)](https://www.nuget.org/packages/Dirge/#versions-body-tab) +[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/IkuzakIkuzok/Dirge/blob/main/LICENSE) + +Disposable Implementation Roslyn Generator Extension +## Installation + +You can install the EnumSerializer from [NuGet](https://www.nuget.org/packages/Dirge/). + +## Usage + +Mark a class with the `[AutoDispose]` attribute and implement the `IDisposable` interface. +The generator will automatically generate the implementation of the `Dispose` method for you. + +```C# +using Dirge; + +namespace Test; + +[AutoDispose] +internal partial class TestClass +{ + private readonly Stream _stream = new MemoryStream(); +} +``` + +The generated code will look like this: +```C# +namespace Test; + +partial class TestClass : IDisposable +{ + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + this._stream?.Dispose(); + } + } + finally + { + this.__generated_disposed = true; + } + } +} +``` + +Note that this example is simplified for demonstration purposes. + +To suppress the auto-generated Dispose call for a specific field, you can use the `[DoNotDispose]` attribute: +```C# +using Dirge; + +namespace Test; + +[AutoDispose] +internal partial class TestClass +{ + private readonly Stream _stream1 = new MemoryStream(); + + [DoNotDispose] + private readonly Stream _stream2 = new MemoryStream(); // This field will not be disposed by the generated Dispose method. +} +``` + +Ref-struct is also supported, but `IDisposable` will not be implemented regardless of the language version. + +### Conditional disposal + +Conditional disposal, which allows you to specify conditions under which a field should be disposed, is also supported. +You can use the `[DoNotDisposeWhen]` attribute with a boolean field and a value to compare against: +```C# +using Dirge; + +namespace Test; + +[AutoDispose] +internal partial class TestClass +{ + private readonly bool _leaveOpen; + + [DoNotDisposeWhen(nameof(_leaveOpen), true)] + private readonly Stream _stream; + + internal TestClass(Stream stream, bool leaveOpen) + { + this._stream = stream; + this._leaveOpen = leaveOpen; + } +} +``` + +This will prevent the generator from disposing the `_stream` field when the `_leaveOpen` field is `true`: +```C# +namespace Test; + +partial class TestClass : IDisposable +{ + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + if (!this._leaveOpen) + { + this._stream?.Dispose(); + } + } + } + finally + { + this.__generated_disposed = true; + } + } +} +``` + +### Unmanaged resources + +To safely release unmanaged resources, this generator also supports the implementation of a finalizer. +You can specify a method to release unmanaged resources through the `ReleaseUnmanagedResources` option: +```C# +using Dirge; +using System.IO; + +namespace Test; + +[AutoDispose(ReleaseUnmanagedResources = nameof(ReleaseUnmanagedResources))] +internal sealed partial class TestClass +{ + private readonly Stream _stream; + + internal void ReleaseUnmanagedResources() + { + // Custom logic to release unmanaged resources + } +} +``` + +This will generate a finalizer that calls the specified method to release unmanaged resources: +```C# +namespace Test; + +sealed partial class TestClass : IDisposable +{ + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + this._stream?.Dispose(); + } + + ReleaseUnmanagedResources(); + } + finally + { + this.__generated_disposed = true; + } + } + + ~TestClass() + { + Dispose(false); + } +} +``` + +## Constraints + +To generate the `Dispose` method, the class (or struct) must meet the following constraints: +- It must be a non-static class. +- It must be a partial class or struct. +- It must not be a readonly struct. + +For conditional disposal, the field specified in the `nameof` expression must be a boolean field. +Properties and methods are not supported for the current version. diff --git a/v2/rscg_examples/Dirge/src/.tours/Dirge.tour b/v2/rscg_examples/Dirge/src/.tours/Dirge.tour new file mode 100644 index 000000000..29b4d9e77 --- /dev/null +++ b/v2/rscg_examples/Dirge/src/.tours/Dirge.tour @@ -0,0 +1,60 @@ + +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "Dirge", + "steps": + [ + { + "file": "IDisp/IDisp.csproj", + "description": "First, we add Nuget [Dirge](https://www.nuget.org/packages/Dirge/) in csproj ", + "pattern": "Dirge" + } + + ,{ + "file": "IDisp/ConnectionDB.cs", + "description": "File ConnectionDB.cs ", + "pattern": "this is the code" + } + + ,{ + "file": "IDisp/DALDB.cs", + "description": "File DALDB.cs ", + "pattern": "this is the code" + } + + ,{ + "file": "IDisp/Program.cs", + "description": "File Program.cs \r\n>> dotnet run --project IDisp/IDisp.csproj ", + "pattern": "this is the code" + } + + + ,{ + "file": "IDisp/obj/GX/Dirge/Dirge.Generators.TypesGenerator/DoNotDisposeWhenAttribute.g.cs", + "description": "Generated File 4 from 4 : DoNotDisposeWhenAttribute.g.cs ", + "line": 1 + } + + ,{ + "file": "IDisp/obj/GX/Dirge/Dirge.Generators.TypesGenerator/DoNotDisposeAttribute.g.cs", + "description": "Generated File 3 from 4 : DoNotDisposeAttribute.g.cs ", + "line": 1 + } + + ,{ + "file": "IDisp/obj/GX/Dirge/Dirge.Generators.TypesGenerator/AutoDisposeAttribute.g.cs", + "description": "Generated File 2 from 4 : AutoDisposeAttribute.g.cs ", + "line": 1 + } + + ,{ + "file": "IDisp/obj/GX/Dirge/Dirge.Generators.DisposeGenerator/DALDB.GeneratedDispose.g.cs", + "description": "Generated File 1 from 4 : DALDB.GeneratedDispose.g.cs ", + "line": 1 + } + + ], + + "ref": "main" + +} \ No newline at end of file diff --git a/v2/rscg_examples/Dirge/src/IDisp.sln b/v2/rscg_examples/Dirge/src/IDisp.sln new file mode 100644 index 000000000..ad2677ba6 --- /dev/null +++ b/v2/rscg_examples/Dirge/src/IDisp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33829.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDisp", "IDisp\IDisp.csproj", "{6237DD9A-6211-4046-97B4-754E12478992}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6237DD9A-6211-4046-97B4-754E12478992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6237DD9A-6211-4046-97B4-754E12478992}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6237DD9A-6211-4046-97B4-754E12478992}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6237DD9A-6211-4046-97B4-754E12478992}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {81F892FB-0998-4DEA-92E1-55B8EECB0608} + EndGlobalSection +EndGlobal diff --git a/v2/rscg_examples/Dirge/src/IDisp/ConnectionDB.cs b/v2/rscg_examples/Dirge/src/IDisp/ConnectionDB.cs new file mode 100644 index 000000000..3ba510b15 --- /dev/null +++ b/v2/rscg_examples/Dirge/src/IDisp/ConnectionDB.cs @@ -0,0 +1,14 @@ +namespace IDisposableGeneratorDemo; + +class ConnectionDB : IDisposable +{ + static int count = 0; + public ConnectionDB() + { + Interlocked.Increment(ref count); + } + public void Dispose() + { + Console.WriteLine($"disposing connectiondb {Interlocked.Decrement(ref count)}"); + } +} diff --git a/v2/rscg_examples/Dirge/src/IDisp/DALDB.cs b/v2/rscg_examples/Dirge/src/IDisp/DALDB.cs new file mode 100644 index 000000000..9892de90b --- /dev/null +++ b/v2/rscg_examples/Dirge/src/IDisp/DALDB.cs @@ -0,0 +1,15 @@ +namespace IDisposableGeneratorDemo; + +[Dirge.AutoDispose] +partial class DALDB +{ + private ConnectionDB cn; + private ConnectionDB cn1; + + public DALDB() + { + cn = new ConnectionDB(); + cn1=new ConnectionDB(); + } + +} diff --git a/v2/rscg_examples/Dirge/src/IDisp/IDisp.csproj b/v2/rscg_examples/Dirge/src/IDisp/IDisp.csproj new file mode 100644 index 000000000..18cbd26b0 --- /dev/null +++ b/v2/rscg_examples/Dirge/src/IDisp/IDisp.csproj @@ -0,0 +1,20 @@ + + + + Exe + net10.0 + enable + enable + + + true + $(BaseIntermediateOutputPath)\GX + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/v2/rscg_examples/Dirge/src/IDisp/Program.cs b/v2/rscg_examples/Dirge/src/IDisp/Program.cs new file mode 100644 index 000000000..601e1dcde --- /dev/null +++ b/v2/rscg_examples/Dirge/src/IDisp/Program.cs @@ -0,0 +1,7 @@ +using IDisposableGeneratorDemo; +//https://github.com/benutomo-dev/RoslynComponents +using (var db = new DALDB()) +{ + Console.WriteLine("before releasing"); +} +Console.WriteLine("after releasing"); \ No newline at end of file diff --git a/v2/rscg_examples/Dirge/video.json b/v2/rscg_examples/Dirge/video.json new file mode 100644 index 000000000..c75958ea3 --- /dev/null +++ b/v2/rscg_examples/Dirge/video.json @@ -0,0 +1,39 @@ +{ + "scriptName": "Dirge", + "steps": +[ + {"typeStep":"exec","arg":"clipchamp.exe launch"}, + {"typeStep":"text","arg": "Welcome to Roslyn Examples"}, + {"typeStep":"text","arg":"If you want to see more examples , see List Of RSCG"}, + {"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG"}, + {"typeStep":"text","arg": "My name is Andrei Ignat and I am deeply fond of Roslyn Source Code Generator. "}, + +{"typeStep":"text","arg": "Today I will present Dirge . Generating disposable ."}, +{"typeStep":"browser","arg":"https://www.nuget.org/packages/Dirge/"}, +{"typeStep":"text","arg": "The whole example is here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge"}, +{"typeStep":"text","arg": "You can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge#download-example-net--c-"}, +{"typeStep":"text","arg":"Here is the code downloaded "}, +{"typeStep":"exec","arg":"explorer.exe /select,D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Dirge\\src\\IDisp.sln"}, +{"typeStep":"text","arg": "So , let's start the project with Visual Studio Code "}, +{"typeStep":"stepvscode","arg": "-n D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Dirge\\src"}, + +{"typeStep":"text","arg": "To use it ,you will put the Nuget Dirge into the csproj "}, + +{"typeStep":"stepvscode","arg": "-r -g D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\Dirge\\src\\IDisp\\IDisp.csproj"}, + +{"typeStep":"text","arg": "And now I will show you an example of using Dirge"}, + +{"typeStep":"hide","arg": "now execute the tour in VSCode"}, +{"typeStep":"tour", "arg": "src/.tours/"}, +{"typeStep":"text","arg":" And I will execute the project"}, +{"typeStep":"showproj", "arg":"IDisp.csproj"}, +{"typeStep":"text","arg":" This concludes the project"}, +{"typeStep":"waitseconds","arg":"30"}, +{"typeStep":"text","arg": "Remember, you can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge#download-example-net--c-", +SpeakTest=" "}, +{"typeStep":"waitseconds","arg":"30"}, +] +} diff --git a/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md b/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md new file mode 100644 index 000000000..3fefb7e00 --- /dev/null +++ b/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md @@ -0,0 +1,7 @@ +# Author : Kazuki Kohzuki + +Number RSCG: 1 + + + 1 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2023-07-01 + diff --git a/v2/rscg_examples_site/docs/Categories/Disposer.md b/v2/rscg_examples_site/docs/Categories/Disposer.md index 3eeb1f3c8..d783afc97 100644 --- a/v2/rscg_examples_site/docs/Categories/Disposer.md +++ b/v2/rscg_examples_site/docs/Categories/Disposer.md @@ -1,16 +1,18 @@

Disposer

-Number RSCG: 6 +Number RSCG: 7 1 [BenutomoAutomaticDisposeImplSourceGenerator](/docs/BenutomoAutomaticDisposeImplSourceGenerator) [![Nuget](https://img.shields.io/nuget/dt/Benutomo.AutomaticDisposeImpl.SourceGenerator?label=Benutomo.AutomaticDisposeImpl.SourceGenerator)](https://www.nuget.org/packages/Benutomo.AutomaticDisposeImpl.SourceGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/benutomo-dev/RoslynComponents?style=social) 2023-08-15 2 [Coplt.Dropping](/docs/Coplt.Dropping) [![Nuget](https://img.shields.io/nuget/dt/Coplt.Dropping?label=Coplt.Dropping)](https://www.nuget.org/packages/Coplt.Dropping/) ![GitHub Repo stars](https://img.shields.io/github/stars/2A5F/Coplt.Dropping?style=social) 2024-08-13 - 3 [DisposableHelpers](/docs/DisposableHelpers) [![Nuget](https://img.shields.io/nuget/dt/DisposableHelpers?label=DisposableHelpers)](https://www.nuget.org/packages/DisposableHelpers/) ![GitHub Repo stars](https://img.shields.io/github/stars/Kiryuumaru/DisposableHelpers?style=social) 2023-10-09 + 3 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2023-07-01 - 4 [Disposer](/docs/Disposer) [![Nuget](https://img.shields.io/nuget/dt/Disposer?label=Disposer)](https://www.nuget.org/packages/Disposer/) ![GitHub Repo stars](https://img.shields.io/github/stars/HakamFostok/Disposer?style=social) 2023-10-03 + 4 [DisposableHelpers](/docs/DisposableHelpers) [![Nuget](https://img.shields.io/nuget/dt/DisposableHelpers?label=DisposableHelpers)](https://www.nuget.org/packages/DisposableHelpers/) ![GitHub Repo stars](https://img.shields.io/github/stars/Kiryuumaru/DisposableHelpers?style=social) 2023-10-09 - 5 [GenerateDispose](/docs/GenerateDispose) [![Nuget](https://img.shields.io/nuget/dt/GenerateDispose?label=GenerateDispose)](https://www.nuget.org/packages/GenerateDispose/) ![GitHub Repo stars](https://img.shields.io/github/stars/ItaiTzur76/GenerateDispose?style=social) 2026-05-13 + 5 [Disposer](/docs/Disposer) [![Nuget](https://img.shields.io/nuget/dt/Disposer?label=Disposer)](https://www.nuget.org/packages/Disposer/) ![GitHub Repo stars](https://img.shields.io/github/stars/HakamFostok/Disposer?style=social) 2023-10-03 - 6 [IDisposableGenerator](/docs/IDisposableGenerator) [![Nuget](https://img.shields.io/nuget/dt/IDisposableGenerator?label=IDisposableGenerator)](https://www.nuget.org/packages/IDisposableGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/Elskom/IDisposableGenerator?style=social) 2023-10-11 + 6 [GenerateDispose](/docs/GenerateDispose) [![Nuget](https://img.shields.io/nuget/dt/GenerateDispose?label=GenerateDispose)](https://www.nuget.org/packages/GenerateDispose/) ![GitHub Repo stars](https://img.shields.io/github/stars/ItaiTzur76/GenerateDispose?style=social) 2026-05-13 + + 7 [IDisposableGenerator](/docs/IDisposableGenerator) [![Nuget](https://img.shields.io/nuget/dt/IDisposableGenerator?label=IDisposableGenerator)](https://www.nuget.org/packages/IDisposableGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/Elskom/IDisposableGenerator?style=social) 2023-10-11 \ No newline at end of file diff --git a/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx b/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx index 8b37e66c7..de3950dc8 100644 --- a/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx +++ b/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx @@ -4,13 +4,15 @@ 2 [Coplt.Dropping](/docs/Coplt.Dropping) [![Nuget](https://img.shields.io/nuget/dt/Coplt.Dropping?label=Coplt.Dropping)](https://www.nuget.org/packages/Coplt.Dropping/) ![GitHub Repo stars](https://img.shields.io/github/stars/2A5F/Coplt.Dropping?style=social) 2024-08-13 - 3 [DisposableHelpers](/docs/DisposableHelpers) [![Nuget](https://img.shields.io/nuget/dt/DisposableHelpers?label=DisposableHelpers)](https://www.nuget.org/packages/DisposableHelpers/) ![GitHub Repo stars](https://img.shields.io/github/stars/Kiryuumaru/DisposableHelpers?style=social) 2023-10-09 + 3 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2023-07-01 - 4 [Disposer](/docs/Disposer) [![Nuget](https://img.shields.io/nuget/dt/Disposer?label=Disposer)](https://www.nuget.org/packages/Disposer/) ![GitHub Repo stars](https://img.shields.io/github/stars/HakamFostok/Disposer?style=social) 2023-10-03 + 4 [DisposableHelpers](/docs/DisposableHelpers) [![Nuget](https://img.shields.io/nuget/dt/DisposableHelpers?label=DisposableHelpers)](https://www.nuget.org/packages/DisposableHelpers/) ![GitHub Repo stars](https://img.shields.io/github/stars/Kiryuumaru/DisposableHelpers?style=social) 2023-10-09 - 5 [GenerateDispose](/docs/GenerateDispose) [![Nuget](https://img.shields.io/nuget/dt/GenerateDispose?label=GenerateDispose)](https://www.nuget.org/packages/GenerateDispose/) ![GitHub Repo stars](https://img.shields.io/github/stars/ItaiTzur76/GenerateDispose?style=social) 2026-05-13 + 5 [Disposer](/docs/Disposer) [![Nuget](https://img.shields.io/nuget/dt/Disposer?label=Disposer)](https://www.nuget.org/packages/Disposer/) ![GitHub Repo stars](https://img.shields.io/github/stars/HakamFostok/Disposer?style=social) 2023-10-03 - 6 [IDisposableGenerator](/docs/IDisposableGenerator) [![Nuget](https://img.shields.io/nuget/dt/IDisposableGenerator?label=IDisposableGenerator)](https://www.nuget.org/packages/IDisposableGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/Elskom/IDisposableGenerator?style=social) 2023-10-11 + 6 [GenerateDispose](/docs/GenerateDispose) [![Nuget](https://img.shields.io/nuget/dt/GenerateDispose?label=GenerateDispose)](https://www.nuget.org/packages/GenerateDispose/) ![GitHub Repo stars](https://img.shields.io/github/stars/ItaiTzur76/GenerateDispose?style=social) 2026-05-13 + + 7 [IDisposableGenerator](/docs/IDisposableGenerator) [![Nuget](https://img.shields.io/nuget/dt/IDisposableGenerator?label=IDisposableGenerator)](https://www.nuget.org/packages/IDisposableGenerator/) ![GitHub Repo stars](https://img.shields.io/github/stars/Elskom/IDisposableGenerator?style=social) 2023-10-11 ### See category diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/index.md b/v2/rscg_examples_site/docs/RSCG-Examples/index.md index 077f13dfe..72f56ad82 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/index.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/index.md @@ -1,7 +1,7 @@ --- sidebar_position: 30 -title: 273 RSCG list by category -description: 273 RSCG list by category +title: 274 RSCG list by category +description: 274 RSCG list by category slug: /rscg-examples --- @@ -514,7 +514,7 @@ import DocCardList from '@theme/DocCardList'; ## Disposer
- Expand Disposer =>examples:6 + Expand Disposer =>examples:7 @@ -545,6 +545,11 @@ import DocCardList from '@theme/DocCardList'; [GenerateDispose](/docs/GenerateDispose) + + + +[Dirge](/docs/Dirge) +
@@ -1871,6 +1876,8 @@ flowchart LR; Disposer--> GenerateDispose((GenerateDispose)) + Disposer--> Dirge((Dirge)) + Documentation--> REslava.ResultFlow((REslava.ResultFlow)) EnhancementClass--> System.Text.RegularExpressions((System.Text.RegularExpressions)) diff --git a/v2/rscg_examples_site/docs/about.md b/v2/rscg_examples_site/docs/about.md index cbace812c..3a0d1969d 100644 --- a/v2/rscg_examples_site/docs/about.md +++ b/v2/rscg_examples_site/docs/about.md @@ -6,7 +6,7 @@ title: About ## Content You will find here code examples -of 273 Roslyn Source Code Generator (RSCG) +of 274 Roslyn Source Code Generator (RSCG) that can be useful for you. That means, you will write more elegant and concise code - even if the generators code is not always nice to look. ## Are those examples ready for production? diff --git a/v2/rscg_examples_site/docs/indexRSCG.md b/v2/rscg_examples_site/docs/indexRSCG.md index 93c630289..32b642b1b 100644 --- a/v2/rscg_examples_site/docs/indexRSCG.md +++ b/v2/rscg_examples_site/docs/indexRSCG.md @@ -7,9 +7,9 @@ slug: /List-of-RSCG import useBaseUrl from '@docusaurus/useBaseUrl'; -## 273 RSCG with examples in descending chronological order +## 274 RSCG with examples in descending chronological order -This is the list of 273 ( 16 from Microsoft) RSCG with examples +This is the list of 274 ( 16 from Microsoft) RSCG with examples [See by category](/docs/rscg-examples) [See as json](/exports/RSCG.json) [See as Excel](/exports/RSCG.xlsx) @@ -20,6 +20,7 @@ This is the list of 273 ( 16 from Microsoft) RSCG with examples | No | Name | Date | Category | | --------- | ----- | ---- | -------- | +|274| [Dirge by Kazuki Kohzuki ](/docs/Dirge)|2023-07-01 => 01 July 2023 | [Disposer](/docs/Categories/Disposer) | |273| [ScottEncodingGenerator by Georgiy Petrov ](/docs/ScottEncodingGenerator)|2026-06-30 => 30 June 2026 | [FunctionalProgramming](/docs/Categories/FunctionalProgramming) | |272| [AlephMapper by Yevhen Cherkes ](/docs/AlephMapper)|2026-06-29 => 29 June 2026 | [Database](/docs/Categories/Database) | |271| [TypedStateBuilder.Generator by Georgiy Petrov ](/docs/TypedStateBuilder.Generator)|2026-05-16 => 16 May 2026 | [Builder](/docs/Categories/Builder) | diff --git a/v2/rscg_examples_site/src/components/HomepageFeatures/index.js b/v2/rscg_examples_site/src/components/HomepageFeatures/index.js index efb5ae47c..37f1ee269 100644 --- a/v2/rscg_examples_site/src/components/HomepageFeatures/index.js +++ b/v2/rscg_examples_site/src/components/HomepageFeatures/index.js @@ -4,7 +4,7 @@ import styles from './styles.module.css'; const FeatureList = [ { -title: '273 Examples (16 from MSFT)', +title: '274 Examples (16 from MSFT)', Svg: require('@site/static/img/undraw_docusaurus_mountain.svg').default, description: ( <> diff --git a/v2/rscg_examples_site/static/exports/RSCG.json b/v2/rscg_examples_site/static/exports/RSCG.json index 6b6fc2682..da909bdc3 100644 --- a/v2/rscg_examples_site/static/exports/RSCG.json +++ b/v2/rscg_examples_site/static/exports/RSCG.json @@ -2185,6 +2185,14 @@ "Source": "https://github.com/Georgiy-Petrov/ScottEncodingGenerator", "Category": "FunctionalProgramming", "AddedOn": "2026-06-30T00:00:00" + }, + { + "Name": "Dirge", + "Link": "https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge", + "NuGet": "https://www.nuget.org/packages/Dirge/", + "Source": "https://github.com/IkuzakIkuzok/Dirge", + "Category": "Disposer", + "AddedOn": "2023-07-01T00:00:00" } ] } \ No newline at end of file From 654a86d98bb711e5fef63d456888abf73f8ee12f Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Sun, 5 Jul 2026 09:56:18 +0300 Subject: [PATCH 2/4] drecond --- README.md | 4 +- later.md | 2 +- v2/RSCGExamplesData/GeneratorDataRec.json | 2 +- v2/rscg_examples/Dirge/description.json | 12 +- v2/rscg_examples/Dirge/video.json | 2 +- .../docs/Authors/Kazuki_Kohzuki.md | 2 +- .../docs/Categories/Disposer.md | 2 +- .../docs/Categories/_PrimitiveDisposer.mdx | 2 +- .../docs/RSCG-Examples/Dirge.md | 540 ++++++++++++++++++ v2/rscg_examples_site/docs/indexRSCG.md | 2 +- .../static/exports/RSCG.json | 2 +- 11 files changed, 561 insertions(+), 11 deletions(-) create mode 100644 v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md diff --git a/README.md b/README.md index f2c465782..a01de36d7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The RSCG_Examples repository is a comprehensive documentation system that automa This system serves as both a learning resource for .NET developers interested in source generators and an automated pipeline for maintaining up-to-date documentation about the RSCG ecosystem -## Latest Update : 2026-06-30 => 30 June 2026 +## Latest Update : 2026-07-01 => 01 July 2026 If you want to see examples with code, please click ***[List V2](https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG)*** @@ -28,7 +28,7 @@ Those are the 274 Roslyn Source Code Generators that I have tested you can see a ( including 16 from Microsoft ) ### 274. [Dirge](https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge) , in the [Disposer](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#disposer) category -Generated on : 2023-07-01 => 01 July 2023 +Generated on : 2026-07-01 => 01 July 2026
Expand diff --git a/later.md b/later.md index 6609fbb71..8c0ad9ff3 100644 --- a/later.md +++ b/later.md @@ -1,6 +1,6 @@ # Just later -## Latest Update : 2026-06-30 => 30 June 2026 +## Latest Update : 2026-07-01 => 01 July 2026 diff --git a/v2/RSCGExamplesData/GeneratorDataRec.json b/v2/RSCGExamplesData/GeneratorDataRec.json index 69830e035..dac3dcc7f 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1658,7 +1658,7 @@ { "ID": "Dirge", "Category": 18, - "dtStart": "2023-07-01T00:00:00", + "dtStart": "2026-07-01T00:00:00", "show": true } ] \ No newline at end of file diff --git a/v2/rscg_examples/Dirge/description.json b/v2/rscg_examples/Dirge/description.json index 642b070ed..ee36a735c 100644 --- a/v2/rscg_examples/Dirge/description.json +++ b/v2/rscg_examples/Dirge/description.json @@ -9,7 +9,17 @@ "source":"https://github.com/IkuzakIkuzok/Dirge" }, "data":{ - "goodFor":["Generating disposable"], + "goodFor":["", +"", +"**Dirge** is a Roslyn-based code generator that automatically implements the `IDisposable` pattern for C# classes.", +"", +"Key Features:", +"", +"1. **AutoDispose Attribute**: Mark any partial class with `[AutoDispose]` to automatically generate `Dispose()` and `Dispose(bool)` methods.", +"", +"2. **Automatic Field Disposal**: The generator detects all disposable fields and automatically calls `.Dispose()` on them in the correct order.", +"" +], "csprojDemo":"IDisp.csproj", "csFiles":["Program.cs","DALDB.cs","ConnectionDB.cs"], "excludeDirectoryGenerated":[""], diff --git a/v2/rscg_examples/Dirge/video.json b/v2/rscg_examples/Dirge/video.json index c75958ea3..c1388bbcb 100644 --- a/v2/rscg_examples/Dirge/video.json +++ b/v2/rscg_examples/Dirge/video.json @@ -8,7 +8,7 @@ {"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG"}, {"typeStep":"text","arg": "My name is Andrei Ignat and I am deeply fond of Roslyn Source Code Generator. "}, -{"typeStep":"text","arg": "Today I will present Dirge . Generating disposable ."}, +{"typeStep":"text","arg": "Today I will present Dirge . **Dirge** is a Roslyn-based code generator that automatically implements the `IDisposable` pattern for C# classes.Key Features:1. **AutoDispose Attribute**: Mark any partial class with `[AutoDispose]` to automatically generate `Dispose()` and `Dispose(bool)` methods.2. **Automatic Field Disposal**: The generator detects all disposable fields and automatically calls `.Dispose()` on them in the correct order. ."}, {"typeStep":"browser","arg":"https://www.nuget.org/packages/Dirge/"}, {"typeStep":"text","arg": "The whole example is here"}, {"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge"}, diff --git a/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md b/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md index 3fefb7e00..f7d6ce88e 100644 --- a/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md +++ b/v2/rscg_examples_site/docs/Authors/Kazuki_Kohzuki.md @@ -3,5 +3,5 @@ Number RSCG: 1 - 1 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2023-07-01 + 1 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2026-07-01 diff --git a/v2/rscg_examples_site/docs/Categories/Disposer.md b/v2/rscg_examples_site/docs/Categories/Disposer.md index d783afc97..d5225746d 100644 --- a/v2/rscg_examples_site/docs/Categories/Disposer.md +++ b/v2/rscg_examples_site/docs/Categories/Disposer.md @@ -6,7 +6,7 @@ Number RSCG: 7 2 [Coplt.Dropping](/docs/Coplt.Dropping) [![Nuget](https://img.shields.io/nuget/dt/Coplt.Dropping?label=Coplt.Dropping)](https://www.nuget.org/packages/Coplt.Dropping/) ![GitHub Repo stars](https://img.shields.io/github/stars/2A5F/Coplt.Dropping?style=social) 2024-08-13 - 3 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2023-07-01 + 3 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2026-07-01 4 [DisposableHelpers](/docs/DisposableHelpers) [![Nuget](https://img.shields.io/nuget/dt/DisposableHelpers?label=DisposableHelpers)](https://www.nuget.org/packages/DisposableHelpers/) ![GitHub Repo stars](https://img.shields.io/github/stars/Kiryuumaru/DisposableHelpers?style=social) 2023-10-09 diff --git a/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx b/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx index de3950dc8..28fda18bb 100644 --- a/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx +++ b/v2/rscg_examples_site/docs/Categories/_PrimitiveDisposer.mdx @@ -4,7 +4,7 @@ 2 [Coplt.Dropping](/docs/Coplt.Dropping) [![Nuget](https://img.shields.io/nuget/dt/Coplt.Dropping?label=Coplt.Dropping)](https://www.nuget.org/packages/Coplt.Dropping/) ![GitHub Repo stars](https://img.shields.io/github/stars/2A5F/Coplt.Dropping?style=social) 2024-08-13 - 3 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2023-07-01 + 3 [Dirge](/docs/Dirge) [![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) ![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) 2026-07-01 4 [DisposableHelpers](/docs/DisposableHelpers) [![Nuget](https://img.shields.io/nuget/dt/DisposableHelpers?label=DisposableHelpers)](https://www.nuget.org/packages/DisposableHelpers/) ![GitHub Repo stars](https://img.shields.io/github/stars/Kiryuumaru/DisposableHelpers?style=social) 2023-10-09 diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md b/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md new file mode 100644 index 000000000..3be618826 --- /dev/null +++ b/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md @@ -0,0 +1,540 @@ +--- +sidebar_position: 2740 +title: 274 - Dirge +description: +slug: /Dirge +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import TOCInline from '@theme/TOCInline'; +import SameCategory from '../Categories/_PrimitiveDisposer.mdx'; + +# Dirge by Kazuki Kohzuki + + + + +## NuGet / site data +[![Nuget](https://img.shields.io/nuget/dt/Dirge?label=Dirge)](https://www.nuget.org/packages/Dirge/) +[![GitHub last commit](https://img.shields.io/github/last-commit/IkuzakIkuzok/Dirge?label=updated)](https://github.com/IkuzakIkuzok/Dirge) +![GitHub Repo stars](https://img.shields.io/github/stars/IkuzakIkuzok/Dirge?style=social) + +## Details + +### Info +:::info + +Name: **Dirge** + +Disposable Implementation Roslyn Generator Extension + +Author: Kazuki Kohzuki + +NuGet: +*https://www.nuget.org/packages/Dirge/* + + +You can find more details at https://github.com/IkuzakIkuzok/Dirge + +Source: https://github.com/IkuzakIkuzok/Dirge + +::: + +### Author +:::note +Kazuki Kohzuki +![Alt text](https://github.com/IkuzakIkuzok.png) +::: + +## Original Readme +:::note + + +### Dirge + +[![Test](https://github.com/IkuzakIkuzok/Dirge/actions/workflows/Test.yml/badge.svg)](https://github.com/IkuzakIkuzok/Dirge/actions/workflows/Test.yml) +[![Version](https://img.shields.io/nuget/v/Dirge?styles=flat)](https://www.nuget.org/packages/Dirge/#versions-body-tab) +[![Download](https://img.shields.io/nuget/dt/Dirge?styles=flat)](https://www.nuget.org/packages/Dirge/#versions-body-tab) +[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/IkuzakIkuzok/Dirge/blob/main/LICENSE) + +Disposable Implementation Roslyn Generator Extension +###### Installation + +You can install the EnumSerializer from [NuGet](https://www.nuget.org/packages/Dirge/). + +###### Usage + +Mark a class with the `[AutoDispose]` attribute and implement the `IDisposable` interface. +The generator will automatically generate the implementation of the `Dispose` method for you. + +```C# +using Dirge; + +namespace Test; + +[AutoDispose] +internal partial class TestClass +{ + private readonly Stream _stream = new MemoryStream(); +} +``` + +The generated code will look like this: +```C# +namespace Test; + +partial class TestClass : IDisposable +{ + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + this._stream?.Dispose(); + } + } + finally + { + this.__generated_disposed = true; + } + } +} +``` + +Note that this example is simplified for demonstration purposes. + +To suppress the auto-generated Dispose call for a specific field, you can use the `[DoNotDispose]` attribute: +```C# +using Dirge; + +namespace Test; + +[AutoDispose] +internal partial class TestClass +{ + private readonly Stream _stream1 = new MemoryStream(); + + [DoNotDispose] + private readonly Stream _stream2 = new MemoryStream(); // This field will not be disposed by the generated Dispose method. +} +``` + +Ref-struct is also supported, but `IDisposable` will not be implemented regardless of the language version. + +######### Conditional disposal + +Conditional disposal, which allows you to specify conditions under which a field should be disposed, is also supported. +You can use the `[DoNotDisposeWhen]` attribute with a boolean field and a value to compare against: +```C# +using Dirge; + +namespace Test; + +[AutoDispose] +internal partial class TestClass +{ + private readonly bool _leaveOpen; + + [DoNotDisposeWhen(nameof(_leaveOpen), true)] + private readonly Stream _stream; + + internal TestClass(Stream stream, bool leaveOpen) + { + this._stream = stream; + this._leaveOpen = leaveOpen; + } +} +``` + +This will prevent the generator from disposing the `_stream` field when the `_leaveOpen` field is `true`: +```C# +namespace Test; + +partial class TestClass : IDisposable +{ + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + if (!this._leaveOpen) + { + this._stream?.Dispose(); + } + } + } + finally + { + this.__generated_disposed = true; + } + } +} +``` + +######### Unmanaged resources + +To safely release unmanaged resources, this generator also supports the implementation of a finalizer. +You can specify a method to release unmanaged resources through the `ReleaseUnmanagedResources` option: +```C# +using Dirge; +using System.IO; + +namespace Test; + +[AutoDispose(ReleaseUnmanagedResources = nameof(ReleaseUnmanagedResources))] +internal sealed partial class TestClass +{ + private readonly Stream _stream; + + internal void ReleaseUnmanagedResources() + { + // Custom logic to release unmanaged resources + } +} +``` + +This will generate a finalizer that calls the specified method to release unmanaged resources: +```C# +namespace Test; + +sealed partial class TestClass : IDisposable +{ + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + this._stream?.Dispose(); + } + + ReleaseUnmanagedResources(); + } + finally + { + this.__generated_disposed = true; + } + } + + ~TestClass() + { + Dispose(false); + } +} +``` + +###### Constraints + +To generate the `Dispose` method, the class (or struct) must meet the following constraints: +- It must be a non-static class. +- It must be a partial class or struct. +- It must not be a readonly struct. + +For conditional disposal, the field specified in the `nameof` expression must be a boolean field. +Properties and methods are not supported for the current version. + + +::: + +### About +:::note + + + + + + + +**Dirge** is a Roslyn-based code generator that automatically implements the `IDisposable` pattern for C# classes. + + + + + +Key Features: + + + + + +1. **AutoDispose Attribute**: Mark any partial class with `[AutoDispose]` to automatically generate `Dispose()` and `Dispose(bool)` methods. + + + + + +2. **Automatic Field Disposal**: The generator detects all disposable fields and automatically calls `.Dispose()` on them in the correct order. + + + + + +::: + +## How to use + +### Example (source csproj, source files) + + + + + +This is the CSharp Project that references **Dirge** +```xml showLineNumbers {14} + + + + Exe + net10.0 + enable + enable + + + true + $(BaseIntermediateOutputPath)\GX + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + +``` + + + + + + This is the use of **Dirge** in *Program.cs* + +```csharp showLineNumbers +using IDisposableGeneratorDemo; +//https://github.com/benutomo-dev/RoslynComponents +using (var db = new DALDB()) +{ + Console.WriteLine("before releasing"); +} +Console.WriteLine("after releasing"); +``` + + + + + This is the use of **Dirge** in *DALDB.cs* + +```csharp showLineNumbers +namespace IDisposableGeneratorDemo; + +[Dirge.AutoDispose] +partial class DALDB +{ + private ConnectionDB cn; + private ConnectionDB cn1; + + public DALDB() + { + cn = new ConnectionDB(); + cn1=new ConnectionDB(); + } + +} + +``` + + + + + This is the use of **Dirge** in *ConnectionDB.cs* + +```csharp showLineNumbers +namespace IDisposableGeneratorDemo; + +class ConnectionDB : IDisposable +{ + static int count = 0; + public ConnectionDB() + { + Interlocked.Increment(ref count); + } + public void Dispose() + { + Console.WriteLine($"disposing connectiondb {Interlocked.Decrement(ref count)}"); + } +} + +``` + + + + +### Generated Files + +Those are taken from $(BaseIntermediateOutputPath)\GX + + + + +```csharp showLineNumbers +// + +#pragma warning disable CS0282 + +namespace IDisposableGeneratorDemo +{ + partial class DALDB : global::System.IDisposable + { + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Diagnostics.DebuggerBrowsable(global::System.Diagnostics.DebuggerBrowsableState.Never)] + [global::System.Runtime.CompilerServices.CompilerGenerated] + private bool __generated_disposed = false; + + public void Dispose() + { + Dispose(true); + global::System.GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.__generated_disposed) return; + + try + { + if (disposing) + { + this.cn?.Dispose(); + this.cn1?.Dispose(); + } + } + finally + { + this.__generated_disposed = true; + } + } + } +} + +``` + + + + +```csharp showLineNumbers +// + +#nullable enable + +namespace Dirge +{ + [global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + internal sealed class AutoDisposeAttribute : global::System.Attribute + { + public string? ReleaseUnmanagedResources \{ get; set; \} = null; + + internal AutoDisposeAttribute() \{ } + } +} +``` + + + + +```csharp showLineNumbers +// + +namespace Dirge +{ + [global::System.AttributeUsage(global::System.AttributeTargets.Field, Inherited = false, AllowMultiple = false)] + internal sealed class DoNotDisposeAttribute : global::System.Attribute + { + internal DoNotDisposeAttribute() \{ } + } +} +``` + + + + +```csharp showLineNumbers +// + +namespace Dirge +{ + [global::System.AttributeUsage(global::System.AttributeTargets.Field, Inherited = false, AllowMultiple = false)] + internal sealed class DoNotDisposeWhenAttribute : global::System.Attribute + { + internal string FlagName \{ get; } + + internal bool FlagCondition \{ get; } + + internal DoNotDisposeWhenAttribute(string flagName, bool flagCondition) + { + this.FlagName = flagName; + this.FlagCondition = flagCondition; + } + } +} +``` + + + + +## Useful + +### Download Example (.NET C#) + +:::tip + +[Download Example project Dirge ](/sources/Dirge.zip) + +::: + + +### Share Dirge + + + +https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge + + + diff --git a/v2/rscg_examples_site/docs/indexRSCG.md b/v2/rscg_examples_site/docs/indexRSCG.md index 32b642b1b..c8ed1828c 100644 --- a/v2/rscg_examples_site/docs/indexRSCG.md +++ b/v2/rscg_examples_site/docs/indexRSCG.md @@ -20,7 +20,7 @@ This is the list of 274 ( 16 from Microsoft) RSCG with examples | No | Name | Date | Category | | --------- | ----- | ---- | -------- | -|274| [Dirge by Kazuki Kohzuki ](/docs/Dirge)|2023-07-01 => 01 July 2023 | [Disposer](/docs/Categories/Disposer) | +|274| [Dirge by Kazuki Kohzuki ](/docs/Dirge)|2026-07-01 => 01 July 2026 | [Disposer](/docs/Categories/Disposer) | |273| [ScottEncodingGenerator by Georgiy Petrov ](/docs/ScottEncodingGenerator)|2026-06-30 => 30 June 2026 | [FunctionalProgramming](/docs/Categories/FunctionalProgramming) | |272| [AlephMapper by Yevhen Cherkes ](/docs/AlephMapper)|2026-06-29 => 29 June 2026 | [Database](/docs/Categories/Database) | |271| [TypedStateBuilder.Generator by Georgiy Petrov ](/docs/TypedStateBuilder.Generator)|2026-05-16 => 16 May 2026 | [Builder](/docs/Categories/Builder) | diff --git a/v2/rscg_examples_site/static/exports/RSCG.json b/v2/rscg_examples_site/static/exports/RSCG.json index da909bdc3..ca247ae61 100644 --- a/v2/rscg_examples_site/static/exports/RSCG.json +++ b/v2/rscg_examples_site/static/exports/RSCG.json @@ -2192,7 +2192,7 @@ "NuGet": "https://www.nuget.org/packages/Dirge/", "Source": "https://github.com/IkuzakIkuzok/Dirge", "Category": "Disposer", - "AddedOn": "2023-07-01T00:00:00" + "AddedOn": "2026-07-01T00:00:00" } ] } \ No newline at end of file From 2c161ef66eb18cdbc6a812362f5709faca23eec0 Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Sun, 5 Jul 2026 09:59:16 +0300 Subject: [PATCH 3/4] zip --- v2/book/examples/Dirge.html | 80 ++++++++++++++++++ v2/book/list.html | 6 +- v2/book/pandocHTML.yaml | 1 + v2/docFind.json | 6 ++ .../static/sources/Dirge.zip | Bin 0 -> 1848 bytes 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 v2/book/examples/Dirge.html create mode 100644 v2/rscg_examples_site/static/sources/Dirge.zip diff --git a/v2/book/examples/Dirge.html b/v2/book/examples/Dirge.html new file mode 100644 index 000000000..ba480b25a --- /dev/null +++ b/v2/book/examples/Dirge.html @@ -0,0 +1,80 @@ + +

RSCG nr 274 : Dirge

+ +

Info

+Nuget : https://www.nuget.org/packages/Dirge/ + +

You can find more details at : https://github.com/IkuzakIkuzok/Dirge

+ +

Author :Kazuki Kohzuki

+ +

Source: https://github.com/IkuzakIkuzok/Dirge

+ +

About

+ +**Dirge** is a Roslyn-based code generator that automatically implements the `IDisposable` pattern for C# classes.Key Features:1. **AutoDispose Attribute**: Mark any partial class with `[AutoDispose]` to automatically generate `Dispose()` and `Dispose(bool)` methods.2. **Automatic Field Disposal**: The generator detects all disposable fields and automatically calls `.Dispose()` on them in the correct order. + +

+ How to use +

+

+ Add reference to the Dirge in the csproj +

+ + +

This was for me the starting code

+ +
+ I have coded the file Program.cs +
+ +
+ +
+ I have coded the file DALDB.cs +
+ +
+ +
+ I have coded the file ConnectionDB.cs +
+ +
+

And here are the generated files

+ +
+ The file generated is DALDB.GeneratedDispose.g.cs +
+ + +
+ The file generated is AutoDisposeAttribute.g.cs +
+ + +
+ The file generated is DoNotDisposeAttribute.g.cs +
+ + +
+ The file generated is DoNotDisposeWhenAttribute.g.cs +
+ + +

+ You can download the code and this page as pdf from + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/Dirge + +

+ + +

+ You can see the whole list at + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG + +

+ diff --git a/v2/book/list.html b/v2/book/list.html index 35f18431c..8e3fe29b8 100644 --- a/v2/book/list.html +++ b/v2/book/list.html @@ -17,7 +17,7 @@

-This is the list of 273 RSCG with examples => +This is the list of 274 RSCG with examples =>

@@ -1118,6 +1118,10 @@

+ + + +
273 ScottEncodingGenerator
274Dirge
diff --git a/v2/book/pandocHTML.yaml b/v2/book/pandocHTML.yaml index bcabfbc43..d893be639 100644 --- a/v2/book/pandocHTML.yaml +++ b/v2/book/pandocHTML.yaml @@ -287,6 +287,7 @@ input-files: - examples/TypedStateBuilder.Generator.html - examples/AlephMapper.html - examples/ScottEncodingGenerator.html +- examples/Dirge.html # or you may use input-file: with a single value # defaults: diff --git a/v2/docFind.json b/v2/docFind.json index b8e962f3d..c8c648642 100644 --- a/v2/docFind.json +++ b/v2/docFind.json @@ -1636,5 +1636,11 @@ "category": "FunctionalProgramming", "href": "/RSCG_Examples/v2/docs/ScottEncodingGenerator/", "body": "Roslyn incremental source generator for partial interfaces and abstract partial classes that generates Match methods, nested case implementations, and companion module helpers for Scott-encoded types." + }, + { + "title": "Dirge", + "category": "Disposer", + "href": "/RSCG_Examples/v2/docs/Dirge/", + "body": "Disposable Implementation Roslyn Generator Extension" } ] \ No newline at end of file diff --git a/v2/rscg_examples_site/static/sources/Dirge.zip b/v2/rscg_examples_site/static/sources/Dirge.zip new file mode 100644 index 0000000000000000000000000000000000000000..9603ea71c9aed23f388bd2140ac0377d02ea2438 GIT binary patch literal 1848 zcmZ{kc{G%J9LC?lWXW!nsM{EfhG<0A(#S-UrP0{$BokSRv5dOuCi`x58$0F5Qpr|g z>`Ms^hHST?OIgNTYARHOoBLMBa_(_|@A>`np5OC5=X0L#^We>R`CtG52ms**pB-B< zu$y!U0Fd|qKoIMh(R78K%Ki~ChtZ8&@B zSeR4|LiZ`Uq+{-U5KEc6^Frz$hdlLdhPKxlau!D?C}00s?7U=HzSPOn%<6J0pLS^QZ<3*7ae zMMt$dw(2=PiToI6(MN9+ka|@cL1gB)6dd*hd05w-8ACccY9;T$_PLlCnS)hln zY7pGmXSs28N6+eNs=g{ReJLSmpE}Ej<#WMEPyu%obbmgNRL8k)M%!n#8t@L#J7fTJhCFQ2CmhL!1_!RADQ$fkPJv~w^s~7W*8*gq|*V>bR{iDf5S*oG# zLfC5=^3C!lDR9X>i3crxd zZWEXAuLB-be9~_V?80U9JPQ=|KuR{pHp7Mc?PILs5HKH0S(ZZSJRg4DTyaY_QSQ~H zy|tjJSkPeUHFFOb`;f`!T>?CP$k=1*E)?&?M?z0A;@D-(H$9Tsb3{(~}z3R0rQqZTluV{Mlu^rJ-wLj)Q_b%`zV zp`Rpa*8H=K-PaV)KB4=)Fj^gpT0Yvi8W@ZgP3DmeyG=(eMl|H9X&mn|ydYaoI~EsC zpT!oDyBeJXk`c~bJNC##qe9<*xhis+SP+7eAJ%jWqq-xLN;rjwioemB2kC&zhhkLU z1NEk=z(kTq==7Y@{R^LQTHI4_w0q1s&<&0kAji`*qK6a6Fv0@>lIt8lbLm3y_4m0D zNwctQL5oMew4T{h90T>DAyO^WX8Ua&@GARapmI7HI|%KG@BHo%sZi5#Ay(mF)cr7a z{nwSYo{0}VWdRQcRVPopj~|5Bj@8(jsG+lk-5(_(hPeR-5m$A6n+<0Y*f z<6Z>Fo<`$Ltr<*Lx)V>Lmg<vNl^TzdDiSPqGj&T8yT9@~Dzu*P-U z!Pp$LebvTanEjktLgvaviN3vYY4XX-ePvX(Dm}u$K4e=4FT+*c3ljc!W*rneDN!+Y zQZ#p-#Z?mG%tX#tW?d%<=iD(DIQkI9eeS%=)mv#!a>W`$Q z2pm#-FZuEtyryTh@<@5`*GM?dfT8W%XZ{y=;Kq2<!_zZm z)p=-f9)H@n98+1&hCARWPfQ-NcFWos3DZFhbS0v##Mr2-Q5_1C8R1cg`vON;rx2=B zp>?oe>sRP!d*?;)W)L12@c(@eB5gYB?Y~*JRg-LJM!;45A^UHyY#y;yJ~u{mfSdkv x#9CT6Yq!e8hL*;=rrn&7&HAle+|a|JYx)gO@n+C%-(Nt%PYc9*5556_e*qPz{3HMX literal 0 HcmV?d00001 From a61b17e9a8257421befcaf9d1534713a418f6def Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Sun, 5 Jul 2026 10:03:11 +0300 Subject: [PATCH 4/4] desc --- v2/rscg_examples/Dirge/description.json | 6 +++--- v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/v2/rscg_examples/Dirge/description.json b/v2/rscg_examples/Dirge/description.json index ee36a735c..39601777a 100644 --- a/v2/rscg_examples/Dirge/description.json +++ b/v2/rscg_examples/Dirge/description.json @@ -11,13 +11,13 @@ "data":{ "goodFor":["", "", -"**Dirge** is a Roslyn-based code generator that automatically implements the `IDisposable` pattern for C# classes.", +"Dirge is a Roslyn-based code generator that automatically implements the `IDisposable` pattern for C# classes.", "", "Key Features:", "", -"1. **AutoDispose Attribute**: Mark any partial class with `[AutoDispose]` to automatically generate `Dispose()` and `Dispose(bool)` methods.", +"1. AutoDispose Attribute: Mark any partial class with `[AutoDispose]` to automatically generate `Dispose()` and `Dispose(bool)` methods.", "", -"2. **Automatic Field Disposal**: The generator detects all disposable fields and automatically calls `.Dispose()` on them in the correct order.", +"2. Automatic Field Disposal: The generator detects all disposable fields and automatically calls `.Dispose()` on them in the correct order.", "" ], "csprojDemo":"IDisp.csproj", diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md b/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md index 3be618826..d299ddb0b 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/Dirge.md @@ -1,7 +1,7 @@ --- sidebar_position: 2740 title: 274 - Dirge -description: +description: Generating IDisposable automatically for any fields. slug: /Dirge --- import Tabs from '@theme/Tabs';