Class ActionDecorator<TIn>
- Namespace
- PatternKit.Structural.Decorator
- Assembly
- PatternKit.Core.dll
Fluent, allocation-light action decorator that wraps a component and applies layered enhancements for side effects (void-returning operations). Build once, then call Execute(in TIn) to run the component through the decorator pipeline.
public sealed class ActionDecorator<TIn>
Type Parameters
TInInput type passed to the component.
- Inheritance
-
ActionDecorator<TIn>
- Inherited Members
Examples
var decorator = ActionDecorator<string>.Create(msg => Console.WriteLine(msg))
.Before(msg => $"[{DateTime.Now}] {msg}") // Add timestamp
.After(msg => Console.WriteLine("---")) // Add separator after
.Build();
decorator.Execute("Hello"); // Prints timestamped message and separator
Remarks
Mental model: A base component (action) is wrapped by zero or more decorators. Each decorator can:
- Transform the input before passing it to the next layer (ActionDecorator<TIn>.BeforeTransform).
- Execute logic after the next layer completes (ActionDecorator<TIn>.AfterAction).
- Wrap the entire execution with custom logic (ActionDecorator<TIn>.AroundTransform).
Immutability: After Build(), the decorator chain is immutable and safe for concurrent reuse.
Methods
Create(Component)
Creates a new builder for constructing a decorated action.
public static ActionDecorator<TIn>.Builder Create(ActionDecorator<TIn>.Component component)
Parameters
componentActionDecorator<TIn>.Component
Returns
- ActionDecorator<TIn>.Builder
Execute(in TIn)
Executes the decorated component with the given input.
public void Execute(in TIn input)
Parameters
inputTIn