Generate related classes in batches based on object classes, and generate object classes

Source: Internet
Author: User

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 );
#>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.