惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cybersecurity and Infrastructure Security Agency CISA
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
量子位
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
小众软件
小众软件
T
Tailwind CSS Blog
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
博客园 - 叶小钗
宝玉的分享
宝玉的分享
P
Privacy International News Feed
T
Tor Project blog
博客园_首页
AWS News Blog
AWS News Blog
雷峰网
雷峰网
C
Cisco Blogs
Help Net Security
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 【当耐特】
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Schneier on Security
博客园 - Franky
W
WeLiveSecurity
L
LINUX DO - 热门话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
腾讯CDC
L
Lohrmann on Cybersecurity
J
Java Code Geeks
美团技术团队
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX

博客园 - Morris

C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(673,5): error MSB3491: 未能向文件 - Morris as3 addEventListener各参数详解 在Flash中管理鼠标右键 Java与Action Script(Flash)类型对照 WinAPI--Win32 系统入口函数介绍 JavaScript 取得目前所在分割FRAME的寬度 用 FLASH CS5 作一個於 FLEX 可控制的 SWC 組件 Flash 創建好的 SWC 組件,如何在 FLEX 作一UI、簡單測試 Develop Android APP in Flash CS5 How to use Flex WebService Component in Flash Generate a iPhone certificate signing request on Windows 动态命名影片剪辑 Associative arrays 訪問父MOVIECLIP下的所有依序列號命名的子MOVIECLIP - Morris - 博客园 心跳模拟 AS2.0中实现数据结构-哈希表 Alcon 使用方式重點 Flash AS2 同 VB.NET 類似的 WITH 寫法 flash AS3应用程序模块化开发与ApplicationDomain
CodeSmith基础(一) - Morris - 博客园
Morris · 2010-11-06 · via 博客园 - Morris

创建好一个模板后第一步要指明这是一个C#语言的模板。

<%@ CodeTemplate Language="C#" TargetLanguage="C#"
      Description="Generates a class including a special informational header" %>

        第二步,我们要指明模板在生成代码时的属性,即生成代码需要的输入值变量。

<%@ Property Name="NameSpace" Type="String"
      Category="Context"
      Description="The namespace to use for this class" %>

        如上边所示,在进行代码生成时,在CodeSmith Explorer中选择模板后生成代码的窗口中,变量的名称为NameSpace,类型是String,类别是Context,当用户选中这个属性时对于属性的描述Description。
        我们可以按照C#语言的语法去使用定义的变量,例如:

///////////////////////////////////////////////////////////////////////////////////////
// File: <%=ClassName%>.cs

        例如下面这个例子模板使用了上面介绍的知识。Test.cst

<%@ CodeTemplate Language="C#" TargetLanguage="C#"
      Description="Generates a class including a special informational header" %>
<%@ Property Name="NameSpace" Type="String"
      Category="Context"
      Description="The namespace to use for this class" %>
<%@ Property Name="ClassName" Type="String"
      Category="Context"
      Description="The name of the class to generate" %>
<%@ Property Name="DevelopersName" Type="String"
      Category="Context"
      Description="The name to include in the comment header" %>

///////////////////////////////////////////////////////////////////////////////////////
// File: <%=ClassName%>.cs
// Description: Enter summary here after generation.
// ---------------------
// Copyright © <%= DateTime.Now.Year %> Our Client
// ---------------------
// History
//    <%= DateTime.Now.ToShortDateString() %>    <%= DevelopersName%>    Original Version
///////////////////////////////////////////////////////////////////////////////////////
using System;
namespace <%=NameSpace %>
{
/// <summary>
/// Summary description for <%=ClassName %>.
/// </summary>
public class <%=ClassName %>
      {
public <%=ClassName %>()
            {
//
// TODO: Add constructor logic here
//
            }
      }
}

然后我们在CodeSmith Explorer中双击这个模板就会看到相应的属性界面,这里的属性均是我们在前边定义的属性。

按下Generate按钮生成,即可实现一个简单的类代码的生成。

1///////////////////////////////////////////////////////////////////////////////////////
2// File: MyClass.cs
3// Description: Enter summary here after generation.
4// ---------------------
5// Copyright © 2003 Our Client
6// ---------------------
7// History
8//    12/2/2003    Mr. Smith    Original Version
9///////////////////////////////////////////////////////////////////////////////////////
10
11using System;
12
13namespace MyNameSpace
14{
15 /// <summary>
16 /// Summary description for MyClass.
17 /// </summary>
18 public class MyClass
19 {
20 public MyClass()
21 {
22 //
23 // TODO: Add constructor logic here
24 //
25            }
26      }
27}

生成后的代码即可放入Visual Studio .NET中使用,我们使用CodeSmith的目的就是为了快速高效的开发。