Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# template engine [closed]

I have used StringTemplate with good results. Some resources:

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

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


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


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.


Have you looked at XSLT? You'll have to start with your source data format in XML, maybe by xmlserializing your data objects. You can do loops and if statements with ease!

Kathleen Dollard has a book on generating code via XSLT.

Personally, I'm a big fan of T4 (especially when generating C#), but you might find that since XML and HTML are your output types XSLT has you covered. Plus it's very cross-platform.