C# template engine [closed]

Solution 1:

I have used StringTemplate with good results. Some resources:

  • Five minute introduction
  • Article on CodeProject showing example use from C#

Solution 2:

What about T4, Text Template Transformation Toolkit? It should fit your requirements, and is built-in in Visual Studio.

Great T4 resources:

Oleg Sych's blog

T4 Editor

T4 Toolbox

Solution 3:

There is a nice article how to use RazorView engine: How to create a localizable text template engine using RazorEngine

Solution 4:

SmartFormat is a pretty simple library that meets all your requirements. It is focused on composing "natural language" text, and is great for generating data from lists, or applying conditional logic.

The syntax is extremely similar to String.Format, and is very simple and easy to learn and use. Here's an example of the syntax from the documentation:

Smart.Format("{Name}'s friends: {Friends:{Name}|, |, and}", user)
// Result: "Scott's friends: Michael, Jim, Pam, and Dwight"

The library is open source and easily extensible, so you can also enhance it with additional features.