CodeSmith Model Template
CodeSmith生成实体类模板:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<%--
Name : TearsEntity.cst
Author : Sheng
Description: Create Model Template
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" ResponseEncoding="UTF-8" Description="Build A Model" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="TableName" %>
<%@ Property Name="NameSpace" Type="String" Default="Model" Optional="False" Category="" Description="NameSpace" %>
<%@ Property Name="Author" Type="System.String" Default="Tears" Optional="False" Category="" Description="Author" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
//======================================================================
//
// http://www.*****.com.cn
//
// Copyright (C) 2009-2010 ********
// All Rights Reserved
//
// FileName : <%= SourceTable.Name %>
// Description :
//
// Created By : Sheng <%= DateTime.Now.ToString() %>
//
//======================================================================
using System;
using System.Data;
using System.Configuration;
namespace <%=NameSpace%>
{
/// <summary>
/// <%= SourceTable.Name %> Model
/// </summary>
[Serializable()]
public class <%= SourceTable.Name %>
{
#region 私有字段
<% for (int i = 0; i < SourceTable.Columns.Count; i++){ %>
private <%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>;
<% } %>
#endregion
#region 构造函数
/// <summary>
/// 无参构造函数
/// </summary>
public <%= SourceTable.Name %> () { }
/// <summary>
/// 有参构造函数
/// </summary>
<% for (int i = 1; i < SourceTable.Columns.Count; i++) { %>
/// <param name="<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>"><%= SourceTable.Columns[i].Description %></param>
<% } %>
public <%= SourceTable.Name %> (<% for (int i = 1; i < SourceTable.Columns.Count-1; i++){ %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>,<% } %><% for (int i = SourceTable.Columns.Count-1; i < SourceTable.Columns.Count; i++) { %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> <% } %>)
{
<% for (int i = 1; i < SourceTable.Columns.Count; i++) { %>
this.<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> = <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>;
<% } %>
}
/// <summary>
/// 有参构造函数
/// </summary>
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
/// <param name="<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>"><%= SourceTable.Columns[i].Description %></param>
<% } %>
public <%= SourceTable.Name %> (<% for (int i = 0; i < SourceTable.Columns.Count-1; i++){ %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>,<% } %><% for (int i = SourceTable.Columns.Count-1; i < SourceTable.Columns.Count; i++) { %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> <% } %>)
:this(<% for (int i = 1; i < SourceTable.Columns.Count-1; i++){ %><%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>,<% } %><% for (int i = SourceTable.Columns.Count-1; i < SourceTable.Columns.Count; i++) { %><%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> <% } %>)
{
this.<%= StringUtil.ToCamelCase(SourceTable.Columns[0].Name) %> = <%= StringUtil.ToCamelCase(SourceTable.Columns[0].Name) %>;
}
#endregion
#region 公共属性
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
///<summary>
///<%= SourceTable.Columns[i].Description %>
///</summary>
public <%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToPascalCase(SourceTable.Columns[i].Name) %>
{
get
{
return this.<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>;
}
set
{
this.<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> = value;
}
}
<% } %>
#endregion
}
}
Name : TearsEntity.cst
Author : Sheng
Description: Create Model Template
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" ResponseEncoding="UTF-8" Description="Build A Model" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="TableName" %>
<%@ Property Name="NameSpace" Type="String" Default="Model" Optional="False" Category="" Description="NameSpace" %>
<%@ Property Name="Author" Type="System.String" Default="Tears" Optional="False" Category="" Description="Author" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
//======================================================================
//
// http://www.*****.com.cn
//
// Copyright (C) 2009-2010 ********
// All Rights Reserved
//
// FileName : <%= SourceTable.Name %>
// Description :
//
// Created By : Sheng <%= DateTime.Now.ToString() %>
//
//======================================================================
using System;
using System.Data;
using System.Configuration;
namespace <%=NameSpace%>
{
/// <summary>
/// <%= SourceTable.Name %> Model
/// </summary>
[Serializable()]
public class <%= SourceTable.Name %>
{
#region 私有字段
<% for (int i = 0; i < SourceTable.Columns.Count; i++){ %>
private <%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>;
<% } %>
#endregion
#region 构造函数
/// <summary>
/// 无参构造函数
/// </summary>
public <%= SourceTable.Name %> () { }
/// <summary>
/// 有参构造函数
/// </summary>
<% for (int i = 1; i < SourceTable.Columns.Count; i++) { %>
/// <param name="<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>"><%= SourceTable.Columns[i].Description %></param>
<% } %>
public <%= SourceTable.Name %> (<% for (int i = 1; i < SourceTable.Columns.Count-1; i++){ %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>,<% } %><% for (int i = SourceTable.Columns.Count-1; i < SourceTable.Columns.Count; i++) { %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> <% } %>)
{
<% for (int i = 1; i < SourceTable.Columns.Count; i++) { %>
this.<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> = <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>;
<% } %>
}
/// <summary>
/// 有参构造函数
/// </summary>
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
/// <param name="<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>"><%= SourceTable.Columns[i].Description %></param>
<% } %>
public <%= SourceTable.Name %> (<% for (int i = 0; i < SourceTable.Columns.Count-1; i++){ %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>,<% } %><% for (int i = SourceTable.Columns.Count-1; i < SourceTable.Columns.Count; i++) { %><%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> <% } %>)
:this(<% for (int i = 1; i < SourceTable.Columns.Count-1; i++){ %><%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>,<% } %><% for (int i = SourceTable.Columns.Count-1; i < SourceTable.Columns.Count; i++) { %><%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> <% } %>)
{
this.<%= StringUtil.ToCamelCase(SourceTable.Columns[0].Name) %> = <%= StringUtil.ToCamelCase(SourceTable.Columns[0].Name) %>;
}
#endregion
#region 公共属性
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
///<summary>
///<%= SourceTable.Columns[i].Description %>
///</summary>
public <%= SourceTable.Columns[i].SystemType %> <%= StringUtil.ToPascalCase(SourceTable.Columns[i].Name) %>
{
get
{
return this.<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %>;
}
set
{
this.<%= StringUtil.ToCamelCase(SourceTable.Columns[i].Name) %> = value;
}
}
<% } %>
#endregion
}
}