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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

博客园 - HelloSnoopy

写了个用一个文件定义样式的DataGrid 一个最基本的WebService+Flash调用的实例 [转载]如何奔向程序员打工的出头之日? 一定要讲给孩子们的20个小故事 人脉对职业生涯最重要 (转) 爱情的10种样子,送给懂爱的朋友们 装了Enterprise Library.NET 200501release C#判断是否为数字的最好速度! 开源的 BugTracker.net 错误跟踪管理系统 Enjoy new year of 2005! Flash AS2 用EventDispatcher广播事件 设计模式随笔-让众口不再难调 [专题]MVC构架模式 使用Microsoft Application Block之Cache Application 用一条SQL完成数据表的行统计 如何使IFrame的长宽与内容自动适应大小 为Project提供一个统一风格的DataGrid 用于读取树形任一节点下所有级别子节点的SqlServer UDF asp.net forums中定时器的应用
CodeSmith使用心得
HelloSnoopy · 2004-12-27 · via 博客园 - HelloSnoopy

  come from:http://www.cnblogs.com/elevenwolf/archive/2004/12/01/71391.aspx 

  代码生成器大家都用过吧,CodeSmith我想大家也不陌生。最近就用CodeSmith生成了自己的实体类。当然你也可以用它来生成HTML页面以及文档。

下面我就来说一说我生成实体类的步骤:
一、首先介绍一下CodeSmith 2.6CodeSmith 2.6安装后,会有3exe:
1.       CodeSmith.exe即为CodeSmith Explorer,可视化生成代码工具,免费,没有时间限制
2.       CodeSmithConsole.exe Command模式下运行,免费,没有时间限制
3.       CodeSmithStudio.exe编辑模板的工具的工具,可以校验模板语法是否正确。试用30天。
CodeSmith模板支持C#VB.Net语法,可以调用.net类库,语法和.net基本上是一样的。  

二、制作模板
1.在这里我选择了C#作为模板的开发语言。
<%@ CodeTemplate Language="C#" TargetLanguage="Text" Description="Template description here." %> 
2.要生成数据库的实体类,数据连接和表名不可缺少的。在CodeSmith中通过SchemaExplorer.dll来帮你和数据库打交道。
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
在模板中导入SchemaExplorer
然后设置一系列的需要传入的参数:
<%@ Property Name="DataBase" Type="SchemaExplorer.DatabaseSchema" Category="Context" Description="数据库连接." %>
<%@ Property Name="TableName" Type="System.String" Default="" Optional="False" Category="" Description="表名" %> 

3.CodeSmith模板脚本格式:
<script runat="template"> 
       CodeTemplateRule rule=new CodeTemplateRule();
</script>  

或者:
/// <summary> 
    /// 作用:<%= Description %> 
    /// 作者:<%= Author %> 
    /// 日期:<%= DateTime.Now.ToString() %>
///</summary>  

4.我自己写了一个dll来存放自己的函数 CodeTemplateRule.dll ,其中引用到了SchemaExplorer,举个例子:

这段代码的含义就是取数据库中某张表所有列的集合。

Demo文件:
模板文件:entity.cst
自己写的.net程序集:CodeTemplateRule.cs
生成后的代码效果:AccountBookEntity.cs  

三、运行
1.       CodeSmith.exe运行模板,CodeSmith会弹出对话框来你来填写你的参数。
2.       CodeSmithConsole.exe运行模板,参数可以放在xml文件中。例如:
<?xml version="1.0" encoding="utf-8" ?>

<codeSmith> 

       <propertySets>

              <propertySet>

                     <property name="SampleStringProperty1">string111111111</property>

                     <property name="SampleBooleanProperty1">false</property>         

              </propertySet>         

       </propertySets>

</codeSmith>

然后用命令执行:

3.       CodeSmithStudio.exe运行模板  

总结:

代码生成器给我们编程工作带来了很大的便利,不需要做很多重复性的工作。