Code Generation Tool-NCodeGenerate tutorial (4) CodeSmith template Conversion Tool-What is NCodeGenerate? Code Generation Tool-NCodeGenerate tutorial (1) traverse Databases

Source: Internet
Author: User

CodeSmith is one of the most widely used tools in code generation and has rich template resources and users. Many of my friends used CodeSmith and there are many ready-made templates. NCodeGenerate provides a template Conversion Tool from CodeSmith to NCodeGenerate. It makes it easier for users to switch from CodeSmith to NCodeGenerate. Next we will introduce it.

Open the tool menu> CodeSmith Conversion

    

In the window above, select the file to be converted and the file to be output, and click convert. Since some concepts in CodeSmith and NCodeGenerate templates do not fully correspond to each other, such conversions only involve simple structure and syntax conversions. The programmer must make adjustments on his own.

After the CodeSmith template is converted, the correspondence between NCodeGenerate and ncodesmith is as follows:

1. CodeTemplate command

Example: <% @ CodeTemplate Language = "C #" Inherits = "CsNHibernateHelper" Src = ".. /Helpers/CsNHibernateHelper. cs "TargetLanguage =" C # "Debug =" False "Description =" Generates a Business Object for nhib.pdf. "%>

There is no corresponding concept in NCodeGenerate and it is converted to an empty string.

Ii. Property

Example: <% @ Property Name = "SourceTable" Type = "SchemaExplorer. tableSchema "Optional =" False "Category =" 1a. source Table "Description =" The source table to generate from. "%>

Replace NCodeGenerate with an attribute of the Model class.

Public NCodeGenerate. DBSchema. TableSchema SourceTable {get; set ;}

Iii. Assembly

Example: <% @ Assembly Name = "SchemaExplorer" %>

Reference the Assembly in NCodeGenerate. As long as it is converted to an empty string, NCodeGenerate will automatically process the assembly.

Iv. Import Namespace

Example: <% @ Import Namespace = "SchemaExplorer" %>

The reference of the corresponding namespace in NCodeGenerate is converted into the following code:

@ Using NCodeGenerate. DBSchema;

V. script

For example:

<Script runat = "template">

The Code in all scripts in the template is extracted and stored as a code file with the same name as the conversion target but suffixed with cs.

Add the corresponding reference @ AssemblyFile reference instruction to the template.

Vi. Code of the template's <%> and <% = %> asp.net syntax

Convert all code to Razor format starting.

The template conversion function is described here. Wish you a happy New Year.

 

Appendix: NCodeGenerate adds the NCodeGenerate. DBSchema document, which is connected in the following document.

Attached:

NCodeGenerate.zip

Document: Document

 

NCodeGenerate series of articles:

I. What is NCodeGenerate? Ii. Code Generation Tool-NCodeGenerate tutorial (1) traverse all tables in the database III. Code Generation Tool-NCodeGenerate tutorial (2) code Generation Tool-NCodeGenerate tutorial (3) generate code to a file. 5. Code Generation Tool-NCodeGenerate tutorial (4) CodeSmith template conversion 6. Code Generation Tool-NCodeGenerate tutorial (5) support for multiple databases 7. Code Generation Tool-NCodeGenerate tutorial (6) NTrace output for debugging functions 8. Code Generation Tool-NCodeGenerate tutorial (7) unveil the mystery of the debugging function 9. Code Generation Tool-NCodeGenerate tutorial (8) unveil the secrets of the Razor template engine 10. Code Generation Tool-NCodeGenerate tutorial (9) Data Type ing Map function

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.