Search code examples
typescode-generationtelosys

How to change Telosys default types according with the target language?


It seems Telosys code generator uses Java types by default.

For example, if a field type is “int” in the model the language type generated is “Integer” (or “int” if “@PrimitiveType” or “@NotNull”).

Is it possible to change the types according with the target language?

In my case I’d like to generate code C#. So expected types are "int", "uint", "Int32"


Solution

  • Indeed, the default target language is Java but you can change it.

    You just have to define the target language in each template file (".vm" file) needing type conversion.

    To do that use the instruction $env.setLanguage('Language-Name')

    For example $env.setLanguage('C#') set C# as the target language for the current ".vm" file

    $env.setLanguage('C#') // Set target language
    #foreach( $attrib in $entity.attributes )
       public $attrib.type  $attrib.name { get; set; }  // 'attrib.type' is now C# type  
    #end