TemplateBase.cs文件相关内容

CodeSmith模板定制指南
本文介绍了如何通过修改CodeSmith核心文件TemplateBase.cs来定制自己的模板。重点讲解了添加新模板MyTest.cst所需的三个关键步骤,并强调了这些修改对于模板正常工作的必要性。
<p>TemplateBase.cs是CodeSmith的核心,要编写高质量的模板必须先要了解其中的内容
这里我简单说一下:要添加一个MyTest.cst模板需要在TemplateBase.cs中注意修改的3个地方:
1.</p>
<pre class="csharp" name="code"> #region Enumerations

public enum ObjectType

{

<font color="#ff0000"> MyTest,
</font>
EditableRoot,

EditableRootList,

EditableChild,

EditableChildList,

EditableSwitchable,

NameValueList,

ReadOnlyRoot,

ReadOnlyRootList,

ReadOnlyChild,

ReadOnlyChildList

}</pre>

2.
<pre class="csharp" name="code"> public class TemplateHelper

{

private TemplateHelper() { }


public static bool IsObjectType(ICodeTemplateInfo info)

{

switch (info.FileName.ToLower())

{

<font color="#ff0000">case "mytest.cst":
</font>3.<pre class="csharp" name="code"> public static ObjectType ToObjectType(ICodeTemplateInfo info)

{

switch (info.FileName.ToLower())

{

<font color="#ff0000">case "mytest.cst": return ObjectType.MyTest;
</font>
case "editableroot.cst": return ObjectType.EditableRoot;

case "editablerootlist.cst": return ObjectType.EditableRootList;</pre>
<pre class="csharp" name="code">否则生成的时候会报错,提示不能生成业务类型</pre>
</pre>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值