• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
鱼要的是海洋,鸟要的是天空,我要的是自由!
平凡的人不平凡的人生
博客园    首页    新随笔    联系   管理    订阅  订阅

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
posted @ 2007-06-15 11:10  伊凡  阅读(391)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3