TemplR 1.0.2
dotnet add package TemplR --version 1.0.2
NuGet\Install-Package TemplR -Version 1.0.2
<PackageReference Include="TemplR" Version="1.0.2" />
paket add TemplR --version 1.0.2
#r "nuget: TemplR, 1.0.2"
// Install TemplR as a Cake Addin #addin nuget:?package=TemplR&version=1.0.2 // Install TemplR as a Cake Tool #tool nuget:?package=TemplR&version=1.0.2
TemplR
Serializable, Type-safe Payload Enrichment for .NET
Installing TemplR.
TemplR can be installed from nuget
Install-Package TemplR
or using the dotnet clr
dotnet add package TemplR
Creating a template proxy.
TemplR can auto-generate proxies from your own data objects that allow properties to be replaced by strongly typed variables. To create a proxy from an existing record or class you first need to install TemplR's code generator library:
Install-Package TemplR.Generator
Next define a new proxy by defining a new partial class decorated with the TemplateAttribute
[Template(typeof(Person))]
public partial class PersonTemplate {}
The TemplateAttribute takes a single argument equal to the type that is being proxied. You should now be able to create a new PersonTemplate instance, which will have proxiable versions of all the original class' properties...
var person = new PersonTemplate
{
Name = "Santa Claus",
Age = From.Variable("yearsSinceFirstChristmas"),
IsImaginary = From.Variable()
}
If no name is passed to From.Variable, then the variable will take the same name as the property it is assigned to.
This proxy can be passed to any method which accepts either Template or Template<Person> as a parameter.
Json Serialization and Deserialization.
TemplR supports both serialization and deserialization using System.Text.Json. To enable this functionality you need to install the following library...
Install-Package TemplR.System.Text.Json
To add the required converters, create a new instance of JsonSerializerOptions and call the UseTemplR() extension method on it.
JsonSerializerOptions serializerOptions = new()
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
serializerOptions.UseTemplR();
from that point on these options should be used for all calls to the JsonSerializer.
Serialization with variable values.
To serialize a template, with replacement values for any variables, first deserialize to the Template type, call SetVariables and then re-serialize it...
var template = JsonSerializer.Deserialize<Template>(json, serializerOptions);
template.SetVariables(new()
{
{ "yearsSinceFirstChristmas", 42 },
{ "isImaginary", false }
});
var jsonWithVariables = JsonSerializer.Serialize(template, serializerOptions);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TemplR:
Package | Downloads |
---|---|
TemplR.System.Text.Json
Integration for TemplR with System.Text.Json. |
GitHub repositories
This package is not used by any popular GitHub repositories.