Universal.Common.Text.Templating 1.0.0

dotnet add package Universal.Common.Text.Templating --version 1.0.0
                    
NuGet\Install-Package Universal.Common.Text.Templating -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="Universal.Common.Text.Templating" Version="1.0.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.0.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.0.0
                    
#r "nuget: Universal.Common.Text.Templating, 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 Universal.Common.Text.Templating@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=Universal.Common.Text.Templating&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Universal.Common.Text.Templating&version=1.0.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.)

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.0.0 308 10/8/2025

Initial release of text templating system with support for double braces and dollar braces placeholder formats.