Currently I am able to generate my main model files (partial model and generated partial model).
this is my current template:
Code: Select all
<#
// Empty template for Devart Entity Developer C# code generation.
// Copyright (c) 2008-2018 Devart. All rights reserved.
#>
<#@ template language="C#" #>
<#@ include file="Validation.tmpl" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Xml" #>
<#
//------------------------------------------------------------------------------
// Template properties:
//------------------------------------------------------------------------------
// Output options
#>
<#@ property name="ModelNameSpace" displayName="Model namespace" category="Model" type="System.String" description="Specifies output namespace for the generated model entity classes." #>
<#@ property name="ModelGeneratedOutput" displayName="Model Generated" category="Model" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="ModelPartialOutput" displayName="Model Empty Partial" category="Model" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="ModelDapperNameSpace" displayName="Dapper Model namespace" category="Dapper" type="System.String" description="Specifies output namespace for the generated model entity classes." #>
<#@ property name="ModelDapperGeneratedOutput" displayName="Dapper Model Generated" category="Dapper" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="ModelDapperPartialOutput" displayName="Dapper Model Empty Partial" category="Dapper" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="MetaModelNameSpace" displayName="Meta Model namespace" category="Meta" type="System.String" description="Specifies output namespace for the generated model entity classes." #>
<#@ property name="MetaModelrGeneratedOutput" displayName="Meta Model Generated" category="Meta" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="MetaModelPartialOutput" displayName="Meta Model Empty Partial" category="Meta" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="InterfaceNameSpace" displayName="Interface namespace" category="Interface" type="System.String" description="Specifies output namespace for the generated model entity classes." #>
<#@ property name="InterfaceGeneratedOutput" displayName="Interface Generated" category="Interface" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#@ property name="InterfacePartialOutput" displayName="Interface Empty Partial" category="Interface" type="OutputInfo" editor="OutputInfoEditor" description="Specifies output for the generated model entity classes." #>
<#
// Settings
output.Extension = ".cs";
output.FileName = model.FileName;
string namespaceName = codeProvider.GetValidIdentifier(model.Namespace);
// Begin generation
//------------------------------------------------------------------------------
// Class generation for entities
//------------------------------------------------------------------------------
var namespaces = from cls in model.Classes.Cast<Class>()
let nspName = !String.IsNullOrEmpty(cls.Namespace) ? codeProvider.GetValidIdentifier(cls.Namespace) : namespaceName
group cls by nspName;
// get namespaces?
foreach (var _namespace in namespaces) {
// get classes
foreach (EntityClass cls in _namespace) {
// handle class generation
string rootFileName = cls.Name;
output.Extension = ".cs";
output.PushOutputRedirection(ModelPartialOutput, "", rootFileName, OverwriteMode.None);
// generate empty partial
GenerateEnmptyPartial(_namespace.Key, cls);
output.PopOutputRedirection();
// generate base class
output.Extension = ".cs";
output.PushOutputRedirection(ModelGeneratedOutput, rootFileName + ".Generated");
//GeneratePocoClass(_namespace.Key, cls);
GeneratePOCO(_namespace.Key, cls);
output.PopOutputRedirection();
}
}
// End of generation
#>
<#+
///
/// Generates Class as Partial (Empty) for user declarations
///
private void GenerateEnmptyPartial(string _namespaceKey, EntityClass cls)
{#>
namespace <#= _namespaceKey #>
{
<#= codeProvider.FormatClassAccess(cls.Access) #> partial class <#= codeProvider.GetValidIdentifier(cls.Name) #>
{
}
}
<#+
}
#>
<#+
///
/// Generates Class as Partial (Empty) for user declarations
///
private void GeneratePOCO(string _namespaceKey, EntityClass cls)
{#>
namespace <#= _namespaceKey #>
{
//------------------------------------------------------------------------------
// This is auto-generated code.
//------------------------------------------------------------------------------
// This code was generated by Devart Entity Developer tool using custom template at <#= DateTime.Now #>
//
// OW ED T4
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//------------------------------------------------------------------------------
<#= codeProvider.FormatClassAccess(cls.Access) #> partial class <#= codeProvider.GetValidIdentifier(cls.Name) #>
{
#region properties
#endregion
public <#= codeProvider.GetValidIdentifier(cls.Name) #>() {
}
}
}
<#+}#>