CodeSmith数据表实体类生成模板

<%@ CodeTemplate Language="C#" TargetLanguage="C#" %>
<%@ Property Name="NameSpace" Type="String" Category="Context" %>
<%@ Property Name="Table" Type="SchemaExplorer.TableSchema" Category="Context" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>

<script runat="template">
//首字母小写
public string LCase(string text)
{
    return text.Substring(0,1).ToLower() + text.Substring(1);
}
//首字母大写
public string UCase(string text)
{
    return text.Substring(0,1).ToUpper() + text.Substring(1);
}
</script>
////////////////////////////////////////////////
// File: <% =UCase(Table.Name) %>Info.cs
// Description: Enter summary here after generation.
// Date: <% =DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") %>
// Web: http://www.mzwu.com/
////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;

namespace <% =NameSpace %>
{
    public class <% =UCase(Table.Name) %>Info
    {
        <%-- 私有字段 --%>
        <% for(int i=0;i<Table.Columns.Count;i++) {%>
        private <% =Table.Columns[i].SystemType.Name %> _<% =LCase(Table.Columns[i].Name) %>;
        <% }%>
        
        <%-- 属性 --%>
        <% for(int i=0;i<Table.Columns.Count;i++) {%>
        /// <summary>
        /// <% =Table.Columns[i].Description %>
        /// </summary>
        public <% =Table.Columns[i].SystemType.Name %> <% =UCase(Table.Columns[i].Name) %>
        {
            get {return _<% =LCase(Table.Columns[i].Name) %>;}
            set {_<% =LCase(Table.Columns[i].Name) %> = value;}
        }
        <% }%>
        
        <%-- 构造函数 --%>
        /// <summary>
        /// 构造函数
        /// </summary>
        public <% =UCase(Table.Name) %>Info()
        {}
            
        /// <summary>
        /// 构造函数
        /// </summary>
        <% for(int i=0;i<Table.Columns.Count;i++) {%>
        /// <param name="<% =LCase(Table.Columns[i].Name) %>"><% =Table.Columns[i].Description %></param>
        <% }%>
        public <% =UCase(Table.Name) %>Info
        (
        <% for(int i=0;i<Table.Columns.Count;i++) {%>
        <% =Table.Columns[i].SystemType.Name %> <% =LCase(Table.Columns[i].Name) %><% if(i<Table.Columns.Count-1)Response.Write(","); %>
        <% }%>
        )
        {
            <% for(int i=0;i<Table.Columns.Count;i++) {%>
            _<% =LCase(Table.Columns[i].Name) %> = <% =LCase(Table.Columns[i].Name) %>;
            <% }%>
        }
    }
}


评论: 0 | 引用: 0 | 查看次数: 4595
发表评论
登录后再发表评论!