<%@ CodeTemplate Language="C#" TargetLanguage="C#" Src="" Inherits="" Debug="False" CompilerVersion="v3.5" Description="Template description here." %>
<%@ Property Name="ns" Type="System.String" Default="Yonyou.Cn" Optional="False" Category="命名空间" Description="描写命名空间" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<%@ Property Name="TableSrc" Type="SchemaExplorer.TableSchema" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace <%=ns%>
{
public class <%=TableSrc.Name%>
{
<%for(int i=0;i<TableSrc.Columns.Count;i++){%>
private <%=GetCSharpTypeFromDBFieldType(TableSrc.Columns[i])%> _<%=ConvertToFieldName(TableSrc.Columns[i].Name) %>;
public string <%=ConvertToPropertyName(TableSrc.Columns[i].Name) %>
{
get{
return _<%=ConvertToFieldName(TableSrc.Columns[i].Name) %>;
}

set{
_<%=ConvertToFieldName(TableSrc.Columns[i].Name) %>=value;
}
}
<%} %>
}
}

<script runat="template">

public string GetCSharpTypeFromDBFieldType(ColumnSchema column)
{
string type;
switch (column.DataType)
{
case DbType.AnsiString: type= "string";break;
case DbType.AnsiStringFixedLength: type= "string";break;
case DbType.Binary: type= "byte[]";break;
case DbType.Boolean: type= "bool";break;
case DbType.Byte: type= "byte";break;
case DbType.Currency: type= "decimal";break;
case DbType.Date: type= "DateTime";break;
case DbType.DateTime: type= "DateTime";break;
case DbType.Decimal: type= "decimal";break;
case DbType.Double: type= "double";break;
case DbType.Guid: type= "Guid";break;
case DbType.Int16: type= "short";break;
case DbType.Int32: type= "int";break;
case DbType.Int64: type= "long";break;
case DbType.Object: type= "object";break;
case DbType.SByte: type= "sbyte";break;
case DbType.Single: type= "float";break;
case DbType.String: type= "string";break;
case DbType.StringFixedLength: type= "string";break;
case DbType.Time: type= "TimeSpan";break;
case DbType.UInt16: type= "ushort";break;
case DbType.UInt32: type= "uint";break;
case DbType.UInt64: type= "ulong";break;
case DbType.VarNumeric: type= "decimal";break;
default:
{
type= "__UNKNOWN__" + column.NativeType;
break;
}
}
if(column.AllowDBNull&&
column.SystemType.IsValueType)
{
type=type+"?";
}
return type;
}

public string ConvertToFieldName(string field)
{
return char.ToLower(field[0]).ToString()+field.Substring(1);
}
public string ConvertToPropertyName(string field)
{
return char.ToUpper(field[0]).ToString()+field.Substring(1);
}
</script>

CodeSmith 模版的更多相关文章

  1. [转载]企业级应用架构(NHibernater+Spring.Net+MVC3)

    本人已经从事公司两套这类架构系统的开发工作啦!对于这套架构,我惊叹不已!BPS和CMS系统都是采用这套架构.但本人也同时渐渐发现了这套架构有诸多 不足之处,于是本人利用闲暇时光进一步改进了这套架构.新 ...

  2. CodeSmith的基础模版类(CodeSmith help中的内容)

    基础模版类类型描述: Batch      OutputFileCodeTemplate  模版通过继承此类能够在生成过程中把他们的输出保存到文件中 ScriptError    在脚本执行中出现一个 ...

  3. 2015.05.14:codesmith

    安装: 安装好codesmith会有两个软件:一个编译器(CodeSmith Generator Explorer),一个生成工具(CodeSmith Generator Studio) 破解: 一般 ...

  4. CodeSmith操作Access时字段的排序问题

    最近在用CodeSmith操作写ACCESS数据库的代码模版,发现CodeSmith默认的字段顺序与ACCESS中表的字段顺序不一致. 首先在ACCESS数据库中建一个测试表Test,并添加ID.Na ...

  5. CodeSmith Template Model Output

    背景:上学那会儿就接触CodeSmith,是一款非常优秀的代码自动生成工具.以前写过好些基本模版,可惜早不知道扔到哪儿去了,如今只能重新开始,把它捡回来,加油. 效果:将数据库 DataBase 应用 ...

  6. 代码生成引擎之T4模版

    在学校三年.公司里呆了快一年了,作用ASP.NET开发的我,居然从来没听过T4模版,公司里也没有人使用,它就是这样不为世人所熟知,却又默默的奉献着!这...........tm还是我吗?什么时候会说这 ...

  7. CodeSmith开发系列资料总结

    CodeSmith开发系列资料总结 最近跟同事在研究CodeSmith,感觉中文文档是少之又少,所以我们自己写(翻译)了一些文档,总结如下,希望对使用CodeSmith的朋友有所帮助: “努力学习的熊 ...

  8. 【codesmith】 初次试用(未发布)

      一直都有听过codesmith,一个很好用的软件,减少大量代码的输入,比如你生成一个list,并添加5个项. ArrayList list1=new ArrayList(); list1.Add( ...

  9. 创建ABPboilerplate模版项目

    本文是根据角落的白板报的<通过ABPboilerplate模版创建项目>一文的学习总结,感谢原文作者角落的白板报. 1 准备 开发环境: Visual Studio 2015 update ...

随机推荐

  1. SQL SERVER 自定义函数 split

    Create function [dbo].[split] ( ), ) ) )) as begin declare @i int set @SourceSql=rtrim(ltrim(@Source ...

  2. C#使用seleium实现一个自动登录器

    1.http://docs.seleniumhq.org/ 下载seleium包 2.新建一个C#项目,比如控制台,引用seleium包中的dll using System; using System ...

  3. PHP学习笔记二十【静态方法】

    <?php //静态变量的基本用法 //1,在类中定义变量 //2.定义方式[访问修饰符]static 变量名 //3.访问方式self::$变量名 第二种方式,类名::$变量名 //4.在类外 ...

  4. NPOI通过DataTable导出和读取Excel

    Excel导入及导出问题产生: 从接触.net到现在一直在维护一个DataTable导出到Excel的类,时不时还会维护一个导入类.以下是时不时就会出现的问题: 导出问题: 如果是asp.net,你得 ...

  5. (原)caffe中fine tuning及使用snapshot时的sh命令

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5946041.html 参考网址: http://caffe.berkeleyvision.org/tu ...

  6. 前端开发者使用JS框架的三个等级

    目前前端开发者使用JS框架是种很普遍的现象,因为框架可以加快开发速度,同时避免各类浏览器的兼容性问题.不过同样是用框架开发,不同开发者的境界水平还是有一定差距,本文将这些前端开发者分为三个等级. 第一 ...

  7. Mysql基本类型(五种年日期时间类型)——mysql之二

    转自:<MySQL技术内幕:时间和日期数据类型> http://tech.it168.com/a2012/0904/1393/000001393605_all.shtml

  8. 线程初步了解 - <第一篇>

    操作系统通过线程对程序的执行进行管理,当操作系统运行一个程序的时候,首先,操作系统将为这个准备运行的程序分配一个进程,以管理这个程序所需要的各种资源.在这些资源之中,会包含一个称为主线程的线程数据结构 ...

  9. 深入浅出Node.js (2) - 模块机制

    2.1 CommonJS规范 2.1.1 CommonJS的出发点 2.1.2 CommonJS的模块规范 2.2 Node的模块实现 2.2.1 优先从缓存加载 2.2.2 路径分析和文件定位 2. ...

  10. Remove Nth Node From End of List 解答

    Question Given a linked list, remove the nth node from the end of list and return its head. For exam ...