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
<PackageReference Include="SvSoft.Analyzers.GenericDecoratorGeneration" Version="1.0.0" />
<PackageVersion Include="SvSoft.Analyzers.GenericDecoratorGeneration" Version="1.0.0" />
<PackageReference Include="SvSoft.Analyzers.GenericDecoratorGeneration" />
paket add SvSoft.Analyzers.GenericDecoratorGeneration --version 1.0.0
#r "nuget: SvSoft.Analyzers.GenericDecoratorGeneration, 1.0.0"
#:package SvSoft.Analyzers.GenericDecoratorGeneration@1.0.0
#addin nuget:?package=SvSoft.Analyzers.GenericDecoratorGeneration&version=1.0.0
#tool nuget:?package=SvSoft.Analyzers.GenericDecoratorGeneration&version=1.0.0
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));
}
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 |