Skip to content

Instantly share code, notes, and snippets.

@valeriob
Created December 27, 2014 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valeriob/3e13bd1b0fab3474ecbc to your computer and use it in GitHub Desktop.
Save valeriob/3e13bd1b0fab3474ecbc to your computer and use it in GitHub Desktop.
TypeLite.Net4.tt (1.0.1.0) Knockout support
<#@ 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" #>
<#@ import namespace="TypeLite.TsModels" #>
<#@output extension=".d.ts"#>
<#@include file="Manager.ttinclude"#>
<# var manager = Manager.Create(Host, GenerationEnvironment); #>
<# var ts = TypeScript.Definitions()
.WithReference("Enums.ts")
.ForLoadedAssemblies()
.WithFormatter(KnockoutTypeConverter)
.WithFormatter(KnockoutMemberTypeConverter)
.WithFormatter(KnockoutMemberIdentifierConverter)
;
#>
<#= ts.Generate(TsGeneratorOutput.Properties) #>
<# manager.StartNewFile("Enums.ts"); #>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<# manager.EndBlock(); #>
<# manager.Process(true); #>
<#+
public string KnockoutTypeConverter(TsType type, ITsTypeFormatter formatter)
{
return type.ClrType.Name;// + "ViewModel";
}
public string KnockoutMemberTypeConverter(string memberTypeName, bool isMemberCollection, int dimension = 1)
{
if (isMemberCollection)
{
return string.Format("KnockoutObservableArray<{0}>", memberTypeName);
}
else
{
return string.Format("KnockoutObservable<{0}>", memberTypeName);
}
}
public string KnockoutMemberIdentifierConverter(IMemberIdentifier identifier)
{
return identifier.Name;
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment