Codesmith practical skills (10): use programming execution templates

Source: Internet
Author: User

CodesmithCall someAPIThe main steps are as follows:

LCompile a template

LShow compilation error information

LCreate a new template instance

LFilling templates with metadata

LOutput result

The following sectionCodeThe following operations are displayed:

Codetemplatecompiler Compiler =   New Codetemplatecompiler ( " .. \... \ Storedprocedures. CST " );
Compiler. Compile ();
 
If (Compiler. errors. Count =   0 )
{
Codetemplate Template = Compiler. createinstance ();
 
Databaseschema Database =   New Databaseschema ( New Sqlschemaprovider (), @" Server = (local) \ netsdk; database = northwind; Integrated Security = true; " );
Tableschema table = Database. Tables [ " MERs " ];
 
Template. setproperty ( " Sourcetable " , Table );
Template. setproperty ( " Includedrop " , False );
Template. setproperty ( " Insertprefix " , " Insert " );
 
Template. Render (console. Out );
}
Else
{
For ( Int I =   0 ; I < Compiler. errors. Count; I ++ )
{
Console. Error. writeline (compiler. errors [I]. tostring ());
}
}

Here we use Render Method, in fact Codetemplate. rendertofile And Codetemplate. rendertostring The method may be more useful. It can directly output the result to a file or assign it to a variable of the variable type.

Note: This function can only be used in Codesmith used in Professional Edition

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.