Generate related classes in batches based on object classes, and generate object classes
<#
// Generate the relevant entity class from the object class
#>
<# @ 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 );
// The referenced 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"; // path of the object class file to be generated
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 + "> ();"; // generated file name
FileManager. StartNewFile (repFileNameWithExtension );
#>
/*************************************** **************************************** ***
*
* File name: <# = repFileNameWithExtension #>
* Author: HuangFL
* Creation Time: <# = 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 ("// total number of files generated:" + fileCount );
#>