Template:
<%--
Name: CodeSmith Model
Author: 2009-08-30 QQ:418715961 E_MAIL:[email protected]
Description: CodeSmith Model
--%>
<%@ 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="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the stored procedures should be based on." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<script runat="template">
public string CSharpType(ColumnSchema column)
{
if (column.Name.EndsWith("TypeCode")) return column.Name;
switch (column.DataType)
{
case DbType.AnsiString: return "string ";
case DbType.AnsiStringFixedLength: return "string ";
case DbType.Binary: return "byte[] ";
case DbType.Boolean: return "bool ";
case DbType.Byte: return "byte ";
case DbType.Currency: return "decimal ";
case DbType.Date: return "DateTime";
case DbType.DateTime: return "DateTime";
case DbType.Decimal: return "decimal ";
case DbType.Double: return "double ";
case DbType.Guid: return "Guid ";
case DbType.Int16: return "short ";
case DbType.Int32: return "int ";
case DbType.Int64: return "long ";
case DbType.Object: return "object ";
case DbType.SByte: return "sbyte ";
case DbType.Single: return "float ";
case DbType.String: return "string ";
case DbType.StringFixedLength: return "string ";
case DbType.Time: return "TimeSpan";
case DbType.UInt16: return "ushort ";
case DbType.UInt32: return "uint ";
case DbType.UInt64: return "ulong ";
case DbType.VarNumeric: return "decimal ";
default:
{
return "__UNKNOWN__" + column.NativeType;
}
}
}
</script>
///////////////////////////////////////////////////////////////////////////////////////
// File: <%=SourceTable.Name %>Model.cs
// Description: the <%=SourceTable.Name %>Model Created By CodeSmith.
// ---------------------
// Copyright: @ <%= DateTime.Now.Year %>
// ---------------------
// History:
///////////////////////////////////////////////////////////////////////////////////////
using System;
namespace <%=NameSpace%>.<%=ClassName%>
{
/// <summary>
/// Summary description for <%=SourceTable.Name %>Model.
/// Description:<%=SourceTable.Description %>
/// </summary>
public class <%=SourceTable.Name %>Model
{
#region Private Protery
<%for(int i=0;i<SourceTable.Columns.Count;i++){%>
private <%=CSharpType(SourceTable.Columns[i])%> _<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>;
<%}%>
#endregion
#region Constructor
/// <summary>
/// <%=SourceTable.Name %>Struct Constructor
/// </summary>
public <%=SourceTable.Name %>Model()
{
}
/// <summary>
/// <%=SourceTable.Name %>Struct Constructor(Have Parameters)
/// </summary>
<%for(int i=0;i<SourceTable.Columns.Count;i++){%>
///<param name="<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>"><%if(SourceTable.Columns[i].Description.Length>0){%><%=SourceTable.Columns[i].Name+" "+SourceTable.Columns[i].Description%><%}else{%><%=SourceTable.Columns[i].Name%><%}%></param>
<%}%>
public <%=SourceTable.Name %>Model(<%for(int i=0;i<SourceTable.Columns.Count;i++){%><%=CSharpType(SourceTable.Columns[i])%> <%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%><% if (i < SourceTable.Columns.Count - 1) { %>,<%}%><%}%>)
{
<%for(int i=0;i<SourceTable.Columns.Count;i++){%>
this._<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%> = <%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>;
<%}%>
}
#endregion
#region public Property
<%for(int i=0;i<SourceTable.Columns.Count;i++){%>
///<Summary>
/// <%=SourceTable.Columns[i].Name%><%if(SourceTable.Columns[i].Description.Length>0){%>
/// <%=SourceTable.Columns[i].Description%><%}%>
///</Summary>
public <%=CSharpType(SourceTable.Columns[i]).Trim()%> <%=SourceTable.Columns[i].Name%>
{
get { return _<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>; }
set { _<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%> = value; }
}
<%}%>
#endregion
}
}
Output:
///////////////////////////////////////////////////////////////////////////////////////
// File: CompanyModel.cs
// Description: the CompanyModel Created By CodeSmith.
// ---------------------
// Copyright: @ 2009-9-3 12:48:02
// ---------------------
// History:
///////////////////////////////////////////////////////////////////////////////////////
using System;
namespace LineChat.Model
{
/// <summary>
/// Summary description for CompanyModel.
/// Description:
/// </summary>
public class CompanyModel
{
#region Private Protery
private int _companyId;
private string _companyAccount;
private string _companyName;
private string _companyAddress;
private string _shortName;
private string _phone;
private string _logo;
private string _email;
private int _postCode;
private string _uRL;
private DateTime _createTime;
private string _belong;
private int _adminId;
private DateTime _changeTime;
private int _adminId2;
private int _state;
private string _remark;
#endregion
#region Constructor
/// <summary>
/// CompanyStruct Constructor
/// </summary>
public CompanyModel()
{
}
/// <summary>
/// CompanyStruct Constructor(Have Parameters)
/// </summary>
///<param name="companyId">CompanyId</param>
///<param name="companyAccount">CompanyAccount 唯一键</param>
///<param name="companyName">CompanyName</param>
///<param name="companyAddress">CompanyAddress</param>
///<param name="shortName">ShortName</param>
///<param name="phone">Phone</param>
///<param name="logo">Logo</param>
///<param name="email">Email</param>
///<param name="postCode">PostCode</param>
///<param name="uRL">URL</param>
///<param name="createTime">CreateTime</param>
///<param name="belong">Belong</param>
///<param name="adminId">AdminId</param>
///<param name="changeTime">ChangeTime</param>
///<param name="adminId2">AdminId2</param>
///<param name="state">State 1 有效,0无效</param>
///<param name="remark">Remark</param>
public CompanyModel(int companyId,string companyAccount,string companyName,string companyAddress,string shortName,string phone,string logo,string email,int postCode,string uRL,DateTime createTime,string belong,int adminId,DateTime changeTime,int adminId2,int state,string remark)
{
this._companyId = companyId;
this._companyAccount = companyAccount;
this._companyName = companyName;
this._companyAddress = companyAddress;
this._shortName = shortName;
this._phone = phone;
this._logo = logo;
this._email = email;
this._postCode = postCode;
this._uRL = uRL;
this._createTime = createTime;
this._belong = belong;
this._adminId = adminId;
this._changeTime = changeTime;
this._adminId2 = adminId2;
this._state = state;
this._remark = remark;
}
#endregion
#region public Property
///<Summary>
/// CompanyId
///</Summary>
public int CompanyId
{
get { return _companyId; }
set { _companyId = value; }
}
///<Summary>
/// CompanyAccount
/// 唯一键
///</Summary>
public string CompanyAccount
{
get { return _companyAccount; }
set { _companyAccount = value; }
}
///<Summary>
/// CompanyName
///</Summary>
public string CompanyName
{
get { return _companyName; }
set { _companyName = value; }
}
///<Summary>
/// CompanyAddress
///</Summary>
public string CompanyAddress
{
get { return _companyAddress; }
set { _companyAddress = value; }
}
///<Summary>
/// ShortName
///</Summary>
public string ShortName
{
get { return _shortName; }
set { _shortName = value; }
}
///<Summary>
/// Phone
///</Summary>
public string Phone
{
get { return _phone; }
set { _phone = value; }
}
///<Summary>
/// Logo
///</Summary>
public string Logo
{
get { return _logo; }
set { _logo = value; }
}
///<Summary>
/// Email
///</Summary>
public string Email
{
get { return _email; }
set { _email = value; }
}
///<Summary>
/// PostCode
///</Summary>
public int PostCode
{
get { return _postCode; }
set { _postCode = value; }
}
///<Summary>
/// URL
///</Summary>
public string URL
{
get { return _uRL; }
set { _uRL = value; }
}
///<Summary>
/// CreateTime
///</Summary>
public DateTime CreateTime
{
get { return _createTime; }
set { _createTime = value; }
}
///<Summary>
/// Belong
///</Summary>
public string Belong
{
get { return _belong; }
set { _belong = value; }
}
///<Summary>
/// AdminId
///</Summary>
public int AdminId
{
get { return _adminId; }
set { _adminId = value; }
}
///<Summary>
/// ChangeTime
///</Summary>
public DateTime ChangeTime
{
get { return _changeTime; }
set { _changeTime = value; }
}
///<Summary>
/// AdminId2
///</Summary>
public int AdminId2
{
get { return _adminId2; }
set { _adminId2 = value; }
}
///<Summary>
/// State
/// 1 有效,0无效
///</Summary>
public int State
{
get { return _state; }
set { _state = value; }
}
///<Summary>
/// Remark
///</Summary>
public string Remark
{
get { return _remark; }
set { _remark = value; }
}
#endregion
}
}