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

推荐订阅源

小众软件
小众软件
N
News and Events Feed by Topic
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
H
Heimdal Security Blog
Schneier on Security
Schneier on Security
Engineering at Meta
Engineering at Meta
Google Online Security Blog
Google Online Security Blog
宝玉的分享
宝玉的分享
AI
AI
The GitHub Blog
The GitHub Blog
MongoDB | Blog
MongoDB | Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Last Watchdog
The Last Watchdog
T
Troy Hunt's Blog
S
Security @ Cisco Blogs
H
Hacker News: Front Page
F
Fortinet All Blogs
博客园_首页
S
Secure Thoughts
N
News and Events Feed by Topic
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
Spread Privacy
Spread Privacy
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Hugging Face - Blog
Hugging Face - Blog
Hacker News: Ask HN
Hacker News: Ask HN
C
CXSECURITY Database RSS Feed - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
L
LINUX DO - 最新话题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
Know Your Adversary
Know Your Adversary
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Scott Helme
Scott Helme
P
Privacy & Cybersecurity Law Blog
S
Securelist
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
O
OpenAI News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
PCI Perspectives
PCI Perspectives
L
LangChain Blog
雷峰网
雷峰网
Security Archives - TechRepublic
Security Archives - TechRepublic
V2EX - 技术
V2EX - 技术

博客园 - 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>