CodeSmith实用技巧(十三):使用CodeTemplateInfo对象

博客介绍了在CodeSmith中使用CodeTemplateInfo可获取当前模版信息,并给出具体使用例子,还提到执行模版的输出会因环境不同而不同。

CodeSmith中使用CodeTemplateInfo可以获取当前模版的一些信息:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

属性

返回值

CodeBehind   

Gets the full path to the code-behind file for the template (or an empty string if there is no code-behind file).

ContentHashCode

Gets the hash code based on the template content and all template dependencies.  

DateCreated

Gets the date the template was created.

DateModified

Gets the date the template was modified.  

Description

Gets the description.  

DirectoryName

Gets the name of the directory the template is located in.  

FileName

Gets the name of the template file.  

FullPath

Gets the full path to the template.  

Language

Gets the template language.  

TargetLanguage

Gets the target language.  

看一下一个具体的使用例子:

None.gif<%@ CodeTemplate Language="VB" TargetLanguage="Text" Description="Demonstrates CodeTemplateInfo." %>
None.gif
<% DumpInfo() %>
None.gif
<script runat="template">
None.gifPublic Sub DumpInfo()
None.gif    Response.WriteLine(
"Template:        {0}", Me.CodeTemplateInfo.FileName)
None.gif    Response.WriteLine(
"Created:         {0}", Me.CodeTemplateInfo.DateCreated)
None.gif    Response.WriteLine(
"Description:     {0}", Me.CodeTemplateInfo.Description)
None.gif    Response.WriteLine(
"Location:        {0}", Me.CodeTemplateInfo.FullPath)
None.gif    Response.WriteLine(
"Language:        {0}", Me.CodeTemplateInfo.Language)
None.gif    Response.WriteLine(
"Target Language: {0}", Me.CodeTemplateInfo.TargetLanguage)
None.gifEnd Sub
None.gif
</script>
None.gif
None.gif

执行该模版输出如下(环境不同,输出也不同):

None.gifTemplate:        CodeTemplateInfo.cst
None.gifCreated:         
6/29/2005 8:54:19 PM
None.gifDescription:     Demonstrates CodeTemplateInfo.
None.gifLocation:        C:\Program Files\CodeSmith\v3.
0\SampleTemplates\Test\CodeTemplateInfo.cst
None.gifLanguage:        VB
None.gifTarget Language: Text
None.gif

转载于:https://www.cnblogs.com/Terrylee/archive/2005/12/28/306801.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值