JavaShuo
栏目
标签
CodeSmith基础(一)
时间 2020-01-10
标签
codesmith
基础
繁體版
原文
原文链接
请你们耐心看完全部的基础文章,前两篇网上发表的比较多,是CodeSmith英文帮助文档的第一篇,我后面写的基础是将其余全部的英文帮助所有翻译出来了,所有为本人手写翻译,但愿对你们有所帮助
建立好一个模板后第一步要指明这是一个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
11
using
System;
12
13
namespace
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的目的就是为了快速高效的开发。
相关文章
1.
CodeSmith基础(三)上
2.
CodeSmith基础(三) 中
3.
Codesmith
4.
CodeSmith 图形界面基本操作(一)
5.
CodeSmith 基本语法(二)
6.
VS2008-Codesmith-Nhibernate使用(一)
7.
CodeSmith笔记
8.
CodeSmith介绍
9.
CodeSmith 介绍
10.
CodeSmith注册
更多相关文章...
•
Kotlin 基础语法
-
Kotlin 教程
•
Scala 基础语法
-
Scala教程
•
Kotlin学习(一)基本语法
•
RxJava操作符(一)Creating Observables
相关标签/搜索
codesmith
.Net基础一
基础
Java基础之一
MySQL基础
JSP基础
NodeJs基础篇
基础教程
iOS基础篇
基础架构
MySQL教程
Spring教程
PHP 7 新特性
0
分享到微博
分享到微信
分享到QQ
每日一句
每一个你不满意的现在,都有一个你没有努力的曾经。
最新文章
1.
shell编译问题
2.
mipsel 编译问题
3.
添加xml
4.
直方图均衡化
5.
FL Studio钢琴卷轴之画笔工具
6.
中小企业为什么要用CRM系统
7.
Github | MelGAN 超快音频合成源码开源
8.
VUE生产环境打包build
9.
RVAS(rare variant association study)知识
10.
不看后悔系列!DTS 控制台入门一本通(附网盘链接)
本站公众号
欢迎关注本站公众号,获取更多信息
相关文章
1.
CodeSmith基础(三)上
2.
CodeSmith基础(三) 中
3.
Codesmith
4.
CodeSmith 图形界面基本操作(一)
5.
CodeSmith 基本语法(二)
6.
VS2008-Codesmith-Nhibernate使用(一)
7.
CodeSmith笔记
8.
CodeSmith介绍
9.
CodeSmith 介绍
10.
CodeSmith注册
>>更多相关文章<<