ASP.NET三层架构源码(CodeSmith版)之十:View-Model层

动软代码生成器生成的ASP.NET三层架构代码比较规范,是学习ASP.NET的好例子

此三层架构改造自动软的工厂模式模板,使用CodeSmith进行重写,以方便大家修改模板文件

以下是针对视图Model层的源码:

<%@ CodeTemplate Inherits="CodeTemplate" language="C#" TargetLanguage="Text" Description="NetTiers main template."Debug="True" ResponseEncoding="UTF-8"%>
<%@ Assembly Name="SchemaExplorer" %>  
<%@ Import Namespace="SchemaExplorer" %>  
<%@ Import Namespace="System.Text" %>  
<%@ Property Name="Namespace" Type="String" Category="Context" Description="Namespace"%>  
<%@ Property Name="Author" Type="String" Category="Context"  Description="Author" Default="chenr"%>  
<%@ Property Name="ViewPrefix" Type="System.String" Default="T" Category="Context" Description="The prefix to remove from table names" %>  
<%@ Property Name="ViewName" Type="ViewSchema"  DeepLoad="True" Optional="False" Category="01. Getting Started - Required" Description=""%>
/*------------------------------------------------ 
// File Name:m<%=ClearPrefix(ViewName.Name) %>.cs 
// File Description:<%=ClearPrefix(ViewName.Name) %> DataBase Entity 
// Author:<%=Author%> 
// Create Time:<%= DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")%> 
//------------------------------------------------*/  
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;  
  
namespace <%=Namespace%>.Model  
{  
   ///   
   /// Description <%=ViewName.Description %>  
   ///   
   [Serializable]  
   public class m<%=ClearPrefix(ViewName.Name) %> 
   {  
        #region Private Protery  
        <%for(int i=0;i  
        private <%=CSharpType(ViewName.Columns[i])%> _<%=ViewName.Columns[i].Name.ToLower()%>;
        <%--<%=CSharpType(ViewName.Columns[i])%> _<%=ViewName.Columns[i].Name.Substring(0,1).ToLower()+ViewName.Columns[i].Name.Substring(1,ViewName.Columns[i].Name.Length-1)%>;  --%>
        <%}%>  
        #endregion  
   
        #region Constructor   
        ///   
        /// m<%=ClearPrefix(ViewName.Name) %> Constructor  
        ///   
        public m<%=ClearPrefix(ViewName.Name) %>()  
        {  
        }  
          
        ///   
        /// m<%=ClearPrefix(ViewName.Name) %> Constructor With Parameters  
        ///   
        <%for(int i=0;i 
        /// <%=ViewName.Columns[i].Name.ToLower()%>
        <%--///<%if(ViewName.Columns[i].Description.Length>0){%><%=ViewName.Columns[i].Name+"  "+ViewName.Columns[i].Description%><%}else{%><%=ViewName.Columns[i].Name%><%}%>  --%>
        <%}%>  
        <%--public m<%=ClearPrefix(ViewName.Name) %>(<%for(int i=0;i<%=CSharpType(ViewName.Columns[i])%> <%=ViewName.Columns[i].Name.Substring(0,1).ToLower()+ViewName.Columns[i].Name.Substring(1,ViewName.Columns[i].Name.Length-1)%><% if (i < ViewName.Columns.Count - 1) { %>,<%}%><%}%>)  --%>
        public m<%=ClearPrefix(ViewName.Name) %>(<%for(int i=0;i<%=CSharpType(ViewName.Columns[i])%> <%=ViewName.Columns[i].Name%><% if (i < ViewName.Columns.Count - 1) { %>,<%}%><%}%>)
        {  
        <%for(int i=0;i  
            <%--this._<%=ViewName.Columns[i].Name.Substring(0,1).ToLower()+ViewName.Columns[i].Name.Substring(1,ViewName.Columns[i].Name.Length-1)%> = <%=ViewName.Columns[i].Name.Substring(0,1).ToLower()+ViewName.Columns[i].Name.Substring(1,ViewName.Columns[i].Name.Length-1)%>;  --%>
            this._<%=ViewName.Columns[i].Name.ToLower()%> = <%=ViewName.Columns[i].Name%>;
        <%}%>  
        }  
        #endregion  
     
        #region Public Property  
        <%for(int i=0;i  
        ///  
        /// <%=ViewName.Columns[i].Name%><%if(ViewName.Columns[i].Description.Length>0){%>  
        /// <%=ViewName.Columns[i].Description%><%}%>  
        ///  
        public <%=CSharpType(ViewName.Columns[i]).Trim()%> <%=ViewName.Columns[i].Name%> { get; set; }
        <%}%>  
        #endregion      
   }  
}