木子屋 Dnawo's BLOG

CodeSmith数据表实体类生成模板

👤 dnawo 📅 2009-07-14 👁 5014 👍 0 💬 0 🔄 来源:本站原创
<%@ 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)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 SqlDbType转换为C#数据类型 下一篇 → CodeSmith生成的代码自动保存到文件