4 ms·
I usually use T4 for such tasks. https://en.wikipedia.org/wiki/Text_Template_Transformation_Toolkit https://en.wikipedia.org/wiki/Text_Template_Transformation_T
by Const-me 8y ago
I usually use T4 for such tasks. https://en.wikipedia.org/wiki/Text_Template_Transformation_Toolkit https://en.wikipedia.org/wiki/Text_Template_Transformation_T...
Unlike macros, T4 includes a fully-featured programming language (C#), with all the goodies like collections, cryptography, globalization, etc..
- skrebbel 8y agoYeah, T4 is awesome. And for those readers here who don't like C# for good or bad reasons, you can pretty much do the same with other languages. Eg Ruby has ERB, usualy used for html templating but you can use it for anything. Make a command line tool that loads a a something.ext.erb file, runs it, and writes a something.ext file and you just made yourself a super powerful preprocessor that you already know how to use. Many languages have this (eg EJS in JavaScript, PHP itself in PHP (use output buffering), EEx in Elixir, etc). I'd use this over a "learn yet another language" preprocessor language anytime.
- nerdponx 8y agoLiquid and Jinja2 (both descendants of Django templating language) are also both used outside the web context now. For example, Conda package specs (called "recipes") are written in YAML, but are processed with Jinja2 first.
- skrebbel 8y agoYou still need to learn a new language though (the jinja2 language)
- mohammedbin 8y agoDoes it work on .NET core?
- Const-me 8y agoYou can use Razor engine, IMO they’re very comparable: https://github.com/toddams/RazorLight https://github.com/toddams/RazorLight