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

CodeSmith中使用CodeTemplateInfo可以获取当前模版的一些信息:

属性

返回值

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.  

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

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

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

Template:        CodeTemplateInfo.cst
Created:         
6/29/2005 8:54:19 PM
Description:     Demonstrates CodeTemplateInfo.
Location:        C:\Program Files\CodeSmith\v3.
0\SampleTemplates\Test\CodeTemplateInfo.cst
Language:        VB
Target Language: Text
作者:TerryLee
出处:http://terrylee.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted @ 2005-12-28 18:31 TerryLee 阅读(1445) 评论(1)  编辑 收藏 所属分类: CodeSmith

  回复  引用    
#1楼 2007-02-27 14:51 | 吕合金 [未注册用户]
怎么用?

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2005-12-28 19:38 编辑过


相关链接: