TypeWriter - 过滤不具有给定属性的类或属性

问题描述:

使用打字机.tst文件可以仅使用$Properties([MyAttr])过滤器包含具有特定属性的属性。TypeWriter - 过滤不具有给定属性的类或属性

喜欢本作例子:

export class $Name{ 
     $Properties([MyAttr])[ 
     public $name: $Type = $Type[$Default];] 
    } 

是否有可能包括所有属性除了那些给定的属性?

事情是这样的,也许:

export class $Name{ 
     $Properties(![TsIgnore])[    //but this doesnt work!! 
     public $name: $Type = $Type[$Default];] 
    } 

我已经试过了我能想到的![TsIgnore][!TsIgnore]等但没有工作。也找不到在docs

+0

我知道的最简单的方法是在过滤器内部使用Lambda表达式。例如。 '$ Properties(p =>!p.Attributes.Any(...))[...]' –

什么我实现一个IsIncluded方法:

bool IsIncluded(Class c) 
{ 
    // exclude attributes 
    if(c.BaseClass?.FullName == "System.Attribute") return false; 

    return !ExcludeObjects.Any(ec => c.Name == ec || c.FullName == ec); 
} 
顶部

和地方,我有这样的:

static string[] ExcludeObjects = new string[] 
{ 
    "MyClassToExclude", 
    "Full.Namespace.Path.To.MyOtherClassToExclude", 
}; 

和模板具有这样的:

$Classes($IsIncluded)[ ... ] 

谢谢

您还可以使用

bool IsIncluded(Property c) 
    { 
     if(c.Attributes.Any(a => String.Equals(a.name, "TypeScriptExportExlude", StringComparison.OrdinalIgnoreCase))) 
     return false; 
     return true; 
    } 

其中“TypeScriptExportExlude”是要排除你的财产属性。