Created
December 27, 2014 08:42
-
-
Save valeriob/3e13bd1b0fab3474ecbc to your computer and use it in GitHub Desktop.
TypeLite.Net4.tt (1.0.1.0) Knockout support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ 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