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.
1.2 Illustrator多文檔的幾種排列方式
2.
5.16--java數據類型轉換及雜記
3.
性能指標
4.
(1.2)工廠模式之工廠方法模式
5.
Java記錄 -42- Java Collection
6.
Java記錄 -42- Java Collection
7.
github使用
8.
Android學習筆記(五十):聲明、請求和檢查許可
9.
20180626
10.
服務擴容可能引入的負面問題及解決方法
本站公眾號
歡迎關注本站公眾號,獲取更多信息
相關文章
1.
CodeSmith基礎(三)上
2.
CodeSmith基礎(三) 中
3.
Codesmith
4.
CodeSmith 圖形界面基本操作(一)
5.
CodeSmith 基本語法(二)
6.
VS2008-Codesmith-Nhibernate使用(一)
7.
CodeSmith筆記
8.
CodeSmith介紹
9.
CodeSmith 介紹
10.
CodeSmith註冊
>>更多相關文章<<