More capabilities through better use of templating tools

Issue #29 closed
Abel Pereira
created an issue

MOTIVATION: Allow to reuse code for scenarios unsupported for TypeLITE.

Example: It would be very interesting to share ViewModel interfaces from code targeting other platforms (Android, iOS, Win/XAML) and expose it as ViewModel (aka controllers) for AngularJS, of course using TypeScript.

GENERAL IDEA: Bring more logic to the templating mechanist instead of locking it into the TypeLITE assemblies. This would allow other to very easily build .tt scripts on top of TypeLITE and for instance generate ViewModel/Controllers for AngularJS.

Something like this:

<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="$(TargetDir)TypeLite.dll" #>
<#@ assembly name="$(TargetDir)TypeLite.Net4.dll" #>
<#@ assembly name="$(TargetDir)$(TargetFileName)" #>

<#@ import namespace="TypeLite" #> 
<#@ import namespace="TypeLite.Net4" #> 
<#@output extension=".d.ts"#>

// the nice stull will happen here:
<#= 
// TypeScript.Definitions().ForLoadedAssemblies()

var typesToConvert = Typelite.GetTypesFromLoadedAssemblies();
foreach (var typeToConvert in typesToConvert)
{
    // where typeToConvert  would contain the metadata for script generation
 #>

export interface I<#=  typeToConvert.Name.ToCamelCase() #> {
<#= 
  foreach (var propertyToConvert in typeToConvert.Properties)
  {
      <#=  propertyToConvert.Name.ToCamelCase()   #> : <#=  propertyToConvert.Type.ToJavaScriptType()   #>;
  }
 #>

<#= 
  foreach (var methodToConvert in typeToConvert.Methods)
  {
      <#=  methodToConvert .Name.ToCamelCase()   #> : // and so on...
  }
 #>
}


<#= 
}
 #>

Comments (2)

  1. Lukas Kabrt repo owner

    There might be a more elegant way of doing it, but it's perfectly possible even now - just instead of using the fluent interface you need to use underlaying classes.

    Something like this:

    <#= 
    var builder = new TsModelBuilder();
    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
        builder.Add(assembly);
    }
    var model = builder.Build();
    
    foreach (var classToConvert in model.Classes) {
       ...
    }
    #>
    
  2. Log in to comment