Code Generation Tool-NCodeGenerate tutorial (2) NCodeGenerate is one of the common code generation tools-What is NCodeGenerate? Code Generation Tool-NCodeGenerate tutorial (1) times

Source: Internet
Author: User

NCodeGenerate is very convenient to use.

During use, we often use some common code in different templates. If there is no extension mechanism, the code needs to be copied between various templates, which is obviously too low-level.

By the way, you are right. NCodeGenerate has a good public mechanism. There are two types in total:

I. C # code extension.

Ii. Assembly Extension.

Today we will talk about the first type, C # code extension.

Step 1: Create a C # file in the menu and enter the following code

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using NCodeGenerate.DBSchema; 6 using System.Data; 7 using System.Text.RegularExpressions; 8  9 public static class ConvertHelper110 {11 12 13     public static string TestA(string bb)14     {15         return bb;16     }17     public static string TestA(string bb,string cc)18     {19         return bb+cc;20     }21 }

Well, save the following. Note that you must first save it. Otherwise, the path will not be found during the next reference.

Step 2: Create a template file and enter the following code

 

1 @AssemblyFile .\ConvertHelper1.cs2 

 

Okay, the climax is coming. Check the Code in line 2: Use the @ AssemblyFile command to introduce the CS file generated in one step. The following is the relative path of the file. Note that only relative paths are allowed, and absolute paths are not allowed.

Okay, now let's look at the 5th lines of code. What do you see after @ ConvertHelp1? Are there any smart prompts? Nothing ?!. What's wrong?

The cause is found because the template file is not saved. There is no path. Of course, File Import will not succeed.

Save it now and try again.

 

OK. A prompt is displayed.

Step 3: Run

The result is displayed.

1 

 

Success.

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.