Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IMHO the two most important concepts when writing complex templates is </p> <ol> <li><strong>Separating the model and the view</strong> - This helps keeping the template logic to a minimum (often a cause of maintenance problem). Personally I don't think this requires a framework, it only requires that you do it.</li> <li><strong>Partial is your friend</strong> - I use T4 in general to generate skeleton code from the model. Specific behavior might not be worth the effort to put in the model, better often to allow that behavior come in through the use of partial classes or methods.</li> </ol> <p>Not as important but nice</p> <ol> <li><strong>Make the code searchable</strong> - I don't rely on T4 Addons because I find none of them good enough, with the lack of IntelliSense in order to navigate the code I have to make the code searchable. It can be as simple as instead of calling a Column property Name, I call it ColumnName.</li> <li><strong>Insert "tags" in the output</strong> - Makes it easier finding the code that generated that part of the output.</li> </ol> <p>Example separating model/view:</p> <pre><code>&lt;# // Model for Dependency Pooperties Model = new [] { new ClassDefinition ("MyDataGrid") { P ("CultureInfo" , "CultureInfo"), P ("Pen" , "CellBorderPen"), P ("IEnumerable&lt;object&gt;" , "Rows"), C ("WColumnDefinition" , "Columns"), }, }; #&gt; // Include the view &lt;#@ include file="..\T4\DependencyProperties.ttinclude" #&gt; </code></pre> <p>The view then iterates over the model and generate the dependency properties.</p> <p>The behavior of the dependency properties are then implemented as partial methods</p> <pre><code> partial void Changed_Columns( ObservableCollection&lt;WColumnDefinition&gt; oldValue, ObservableCollection&lt;WColumnDefinition&gt; newValue ) { HookUpColumns(oldValue, null); HookUpColumns(newValue, this); } </code></pre> <p>Note that putting this specific behavior into the model would significantly complicate the model.</p> <p>Finally; it takes time even for a competent programmer to write metaprograms competently. It took me several attempts before I arrived at a style which I believe is maintainable but for me it was worth the effort as I am able to ship quality faster.</p> <p>I hope this helps...</p> <p>PS. I don't Think anyone would argue T4 is ever elegant but it's darn useful nonetheless.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload