Code Generation Tool-ncodegenerate tutorial (6) ntrace output code generation tool-What is ncodegenerate? Code Generation Tool-ncodegenerate tutorial (1) traverse

Source: Internet
Author: User

Ncodegenerate asCodeGenerate tool. You can edit templates, check syntax, and execute template generation code. If there is no logical error in the template, there is no problem in the whole process. But who can ensure there is no error in the written template? Can you? I cannot.ProgramDevelopers know that code debugging takes much longer than code writing during development. Okay, ncodegenerate provides the debugging function. Today, we will briefly talk about the ntrace output in the execution process.

Ncodegenerate provides an ntrace object that can print the output in template execution, regardless of whether the code is correctly executed and ended without being mixed into the generated code.

This ntrace object is actually a stringwriter with the automatic notification function. All functions of the stringwriter object are available. For more information, see http://msdn.microsoft.com/zh-cn/library/system.io.stringwriter_members (V = vs.80). aspx.

Let's take an example:

Create a template and enter the following code:

1 @{2 3Ntrace. writeline ("Begin");4 @: Run begin5 6Ntrace. writeline ("End");7 8 9}

Run the command and the following result is displayed in the code output:

 

The following results are displayed in the output window below the interface:

As you can see, this is the result of successful execution, which is output in different windows.

Let's look at a wrong situation.

Modify the template code:

 
1 @{2 3Ntrace. writeline ("Begin");4 Throw NewException ();5 @: Run begin6Ntrace. writeline ("End");7 8 9}

An exception is thrown when 4th rows are added. In this way, the Code Execution ends on the fourth line.

Run the following command:

The template throws an exception, and the following output only contains begin, but does not have end. This means that the execution of the template to the 4th line of code is over.

I wrote it here today. Next I will talk about how ncodegenerate calls the Visual Studio debugger to perform one-step execution, check the variables, and insert breakpoints. Stay tuned.

 

Appendix: ncodegenerate adds the ncodegenerate. dbschema document, which is connected in the following document.

Attached:

Ncodegenerate.zip

Document: Document

 

Ncodegenerate SeriesArticle:

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.