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