Codesmith practical skills (9): Reload the render method to control the output

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.