First, the initial knowledge T4 engine

Source: Internet
Author: User

We are not unfamiliar with code generators, which is one of the more used tools in everyday coding. The main function of the general code generator is to generate public or basic code to reduce the workload of the coder, and a good code generator in addition to the production of code, but also the ability to build the project architecture and basic modules, so that developers focus on the core of the business logic, improve coding efficiency and reduce workload.

Now the most used code generation technology in the market is template generation technology, here is recommended a relatively good template generation engine T4 (Text template transformation Toolkit), because VisualStudio itself is also used it. As a very good IDE, presumably T4 can get its favor is enough to explain T4 excellent.

To create a new class library project with VS, right-click Add New item to add a text template

The file suffix is generally. tt is an executable file in VS, and the code in the file is automatically executed when you save it.

The TT template and the script in aspx, the executable code is included in <##>. Text that is not included in <##> is output directly to the destination file as static text.

We directly enter "HELLO,T4" in the space below the file to save a target file with the same name suffix. txt, open the file, you can see the following:

The static text in the TT template is output directly to the file. The use of T4 templates is described in detail in the next article.

So where does the VS use the T4? In fact, most of the files created by the template in VS are using T4. We randomly create a new class, which generates some basic code, which is T4 is the role, but T4 has been working in the background, we tend to ignore its role.

(Note: The default new TT template, VS is not support syntax highlighting and smart hints, for ease of writing and presentation, I installed the syntax highlighting plugin, I am using the T4 Editor, in the VS online template can be downloaded to)

First, the initial knowledge T4 engine

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.