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
<PackageReference Include="Universal.Common.Text.Templating" Version="1.0.0" />
<PackageVersion Include="Universal.Common.Text.Templating" Version="1.0.0" />
<PackageReference Include="Universal.Common.Text.Templating" />
paket add Universal.Common.Text.Templating --version 1.0.0
#r "nuget: Universal.Common.Text.Templating, 1.0.0"
#:package Universal.Common.Text.Templating@1.0.0
#addin nuget:?package=Universal.Common.Text.Templating&version=1.0.0
#tool nuget:?package=Universal.Common.Text.Templating&version=1.0.0
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 | Versions 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. |
-
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.