Wednesday, January 9, 2008

Text Templating (.tt) Validation

DSL supports a nice validation model for the Domain classes/model.

But what about the Text Templating requirements?

This are validations that apply only to a specific generation task. Let's say if have a property named DotNetType. It could be that this property does not affect generation of [t1] but I need this property for [t2]. For this cases, you will need to somehow validate in the (tt) Template itself.

Note: You could argue (please don't) that the example below is a bad example, I know but there are still some other real cases.

The 'correct' way

I must say that before finding out that I've tried this 2 other options:

  • Raise an exception (hard but work since it's integrated with the Error list as shown below):

  • Just add a comment to the output file (this is not always possible ( example : template based controls like GridView don't support XML comment inside their tpl tags..)

No comments: