Address: http://www.cnblogs.com/huangcong/archive/2011/01/08/1930553.html
C # Code Generation Tool: The Text Template first experiences the Text Template (also called T4) of Hello world in Vs, which gives me a bit of codesmith feeling, it is also a method for batch generation of code by template and logic code mixing, but there is not much information about T4, and there is no smart awareness of the code written in the T4 template, but I would like to introduce some friends who may use it. Here are some simple examples to try it out. Of course, we should first start with the simplest Hello, world! Start ~
1. Hello, world! 1) create a new project.
Right-click--
New--
Text Template , Named
Newtemplate. TT:
2) After the creation is successful, the following two files will be generated in the project folder:
3) double-click Newtemplate. TT File with the following content:
4) Add a string under these texts" Hello, world! ", And save:
5) in the hosts file, you can see the same content:
Haha, a simple hello, world! Well done. Of course, this function is not worth moving to the table. Let's take a look at how to use it to dynamically generate text ~
Ii. dynamically generate code 1) Add the following code based on the original text:
< # For ( Int I = 0 ; I < 10 ; I ++ ){# >
I am a number: < # = I # > , My square is: < # = I * I # >
< #}# >
2.) Now, check newtemplate.txt. You can see the following content. Haha, isn't it like codesmith?
Summary: Well, the above two examples can help you get started. I will continue to tell you about other functions of the Text Template. Please pay attention to this article. Article Yes. Please click "recommended ~