Skip to main content

Coplt.Dropping by 2A5F

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: Coplt.Dropping

Auto gen dispose pattern

Author: 2A5F

NuGet: https://www.nuget.org/packages/Coplt.Dropping/

You can find more details at https://github.com/2A5F/Coplt.Dropping

Source : https://github.com/2A5F/Coplt.Dropping

Original Readme

note

Coplt.Dropping

Nuget MIT

Auto gen dispose pattern

  • Auto handle Dispose(bool dispoing) pattern
  • Auto handle destructor/finalizer
  • Allow multiple drops
  • Specify the drop order [Drop(Order = X)]
  • The first argument of Drop target method can be bool disposing
  • Mark Drop directly on fields and properties (requires target type have Dispose method)
  • Dose not supported AsyncDispose, too complicated, it is recommended to implement it manually
  • Drop can mark on static methods, will pass this on first argument, if have bool disposing will be the second argument

Example

  • Basic usage

    [Dropping]
    public partial class Foo1
    {
    [Drop]
    public void Drop()
    {
    Console.WriteLine(1);
    }
    }

    Generate output:

    Foo1.dropping.g.cs

About

note

Generating disposable

How to use

Example ( source csproj, source files )

This is the CSharp Project that references Coplt.Dropping

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Coplt.Dropping" Version="0.5.1" OutputItemType="Analyzer" />

</ItemGroup>

</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>

#nullable enable

using Coplt.Dropping;

namespace IDisposableGeneratorDemo {

internal partial class DALDB : global::System.IDisposable
{

protected virtual void Dispose(bool disposing)
{
if (disposing) Drop();
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~DALDB()
{
Dispose(false);
}

}

} // namespace IDisposableGeneratorDemo

Usefull

Download Example (.NET C# )

Share Coplt.Dropping

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Coplt.Dropping

In the same category (Disposer) - 4 other generators

BenutomoAutomaticDisposeImplSourceGenerator

DisposableHelpers

Disposer

IDisposableGenerator