Text Template Transformation Toolkit
Text Template Transformation Toolkit


- <#@ template debug="false" hostspecific="false" language="C#" #>
- <#@ assembly name="System.Core" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Text" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#@ output extension=".cs" #>
- public class Samsung
- {
- <# for(int i=;i<;i++) {#>
- public string S<#=i#>{get;set;}
- <#}#>
- }
写一下控制块的代码
- public class Samsung
- {
- public string S1{ get; set;}
- public string S2{ get; set;}
- public string S3{ get; set;}
- public string S4{ get; set;}
- }
看一下三星的旗舰
- <#@ template debug="false" hostspecific="false" language="C#" #>
- <#@ assembly name="System.Core" #>
- <#@ import namespace="System.Linq" #>
- <#@ import namespace="System.Text" #>
- <#@ import namespace="System.Collections.Generic" #>
- <#@ output extension=".cs" #>
- public class Meizu
- {
- <# for(int i=;i<;i++) {#>
- public string MX<#=i#>{get;set;}
- <#}#>
- }
修改下控制块代码,我想要梦想
- public class Meizu
- {
- public string MX1{ get; set;}
- public string MX2{ get; set;}
- public string MX3{ get; set;}
- public string MX4{ get; set;}
- }
且容我看一眼梦想。
那么T4是有点帅,还是很有点帅。
那么很有点帅,或者相当帅吧。
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Anmutu.OA.IDAL
- {
- /// <summary>
- /// 此接口抽象了DAL实例里公共方法的约束。
- /// </summary>
- public interface IBaseDal<T> where T: class, new ()
- {
- T Add(T entity);
- bool Update(T entity);
- bool Delete(T entity);
- int Delete( params int[] ids);
- }
- }
IBaseDal
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Anmutu.OA.Model;
- namespace Anmutu.OA.IDAL
- {
- /// <summary>
- /// 创建一个接口,约定其返回类型是User类,参数是一个user实体。
- /// </summary>
- public interface IUserDal:IBaseDal<User>
- {
- }
- }
IUserDal
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.Entity;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Anmutu.OA.Model;
- using EntityState = System.Data.Entity.EntityState;
- namespace Anmutu.OA.DAL
- {
- /// <summary>
- /// 把数据库访问层的公共方法抽出来实现。
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public particl class BaseDal<T> where T: class, new() //类。且有一个默认的构造函数。
- {
- //写在这里就没做到线程实例唯一了。此处亦就用简单工厂得到上下文实例。
- private Model.AnmutuModelContainer db = new AnmutuModelContainer();
- public T Add(T entity)
- {
- db.Set<T>().Add(entity);
- db.SaveChanges();
- return entity;
- }
- public bool Update(T entity)
- {
- db.Entry(entity).State = EntityState.Modified;
- return db.SaveChanges() > ;
- }
- public bool Delete(T entity)
- {
- db.Entry(entity).State = EntityState.Deleted;
- return db.SaveChanges() > ;
- }
- public int Delete( params int[] ids)
- {
- foreach ( var id in ids)
- {
- //如若实体已经在内存中就在内存中拿,如果内存中没有则查询数据库。
- var entity = db.Set<T>().Find(id);
- db.Set<T>().Remove(entity);
- }
- return db.SaveChanges();
- }
- }
- }
BaseDal
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Anmutu.OA.IDAL;
- using Anmutu.OA.Model;
- using EntityState = System.Data.Entity.EntityState;
- namespace Anmutu.OA.DAL
- {
- public partial class UserDal : BaseDal<User>,IUserDal //这里实现接口。
- {
- }
- }
UserDal
笔者注:其中有代码少了PARTICAL关键字,如若改兴趣,你会发现是哪里的,笔者就不回去做修改了。
- <#@ template language="C#" debug="false" hostspecific="true"#>
- <#@ include file="EF.Utility.CS.ttinclude"#>
- <#@ output extension=".cs"#>
- <#
- CodeGenerationTools code = new CodeGenerationTools(this);
- MetadataLoader loader = new MetadataLoader(this);
- CodeRegion region = new CodeRegion(this, );
- MetadataTools ef = new MetadataTools(this);
- string inputFile = @"..\\Anmutu.OA.Model\\AumutuModel.edmx";
- EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
- string namespaceName = code.VsNamespaceSuggestion();
- EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
- #>
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Anmutu.OA.IDAL;
- using Anmutu.OA.Model;
- using EntityState = System.Data.Entity.EntityState;
- namespace Anmutu.OA.DAL
- {
- <#
- foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
- {
- #>
- public partial class <#=entity.Name#>Dal : I<#=entity.Name#>Dal
- {
- }
- <#}#>
- }
IUserDal的T4
Text Template Transformation Toolkit的更多相关文章
- C# Meta Programming - Let Your Code Generate Code - Introduction of The Text Template Transformation Toolkit(T4)
<#@ template language="C#" #> <#@ output extension=".cs" #> <#@ a ...
- T4((Text Template Transformation Toolkit))模版引擎之基础入门 C#中文本模板(.tt)的应用
1 关于C#中文本模板(.tt)的简单应用https://blog.csdn.net/zunguitiancheng/article/details/78011145 任何一个傻瓜都能写出计算机能理解 ...
- go语言的模板,text/template包
go语言的模板,text/template包 定义 模板就是将一组文本嵌入另一组文本里 传入string--最简单的替换 package main import ( "os" &q ...
- script "text/template"
<script type="text/template" id="orgItem"> <div class="{orgClass}& ...
- go标准库的学习-text/template
参考:https://studygolang.com/pkgdoc 导入方式: import "text/template" template包实现了数据驱动的用于生成文本输出的模 ...
- <script type="text/template">是干什么的,为什么要把html写在js中? 这是什么编程语言风格,都能这样用吗?
这一段存放了一个模板.在js里面,经常需要使用js往页面中插入html内容.比如这样: var number = 123; $('#d').append('<div class="t& ...
- 前端模板<script type="text/template" id="tmpl">
前端模板, 比连接字符串好用多了, 还可以使用循环\判断等语句, 减少工作量 <script type="text/template" id="member-tmp ...
- 关于MVC模板渲染的一点小事type="text/template"
先上一个demo,简单粗暴,请自便 <!DOCTYPE html> <html> <head lang="en"> <meta chars ...
- 关于 <script type='text/template' > 的妙用 / 使用jquery获取iframe加载完成事件
https://www.cnblogs.com/ddqyc/p/6200539.html <!DOCTYPE html> <html> <head> <met ...
随机推荐
- External Table
CREATE TABLE AS SELECT,使用Oracle9i的External Table Oracle 9i 的一项新特性就是 External Table,它就象通常的数据库表一样,拥有字 ...
- DIV+CSS解决IE6,IE7,IE8,FF兼容问题
1.IE8下兼容问题,这个最好处理,转化成IE7兼容就可以.在头部加如下一段代码,然后只要在IE7下兼容了,IE8下面也就兼容了:1. <metahttp-equivmetahttp-equiv ...
- 小菜鸟带着梦想学chromium
风雨送春归, 飞雪迎春到. 已是悬崖百丈冰, 犹有花枝俏. 俏也不争春, 只把春来报. 待到山花烂漫时, 她在丛中笑. 这首卜算子·咏梅可是应了我的心情了.最近换工作,受到频频打击,面试过程中发现满世 ...
- 【学习笔记】【C语言】字符串数组
1.使用场合 * 一维字符数组中存放一个字符串,比如一个名字char name[20] = "mj" * 如果要存储多个字符串,比如一个班所有学生的名字,则需要二维字符数组,cha ...
- 多文件上传artDialog+plupload
一.效果展示 包括文件上传面板以及文件上传列表 二.介绍 长话短说,采用spring springMVC mybatis maven mysql,实现多文件上传功能,下载使用的是流的形式. 其中涉及的 ...
- 杭电ACM1170--Balloon Comes!
地址 http://acm.hdu.edu.cn/showproblem.php?pid=1170 #include<stdio.h> int main() { int t,a,b; ] ...
- VBA访问SQLSERVER2005筛选数据库
EXCEL版本2010, 引用 Private Sub CommandButton1_Click() Dim conn As New ADODB.Connection Dim rs As New AD ...
- unity打包android游戏部分问题总结
一:虚拟导航栏挡到游戏按钮: 解决方案如下: 1.获取焦点的时候隐藏 虚拟导航条 Navigation bar 隐藏导航条 2.出现导航条的时候,改变游戏界面大小 Unity tidbits: cha ...
- Jquery Slick幻灯片插件
slick 是一个基于 jQuery 的幻灯片插件,具有以下特点: 支持响应式 浏览器支持 CSS3 时,则使用 CSS3 过度/动画 支持移动设备滑动 支持桌面浏览器鼠标拖动 支持循环 支持左右控制 ...
- net中的编译
1.MSBuild 四个基本块(属性.项.任务.目标): MSBuild属性: 属性是一些键/值对,主要用来存储一些配置信息. MSBuild 项: 主要是存储一些项目文件信息,以及文件的元 ...