CodeSmith实用技巧(十):通过编程执行模版
Jun 07, 2016 pm 03:10 PMCodeSmith 在执行模版时通过调用一些 API 来完成的,主要经过了以下这几步的操作: l 编译一个模版 l 显示编译错误信息 l 创建一个新的模版实例 l 用元数据填充模版 l 输出结果 下面这段代码显示了这些操作: CodeTemplateCompilercompiler = new CodeTempla
CodeSmith在执行模版时通过调用一些API来完成的,主要经过了以下这几步的操作:
l 编译一个模版
l 显示编译错误信息
l 创建一个新的模版实例
l 用元数据填充模版
l 输出结果
下面这段代码显示了这些操作:
在这里我们用了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["Customers"];
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());
}
}

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Remove duplicate values from PHP array using regular expressions

What is programming for and what is the use of learning it?

Build browser-based applications with Golang

The Key to Coding: Unlocking the Power of Python for Beginners

Java Made Simple: A Beginner's Guide to Programming Power

Create the Future: Java Programming for Absolute Beginners

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder

Demystifying C: A Clear and Simple Path for New Programmers
