MbSoftLab.TemplateEngine.Core 1.0.5

.NET Core 2.1
There is a newer version of this package available.
See the version list below for details.
dotnet add package MbSoftLab.TemplateEngine.Core --version 1.0.5
NuGet\Install-Package MbSoftLab.TemplateEngine.Core -Version 1.0.5
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="MbSoftLab.TemplateEngine.Core" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MbSoftLab.TemplateEngine.Core --version 1.0.5
#r "nuget: MbSoftLab.TemplateEngine.Core, 1.0.5"
#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.
// Install MbSoftLab.TemplateEngine.Core as a Cake Addin
#addin nuget:?package=MbSoftLab.TemplateEngine.Core&version=1.0.5

// Install MbSoftLab.TemplateEngine.Core as a Cake Tool
#tool nuget:?package=MbSoftLab.TemplateEngine.Core&version=1.0.5


namespace MbSoftLab.TemplateEngine.Core
    public class TemplateEngine : TemplateEngine<object>{}

    public class TemplateEngine<T>{...}

The TemplateEngine replaces values from properties of C# classes in template strings. The C# class with the data holding properties is called the TemplateDataModel class. The string with the placeholders is called a string template or template string.

You can bind the value from your C-property to your string template by using ${YourPropertyName}. You can set a custom delimiters. Use the OpeningDelimiter and CloseingDelimiter properties to handle this.

Also you can access parameterless public methods of TemplateDataModell classes by using ${MethodName()} in your template.

The default is ${ for the start delimiter and } for the end delimiter.

picture of what can done by the TemplateEngine

 Person person = new Person
     FirstName = "Jo",

string template = "<MyTag>${FirstName}, ${LastName}</MyTag>";

TemplateEngine templateEngine = new TemplateEngine(person,template);
string outputString = templateEngine.CreateStringFromTemplate();

Console.Write(outputString); // Output: <MyTag>Jo, Doe</MyTag> 

Install Package

NuGet Package: https://www.nuget.org/packages/MbSoftLab.TemplateEngine.Core/

PM> Install-Package MbSoftLab.TemplateEngine.Core


Methodname Description
string CreateStringFromTemplate([string template]) Creates a String from Datamodell and Template
void LoadTemplateFromFile(string filename) Loads a Stringtemplate from file.
TemplateEngine() Constructor
TemplateEngine(object templateDataModel, string stringTemplate) Constructor
TemplateEngine(object templateDataModel) Constructor
TemplateEngine<T>() Constructor
TemplateEngine<T>(T templateDataModel, string stringTemplate) Constructor
TemplateEngine<T>(T templateDataModel) Constructor


Propertyname Datatype Description
OpeningDelimiter String Set the beginning delimiter for propertyreplacement
CloseingDelimiter String Set the ending delimiter for propertyreplacement
TemplateDataModel Generic / object Modell with Properys for Dataholding
TemplateString string Templatestring
NullStringValue string String for NULL-Values


Load the template and fill with Data from modell

// Create a modell Class for Data
 TemplateDataModel templateDataModel = new TemplateDataModel
     ProjektName = "Projektname"

string template = "<MyTag>${ProjektName}</MyTag>";

TemplateEngine templateEngine = new TemplateEngine(templateDataModel,template);
string outputString = templateEngine.CreateStringFromTemplate();

Console.Write(outputString); // Ausgabe: <MyTag>Projektname</MyTag> 

Load template from file

    TemplateDataModel templateDataModel = new TemplateDataModel
      ProjektName = "Projektname",
      KundeNummer = "1234",
      ProjektLink = "https://google.de",
      ProjektKuerzel = "PKZL"

     TemplateEngine templateEngine = new TemplateEngine(templateDataModel);
     string outputString = templateEngine.CreateStringFromTemplate();


Template and model over PropertyInjection

 TemplateDataModel templateDataModel = new TemplateDataModel
     ProjectName = "Projectname",
     KundeNummer = "1234",
     ProjektLink = "https://google.de",
     ProjektKuerzel = "PKZL"

 string template = "<p>${ProjectName}</p>";
 TemplateEngine templateEngine = new TemplateEngine();
 templateEngine.TemplateDataModel = templateDataModel;
 templateEngine.TemplateString = template;

Template and model over DependencyInjection

  TemplateDataModel templateDataModel = new TemplateDataModel
      ProjectName = "Projectname",
      KundeNummer = "1234",
      ProjektLink = "https://google.de",
      ProjektKuerzel = "PKZL"

  string template = "<p>${ProjectName}</p>";
  TemplateEngine templateEngine = new TemplateEngine(templateDataModel,template);

TemplateEngine with PropertyInjection and generic type

 TemplateDataModel templateDataModel = new TemplateDataModel
     ProjectName = "Projectname",
     KundeNummer = null,
     ProjektLink = "https://google.de",
     ProjektKuerzel = "KZ"

 string template = "<p>{{ProjectName}}</p><p>{{KundeNummer}}</p>";
 TemplateEngine<TemplateDataModel> templateEngine = new TemplateEngine<TemplateDataModel>()
     TemplateDataModel = templateDataModel,
     TemplateString = template,
     OpeningDelimiter = "{{",
     CloseingDelimiter = "}}",
     NullStringValue = "???"

Datatype compatibility

  • ✔ String
  • ✔ Byte
  • ✔ Short
  • ✔ UShort
  • ✔ Long
  • ✔ ULong
  • ✔ SByte
  • ✔ Char
  • ✔ UInt16
  • ✔ Int32
  • ✔ UInt64
  • ✔ Int16
  • ✔ Int32
  • ✔ Int64
  • ✔ Decimal
  • ✔ Double
  • ✔ DateTime
  • ✔ Boolean
  • ❌ Object
  • ❌ CustomClasses
  • ❌ IList, List, Dictionary, IEnumerable, etc..




report an issue


Code licensed under MIT

Documentation licensed under CC BY 4.0.

Product 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-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MbSoftLab.TemplateEngine.Core:

Package Downloads

Der SwaggerUiHeaderBuilder erstellt einen Spezial-Header für das Swagger Ui

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8-preview2 1,795 1/1/2021
1.0.8-preview 332 12/25/2020
1.0.7 853 12/25/2020
1.0.7-preview 221 12/13/2020
1.0.5 570 11/8/2020
1.0.4 634 4/26/2020