惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
S
Securelist
The Hacker News
The Hacker News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs
Jina AI
Jina AI
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
量子位
S
Schneier on Security
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
O
OpenAI News
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
博客园 - 叶小钗
L
LINUX DO - 最新话题
V
Visual Studio Blog
U
Unit 42
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Affairs
AWS News Blog
AWS News Blog
S
Secure Thoughts
腾讯CDC
Cloudbric
Cloudbric
H
Help Net Security
The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
D
DataBreaches.Net
A
About on SuperTechFans
G
GRAHAM CLULEY
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
NISL@THU
NISL@THU
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary

博客园 - SCPlatform

windown 使用python 自动切换网络 CPU封装技术介绍 openssl unicode编译以及VC++2015环境下的问题 重新开启此博 MIFARE Classic S50技术详解 Mifare简介 如何获取JavaCard栈信息 JavaCard应用开发环境 如何获取JavaCard剩余空间 如何统合分析一张JavaCard BER-TLV数据结构 智能卡中的数据结构 加密解密算法 SCPlatform博客文章总目录 C#实现简体中文和繁体中文的转换 QueryString 整站过滤 关于脚本注入的问题 开发Blog需注意的Blog基本特征和功能要素 java 学习步骤
CodeSmith 实体生成模板(C#版)
SCPlatform · 2007-12-12 · via 博客园 - SCPlatform

<%-- 
Name: 
Author: Whicet
Description: 
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="Text" Src="" Inherits="" 
Debug
="False" Description="This is a enity class" %>
<%@ Property Name="CurDB" Type="SchemaExplorer.DatabaseSchema"  
Category
="Context" Description="Database property." %>
<%@ Property Name="CurTable" Type="SchemaExplorer.TableSchema" 
Category
="Context" Description="Table property" %>
<%@ Property Name="MakeLanguage" Type="ML" Default="2" Optional="False"
Category
="Other"   Description="Language" %>
<%@ Property Name="NameSpaces" Type="String" Default="MemberCard" Optional="False"
Category
="Other"  Description="Namespace" %><%@ Assembly Name="System.Data" %>
<%@ Assembly Name="System.Design" %>
<%@ Assembly Name="SchemaExplorer" %><%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Design" %>
<%@ Import Namespace="SchemaExplorer" %><%------------------------------------conditional content--------------------------------%>
<% if (MakeLanguage == ML.CS) { %>
using System;
using System.Data;namespace <%=NameSpaces%>.EntityModel
{
    [Serializable()]
    
public class <%= CurTable.Name %>Entity
    {
        
public <%= CurTable.Name %>Entity()
        {
            
//TODO:
        }
        
<%=GetMakeCode(ML.CS)%>
    }
}
<% } %>
<%else if(MakeLanguage == ML.VB) { %>
Imports System
Imports System.Data

namespase 

<%=NameSpaces%>.EntityModel

    [Serializable()]
    Public Class 

<%= CurTable.Name %>Entity  
        Public Sub New()
        End Sub
        
        
<%=GetMakeCode(ML.VB)%>
    End Class 
'<%= CurTable.Name %>Entity 
End Namespace
<% } %>
<%------------------------------------methods--------------------------------%><script runat="template">
 #region normal

  public enum ML
    {
        VB
=0,
        CS
=2
    }
    
    
public string GetMakeCode(ML MakeLang)
    {
        String result 
= "";
        
if(MakeLang == ML.VB)
        {
            result 
= GetVBCode();
        }
        
else if(MakeLang == ML.CS)
        {
            result 
= GetCSCode();
        }
        
return result;
    }
  #endregion

 
#region FirstToLower
    
public string FirstToLower(string Str)
    {
        String s 
= "";
        s 
= Str.Substring(0,1).ToLower() + Str.Substring(1);
        
return s;
    }
    
#endregion#region Get VBCode and CSCode
    
public string GetVBCode()
    {
        System.Text.StringBuilder sb 
= new System.Text.StringBuilder(100);
        String columnName 
= "";
        String columnType 
= "";
        String firstLower 
= "";
    
        
foreach(ColumnSchema field in CurTable.Columns)
        {
            columnName 
= field.Name;
            columnType 
= GetColumnDataType(ML.VB, field);
            firstLower 
= FirstToLower(columnName);
            
            sb.Append(
"\t" + "Private _" + firstLower + " As " + columnType + GetDefaultValue(columnType) + "\n");
            sb.Append(
"\t" + "<ColumnName()> Public Property " + columnName + "() As " + columnType + "\n");
            sb.Append(
"\t" + "\t" + "Get" + "\n");
            sb.Append(
"\t" + "\t" + "\t" + "Return _" + firstLower + "\n");
            sb.Append(
"\t" + "\t" + "End Get" + "\n");
            sb.Append(
"\t" + "\t" + "Set(ByVal Value As " + columnType + ")" + "\n");
            sb.Append(
"\t" + "\t" + "\t" + "_" + firstLower + " = Value" + "\n");
            sb.Append(
"\t" + "\t" + "End Set" + "\n");
            sb.Append(
"\t" + "End Property" + "\n" + "\n");        
        }
        
return sb.ToString();
    }
    
public string GetCSCode()
    {
        System.Text.StringBuilder sb 
= new System.Text.StringBuilder(100);
        String columnName 
= "";
        String columnType 
= "";
        String firstLower 
= "";
    
        
foreach(ColumnSchema field in CurTable.Columns)
        {
            columnName 
= field.Name;
            columnType 
= GetColumnDataType(ML.CS, field);
            firstLower 
= FirstToLower(columnName);
            
            sb.Append(
"\t" + "\t" + "private " + columnType  + " _"+ firstLower  + " " + GetDefaultValue(columnType) + "\n");
            sb.Append(
"\t" + "\t" + "public  " + columnType + " " + columnName + "\n");
            sb.Append(
"\t" + "\t" + "{" + "\n");
            sb.Append(
"\t" + "\t" + "\t" + "get { " );
            sb.Append(
" "+ "return _" + firstLower + "; }\n");        
            sb.Append(
"\t" + "\t" + "\t" + "set {" );        
            sb.Append(
" " + "_" + firstLower + " = value;" + " }\n");            
            sb.Append(
"\t" + "\t" + "}" + "\n" );        
        }
        
return sb.ToString();
    }
    
#endregion
    
#region Get Default Valu.
    
public string GetDefaultValue(string columnType)
    {
        String result 
= "";
        
switch(columnType)
        {
            
case "Integer":
            
case "Double":
                result 
= "= 0 ";
                
break;
            
case "int":
            
case "double":
                result 
= "= 0; ";
                
break;
            
case "String":
                result 
= "= \"\"";
                
break;
            
case "string":
                result 
= "= \"\";";
                
break;
            
case "DateTime":
                
if(MakeLanguage == ML.VB)
                {
                    result 
= "= System.DateTime.Now ";
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= "= System.DateTime.Now;";
                }    
                
break;
            
case "Boolean":
                result 
= "= False ";
                
break;
            
case "bool":
                result 
= "= false; ";
                
break;
            
default:
                
if(MakeLanguage == ML.VB)
                {
                    result 
= " = new " + columnType;
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= " = new " + columnType + ";";
                }    
                
break;
        }
        
return result;
    }
    
#endregion
    
#region Get ColumnData Type.
    
public string GetColumnDataType(ML makeLang, SchemaExplorer.ColumnSchema columnField)
    {
        String result 
= "";
        
switch(columnField.NativeType.ToLower())
        {
            
case "int":
            
case "tinyint":
            
case "smallint":
            
case "bigint":
                
if(MakeLanguage == ML.VB)
                {
                    result 
= "Integer";
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= "int";
                }    
                
break;
            
case "decimal":
            
case "float":
            
case "money":
            
case "numeric":
            
case "smallmoney":
                
if(MakeLanguage == ML.VB)
                {
                    result 
= "Double";
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= "double";
                }    
                
break;
            
case "char":
            
case "nchar":
            
case "ntext":
            
case "varchar":
            
case "nvarchar":
                
if(MakeLanguage == ML.VB)
                {
                    result 
= "String";
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= "string";
                }    
                
break;
            
case "smalldatetime":
            
case "timestamp":
            
case "datetime":
                result 
= "DateTime";
                
break;
            
case "bit":
                
if(MakeLanguage == ML.VB)
                {
                    result 
= "Boolean";
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= "bool";
                }    
                
break;
            
case "binary":
            
case "image":
            
case "varbinary":
                
if(MakeLanguage == ML.VB)
                {
                    result 
= "Byte()";
                }
                
else if(MakeLanguage == ML.CS)
                {
                    result 
= "byte[]";
                }    
                
break;
        }
        
return result;
    }
    
#endregion
</script>