SvSoft.Analyzers.GenericDecoratorGeneration 1.0.0

dotnet add package SvSoft.Analyzers.GenericDecoratorGeneration --version 1.0.0
                    
NuGet\Install-Package SvSoft.Analyzers.GenericDecoratorGeneration -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SvSoft.Analyzers.GenericDecoratorGeneration" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SvSoft.Analyzers.GenericDecoratorGeneration" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SvSoft.Analyzers.GenericDecoratorGeneration" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SvSoft.Analyzers.GenericDecoratorGeneration --version 1.0.0
                    
#r "nuget: SvSoft.Analyzers.GenericDecoratorGeneration, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SvSoft.Analyzers.GenericDecoratorGeneration@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SvSoft.Analyzers.GenericDecoratorGeneration&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SvSoft.Analyzers.GenericDecoratorGeneration&version=1.0.0
                    
Install as a Cake Tool

Generic Policy Decorator Generator

A C# source generator that generates a universal decorator. Primary use-case is for decoration that does not depend on any method-specific context, e. g. to decorate each interface method with a retry on exceptions.

Usage

// The developer-provided partial class declares the interfaces to implement/decorate, and has the GenericDecorator attribute
[GenericDecorator]
partial class MyFooDecorator(IFoo inner) : IFoo
{
    // for each declared interface, implement a method to get an instance implementing that interface
    // the method will be used by the generated decoration
    private partial IFoo GetInnerIFoo() => inner;

    // implement four universal decoration methods,
    // one for each combination of sync/async and return/void

    private partial void Decorate(Action doInner)
    {
        // do other stuff
        doInner();
    }

    private partial T Decorate(Func<T> doInner)
    {
        // do other stuff
        return doInner();
    }

    private partial Task DecorateAsync(Func<Task> doInner)
    {
        // do other stuff
        return doInner();
    }

    private partial Task<T> DecorateAsync(Func<Task<T>> doInner)
    {
        // do other stuff
        return doInner();
    }
}

This source generator complements the developer-provided class with the boilerplate of wrapping each inner implementation method in a call to the appropriate universal decoration method.

Like this (not necessarily the exact generated code):

// assume this interface
interface IFoo
{
    void DoStuff();
    Task<string> GetStuffAsync(int arg1, string arg2);
}

// <auto-generated />
partial class MyFooDecorator
{
    // (omitted) partial declarations of the necessary methods

    void IFoo.DoStuff() => Decorate(() => inner.DoStuff());

    Task<string> IFoo.GetStuffAsync(int arg1, string arg2) => DecorateAsync(() => inner.GetStuffAsync(arg1, arg2));
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 250 11/16/2025
1.0.0-rc.2 198 11/16/2025
1.0.0-rc.1 191 11/16/2025