3

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 help 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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Qwertie
  • 16,354
  • 20
  • 105
  • 148
  • "A LISP"? ;-) I thought that .NET generics of value-types (when not running through boxing issues) where supposed to be very fast after their run-time specialization and JIT'ing (as opposed to Java/JVM which has no run-time specialization and only has boxed types for "generic" primitives). –  Apr 16 '11 at 06:04
  • Generics of value types are fast for purposes such as lists or dictionaries. However, a generic type cannot perform calculations on value types such as adding T + T together. I'm writing a math library so I'll be doing TONS of math on type T. – Qwertie Apr 16 '11 at 06:09

2 Answers2

4

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

Naraen
  • 3,240
  • 2
  • 22
  • 20
  • 1
    Wow, I certainly didn't expect this to be built-in! I'm using C# Express so here's an obligatory link: http://stackoverflow.com/questions/3309551/does-vs-2010-express-edition-support-t4-preprocessed-templates – Qwertie Apr 16 '11 at 06:21
1

The T4 code generation and templating engine comes with Visual Studio.

There's also String Template, which has a C# port.

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236