I'd like a preprocessing language for metaprogramming
I'm looking for a language sort of like PHP, but more brief -- I'm tempted to call it a "templating engine" but I'm pretty sure that's the wrong term. What is the right term? A text preprocessor?
Anyway I'd like it to be .NET-based because I want to use it to he开发者_运维百科lp write .NET code. Because .NET generics are unsuited for writing fast numeric code (the known workaround is too cumbersome and limited for my needs), I'd like to write a math library using some sort of preprocessing language that allows me to output C# code. For example, I'd like to generate a series of "Point" classes made from various data types (PointF, PointD, PointI, etc.):
#foreach(($T, $Type) in {(F, float), (D, double), (I, int), ...}) #{
public struct Point$T {
public $Type X, Y;
...
}
#}
What can you fine people suggest?
Have you had a chance to try T4 templates? That should be sufficient for what you are trying to achieve. http://msdn.microsoft.com/en-us/library/bb126445.aspx
The T4 code generation and templating engine comes with Visual Studio.
- Understanding T4: Preprocessed Text Templates
There's also String Template, which has a C# port.
精彩评论