首页 > 代码库 > 批量根据实体类生成相关的类
批量根据实体类生成相关的类
<#
// 从实体类生成相关的实体类
#>
<#@ template hostspecific="true" language="C#" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Configuration" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ include file="MultipleOutputHelper.ttinclude" #>
<#
//Multi output
var fileManager = Manager.Create(Host, GenerationEnvironment);
//所引用的using
var modelSp = "Hanlly.MedicalEthics.Models.MedicalQualityDB";
var repSp = "Hanlly.MedicalEthics.Repository";
var repBaseSp = "Hanlly.MedicalEthics.Repository.Infrastructure";
string modelDir = @"D:\work\yiliao\Hanlly.MedicalEthics.Models\MedicalQualityDB"; //需要生成的实体类文件所在的路径
var fileList = Directory.GetFiles(modelDir, "*.cs");
int fileCount = 0;
foreach (var file in fileList)
{
var fileInfo = new FileInfo(file);
var fileName = Path.GetFileNameWithoutExtension(file);
if(fileName.EndsWith("Context")){
continue;
}
var modelName = fileName;
fileName = fileName.Replace("_", "");
var repFileName = fileName + "Repository";
var repFileNameWithExtension = repFileName + ".cs";
//Repository Register
var register = "For<I" + repFileName + ">().Use<" + repFileName + ">();"; //生成的文件名
fileManager.StartNewFile(repFileNameWithExtension);
#>
/**********************************************************************************
*
* 文件名称 :<#= repFileNameWithExtension #>
* 作者 : HuangFL
* 创建时间 : <#= DateTime.Now.ToString("yyy-MM-dd hh:mm:ss") #>
*
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using <#= modelSp #>;
using <#= repBaseSp #>;
namespace <#= repSp #>
{
public interface I<#= repFileName #> : IRepository<<#= modelName #>>
{
}
public class <#= repFileName #> : RepositoryBase<<#= modelName #>>, I<#= repFileName #>
{
public <#= repFileName #>(IDefaultDataContextFactory factory)
: base(factory)
{
}
}
}
<#
fileManager.EndBlock();
WriteLine("//" + register);
fileCount ++;
}
fileManager.Process(true);
WriteLine("//一共生成文件数 : " + fileCount);
#>
// 从实体类生成相关的实体类
#>
<#@ template hostspecific="true" language="C#" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Configuration" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ include file="MultipleOutputHelper.ttinclude" #>
<#
//Multi output
var fileManager = Manager.Create(Host, GenerationEnvironment);
//所引用的using
var modelSp = "Hanlly.MedicalEthics.Models.MedicalQualityDB";
var repSp = "Hanlly.MedicalEthics.Repository";
var repBaseSp = "Hanlly.MedicalEthics.Repository.Infrastructure";
string modelDir = @"D:\work\yiliao\Hanlly.MedicalEthics.Models\MedicalQualityDB"; //需要生成的实体类文件所在的路径
var fileList = Directory.GetFiles(modelDir, "*.cs");
int fileCount = 0;
foreach (var file in fileList)
{
var fileInfo = new FileInfo(file);
var fileName = Path.GetFileNameWithoutExtension(file);
if(fileName.EndsWith("Context")){
continue;
}
var modelName = fileName;
fileName = fileName.Replace("_", "");
var repFileName = fileName + "Repository";
var repFileNameWithExtension = repFileName + ".cs";
//Repository Register
var register = "For<I" + repFileName + ">().Use<" + repFileName + ">();"; //生成的文件名
fileManager.StartNewFile(repFileNameWithExtension);
#>
/**********************************************************************************
*
* 文件名称 :<#= repFileNameWithExtension #>
* 作者 : HuangFL
* 创建时间 : <#= DateTime.Now.ToString("yyy-MM-dd hh:mm:ss") #>
*
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using <#= modelSp #>;
using <#= repBaseSp #>;
namespace <#= repSp #>
{
public interface I<#= repFileName #> : IRepository<<#= modelName #>>
{
}
public class <#= repFileName #> : RepositoryBase<<#= modelName #>>, I<#= repFileName #>
{
public <#= repFileName #>(IDefaultDataContextFactory factory)
: base(factory)
{
}
}
}
<#
fileManager.EndBlock();
WriteLine("//" + register);
fileCount ++;
}
fileManager.Process(true);
WriteLine("//一共生成文件数 : " + fileCount);
#>
批量根据实体类生成相关的类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。