Here is my custom filtering method to extract only class files within the Models
namespace that are tagged with a TypeScript
attribute. Any properties marked with TypeScriptIgnore
will be excluded.
${
// To enable extension methods, include Typewriter.Extensions.*
using Typewriter.Extensions.Types;
// Uncomment the constructor for template settings adjustment.
bool FilterInNamespace(Class c)
{
if(c.Attributes.Any(a=>a.Name == "TypeScript") && c.Namespace.Contains("Models"))
{
return true;
}
else{
return false;
}
}
bool IgnoreProperty(Property p)
{
if(p.Attributes.Any(a => String.Equals(a.name, "TypeScriptIgnore", StringComparison.OrdinalIgnoreCase)
|| String.Equals(a.name,"NotMapped",StringComparison.OrdinalIgnoreCase)))
return false;
return true;
}
// Custom extension methods can be accessed in template by adding $ prefix e.g. $LoudName
}
module MyApp {
$Classes($FilterInNamespace)[
export class $Name {
$Properties($IgnoreProperty)[
// $LoudName
public $name: $Type = $Type[$Default];]
}]
}