Code Generator

The Code Generator is encapsulated in the Sidvall.CodeGenerator project. The code generation has the following work flow:

  1. Resource file(s) are parsed to create a domain model (Sidvall.CodeGenerator.DomainModel).
  2. T4 templates (*.ttinclude) are used to create code based on the domain model.

The Code Generator can create a domain model from the following resources:

  • edmx-files (Entity Framework 6)
  • xsd-files (NOT COMPLETED)
  • resx-files

The T4-templates that are used to create code files are located in Dependencies\Templates.

An example of how to generate code is shown in Dependencies\Templates\System.tt.

  1: // Create domain model from edmx file
  2: var m = Sidvall.CodeGenerator.EdmxHelper.NewDomainModel("Model.edmx");
  3: // Create domain model from resource file
  4: var m = Sidvall.CodeGenerator.ResourceFileHelper.NewDomainModel("Resources.resx", "en-US");
  5: // Create domain model from xsd files (NOT FINISHED)
  6: var m = Sidvall.CodeGenerator.XsdHelper.NewDomainModel("Model.xsd");
  7: // Generate Business Layer
  8: this.RenderResourceLayer(m, @"XXX\GeneratedCode\Data");
  9: this.RenderBusinessLayer(m, @"XXX\GeneratedCode");
 10: // Generate Data Layer
 11: this.RenderBusinessLayerDataPortalLocal(m, @"XXX\GeneratedCode");
 12: this.RenderDataLayer(m, @"XXX.Data.Entity\GeneratedCode");
 13: // Generate Web API Layer
 14: this.RenderBusinessLayerServicesController(m, @"XXX.Web\GeneratedCode\Controllers\Api");
 15: // Generate Portable REST Client
 16: this.RenderBusinessLayerDataPortalRemote(m, @"XXX\GeneratedCode");
 17: // Generate JavaScript REST Client
 18: this.RenderWebLayer(m, @"XXX.Web\GeneratedCode\Scripts");
 19: this.RenderWebLayerBO(m, @"XXX.Web\GeneratedCode\Scripts");
 20: this.RenderWebLayerDataPortal(m, @"XXX.Web\GeneratedCode\Scripts");
 21: // Generate Web Client Resource File
 22: this.RenderWebLayerResources(m, @"\XXX.Web\GeneratedCode");
 23: 

Last edited Mar 17, 2014 at 2:27 PM by sidwall, version 5