Universal.Common.Text.Templating 1.1.0

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

Universal.Common.Text.Templating

A flexible and extensible text templating system that replaces placeholders in templates with values from objects.

Classes

TextTemplateRenderer

Renders text templates by replacing placeholders with provided values from object properties.

// Basic usage with default options ({{Name}} syntax)
var renderer = new TextTemplateRenderer();
string template = "Hello {{Name}}, welcome to {{City}}!";
var values = new { Name = "Alice", City = "Melbourne" };
string result = renderer.Render(template, values);
// Output: "Hello Alice, welcome to Melbourne!"

// Custom configuration
var renderer = new TextTemplateRenderer(new TextTemplateRenderer.Options
{
    RequireAllParameters = false,
    NullValueReplacement = "N/A",
    PlaceholderFormat = new DollarBracesPlaceholderFormat(),
    ValueFormatter = value => System.Web.HttpUtility.HtmlEncode(value.ToString())
});
Configuration Options
  • RequireAllParameters: When true, throws an exception if any placeholder lacks a corresponding property (default: true)
  • NullValueReplacement: String to use when a property value is null (default: empty string)
  • PlaceholderFormat: The placeholder syntax format to use (default: DoubleBracesPlaceholderFormat)
  • ValueFormatter: Custom function to format values before replacement (useful for HTML encoding, JSON escaping, etc.)
  • EnableRecursiveResolution: When true, if a replacement value itself contains placeholders, those are resolved too, repeating until the result stops changing or MaxRecursionDepth is reached (default: false)
  • MaxRecursionDepth: Maximum number of extra passes performed when EnableRecursiveResolution is true; guards against circular references (e.g. A resolves to {{B}} and B resolves to {{A}}). Set to null for unbounded recursion. (default: 10)
// Recursive resolution: values can reference other placeholders
var renderer = new TextTemplateRenderer(new TextTemplateRenderer.Options
{
    EnableRecursiveResolution = true
});
string template = "Hello {{Name}}";
var values = new { Name = "{{Greeting}}", Greeting = "World" };
string result = renderer.Render(template, values);
// Output: "Hello World"

When RequireAllParameters is true and EnableRecursiveResolution is true, a placeholder introduced by a value that has no matching property (e.g. Name resolves to {{Unknown}} and there is no Unknown property) also throws, just like a missing top-level parameter. Without recursion enabled, such text is left as-is and is never treated as an error, since it's just data that happens to look like a placeholder.

DoubleBracesPlaceholderFormat

Placeholder format using {{Name}} syntax, similar to Mustache and Handlebars templates.

var format = new DoubleBracesPlaceholderFormat();
var renderer = new TextTemplateRenderer(new TextTemplateRenderer.Options
{
    PlaceholderFormat = format
});

string template = "User: {{Username}}, Email: {{Email}}";

DollarBracesPlaceholderFormat

Placeholder format using ${Name} syntax, common in shell scripts and many templating systems.

var format = new DollarBracesPlaceholderFormat();
var renderer = new TextTemplateRenderer(new TextTemplateRenderer.Options
{
    PlaceholderFormat = format
});

string template = "User: ${Username}, Email: ${Email}";

IPlaceholderFormat

Interface for implementing custom placeholder formats. Implement this interface to support alternative placeholder syntaxes.

public class CustomPlaceholderFormat : IPlaceholderFormat
{
    public IEnumerable<PlaceholderMatch> Find(string text)
    {
        // Find all placeholders in the text
    }

    public string Replace(string text, string placeholderName, string value)
    {
        // Replace placeholders with values
    }
}

PlaceholderMatch

Represents a matched placeholder in a template, including its position and extracted name.

// Properties:
// - FullMatch: The complete matched text including delimiters (e.g., "{{Name}}")
// - Name: The placeholder name without delimiters (e.g., "Name")
// - Index: Starting position of the match in the text
// - Length: Length of the full match
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net8.0

    • 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.1.1 148 8/4/2026
1.1.0 122 8/4/2026
1.0.0 490 10/8/2025

Added opt-in recursive placeholder resolution (EnableRecursiveResolution/MaxRecursionDepth on Options) so a replacement value that itself contains a placeholder gets resolved too, with a depth cap guarding against circular references. RequireAllParameters now also validates recursively-introduced placeholders when recursion is enabled. Replacement is now a single order-independent pass per round, so the result no longer depends on reflected property order.