DKNet.Svc.Transformation 10.1.16

There is a newer version of this package available.
See the version list below for details.
dotnet add package DKNet.Svc.Transformation --version 10.1.16
                    
NuGet\Install-Package DKNet.Svc.Transformation -Version 10.1.16
                    
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="DKNet.Svc.Transformation" Version="10.1.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.Svc.Transformation" Version="10.1.16" />
                    
Directory.Packages.props
<PackageReference Include="DKNet.Svc.Transformation" />
                    
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 DKNet.Svc.Transformation --version 10.1.16
                    
#r "nuget: DKNet.Svc.Transformation, 10.1.16"
                    
#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 DKNet.Svc.Transformation@10.1.16
                    
#: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=DKNet.Svc.Transformation&version=10.1.16
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.Svc.Transformation&version=10.1.16
                    
Install as a Cake Tool

DKNet.Svc.Transformation

NuGet NuGet Downloads .NET License

Template-token substitution: fills bracketed tokens ([Name], {Email}, <Amount>, {{Ref}}) in a string from a plain object or a IDictionary<string, string>, with pluggable value formatting. Not an object mapper, and not a template engine — there are no conditionals, loops, or partials.

Features

  • ITransformerServiceTransform/TransformAsync a template against one or more parameter sources
  • Four built-in token styles (square/curly/angle/double-curly brackets), or define your own pair
  • Configurable behaviour when a token cannot be resolved (ThrowError, LeaveAsIs, Remove)
  • Pluggable IValueFormatter for bool/number/date formatting, invariant-culture by default
  • Global parameters shared across every template

Installation

dotnet add package DKNet.Svc.Transformation

Quick Start

using DKNet.Svc.Transformation;
using Microsoft.Extensions.DependencyInjection;

builder.Services.AddTransformerService(); // ITransformerService, transient

public sealed class WelcomeEmailBuilder(ITransformerService transformer)
{
    public Task<string> BuildAsync(User user) =>
        transformer.TransformAsync("Hello [Name], your account [Email] is ready.", user);
}

AddTransformerService(Action<TransformOptions>? optionFactory = null) is the only registration entry point. It builds one TransformOptions, registers it as IOptions<TransformOptions>, and registers ITransformerService → TransformerService as transient. It returns immediately if ITransformerService is already registered, so the first call's options win and a later call's delegate is silently ignored.

Configuration — TransformOptions

Configured in code through the delegate passed to AddTransformerService. There is no IConfiguration binding path for this package.

Option Type Default Effect
DefaultDefinitions ICollection<ITokenDefinition> (get-only) [SquareBrackets] Bracket styles recognised. Add more; the property has no setter, so square brackets stay active unless you Clear() the collection first.
Formatter IValueFormatter new ValueFormatter() Converts each resolved value to its display string.
GlobalParameters IEnumerable<object> [] Fallback resolution sources, tried after the call's own parameters.
TokenNotFoundBehavior TokenNotFoundBehavior ThrowError ThrowError throws UnResolvedTokenException; LeaveAsIs keeps the token text; Remove substitutes an empty string.

Built-in definitions, all static readonly on TransformOptions: SquareBrackets ([Token]), CurlyBrackets ({Token}), AngledBrackets (<Token>), DoubleCurlyBrackets ({{Token}}). Define your own with new TokenDefinition(begin, end), which throws ArgumentException for a null or whitespace tag.

ValueFormatter is a public class with virtual members — subclass it to change just the formats:

Property Type Default
DateFormat string "dd/MM/yyyy hh.mm.ss"
IntegerFormat string "###,##0"
NumberFormat string "###,##0.00"

bool renders as Yes/No; int/long use IntegerFormat; double/decimal/float use NumberFormat; DateTime/DateTimeOffset use DateFormat; anything else falls back to ToString(). All formatting runs against CultureInfo.InvariantCulture.

Public extension points

Type Accessibility Can you supply your own?
ITokenDefinition / TokenDefinition public interface / public sealed class Yes — add to DefaultDefinitions.
IValueFormatter / ValueFormatter public interface / public class with virtual members Yes — assign Formatter.
ITransformerService public interface Yes — register your own before calling AddTransformerService.
ITokenExtractor, ITokenResolver public interfaces, internal sealed implementations NoTransformerService constructs them itself; nothing reads yours.

Documentation

Full feature reference, diagrams, and gotchas: https://github.com/baoduy/DKNet/blob/main/docs/Services/DKNet.Svc.Transformation.md

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
10.1.19 0 9/3/2026
10.1.18 0 9/3/2026
10.1.17 0 9/3/2026
10.1.16 0 9/3/2026
10.1.15 61 9/1/2026
10.1.14 62 9/1/2026
10.1.13 75 8/31/2026
10.1.12 88 8/25/2026
10.1.11 92 8/24/2026
10.1.10 90 8/22/2026
10.1.9 99 8/22/2026
10.1.8 86 8/21/2026
10.1.7 85 8/21/2026
10.1.6 88 8/21/2026
10.1.5 106 8/20/2026
10.1.4 88 8/20/2026
10.1.3 98 8/19/2026
10.1.2 110 8/19/2026
10.1.1 88 8/19/2026
10.0.36 99 8/18/2026
Loading failed