In codesmith, The codetemplate. Render method is executed when the template execution is complete for the template output. You can modify the event processing in codesmith output by reloading the codetemplate. Render method. For example, you can modify the template output mode to replace the current default mode, the Code below demonstrates how to output the result to two different files while keeping the default window of codesmith displayed.
1 <% @ codetemplate Language = "C #" targetlanguage = "text" Description = "addtextwriter demonstration." %>
2 <% @ import namespace = "system. Io" %>
3 This template demonstrates using the addtextwriter Method
4to output the template results to multiple locations concurrently.
5 <SCRIPT runat = "template">
6 Public override void render (textwriter writer)
7 {
8 streamwriter filewriter1 = new streamwriter (@ "C: \ test1.txt", true );
9 This. response. addtextwriter (filewriter1 );
10
11 streamwriter filewriter2 = new streamwriter (@ "C: \ test2.txt", true );
12 This. response. addtextwriter (filewriter2 );
13
14 base. Render (writer );
15
16 filewriter1.close ();
17 filewriter2.close ();
18}
19 </SCRIPT>
Note that you cannot forget the base. Render (writer); statement. Otherwise, you will not be able to get the default output. You can also reload the codetemplate. Render Method
To access textwriter, you can also directly add other ancillary information to the template output content.