CodeSmith使用技巧

<pre class="csharp" name="code">1.如何将属性设置成选择一个文件夹的路径
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]


public string OutputDirectory

{

get {return _outputDirectory;}

set {_outputDirectory= value;}

}
2.怎样调用子模板
<pre class="csharp" name="code">1<%

2foreach (TableSchema table in SourceDatabase.Tables)

3{

4 OutputSubTemplate(table);

5}

6%>

7<script runat="template">

8private CodeTemplate _mySubTemplate;

9

10[Browsable(false)]

11public CodeTemplate MySubTemplate

12{

13 get

14 {

15 if (_mySubTemplate == null)

16 {

17 CodeTemplateCompiler compiler = new CodeTemplateCompiler(this.CodeTemplateInfo.DirectoryName + "MySubTemplate.cst");

18 compiler.Compile();

19 if (compiler.Errors.Count == 0)

20 {

21 _mySubTemplate = compiler.CreateInstance();

22 }

23 else

24 {

25 for (int i = 0; i < compiler.Errors.Count; i++)

26 {

27 Response.WriteLine(compiler.Errors[ i].ToString());

28 }

29 }

30 }

31 return _mySubTemplate;

32 }

33}

34

35public void OutputSubTemplate(TableSchema table)

36{

37 MySubTemplate.SetProperty("SourceTable", table);

38 MySubTemplate.SetProperty("IncludeDrop", false);

39 MySubTemplate.SetProperty("InsertPrefix", "Insert");

40 MySubTemplate.Render(Response);

41}

42</script></pre>
</pre>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值