2016-07-15 64 views
1

目前我正在使用Typewriter从我的C#类自动生成TypeScript类。可以说我有这个非常简单的C#类:打字机:生成TypeScript参数属性

[Dto] 
public class MyDto 
{ 
    public string Prop1 { get; set; } 

    public string Prop2 { get; set; } 
} 

我也有这个简单的打字机模板:

$Classes(c => c.Attributes.Any(x => x.Name == "Dto"))[ 
export class $Name { 
    constructor(
     $Properties[ 
      public $name: string, 
     ] 
    ) { } 
}] 

我有这个模板的问题是,有最后的构造后,尾随逗号在所生成的TS类参数属性:

export class MyDto { 
    constructor(
      public prop1: string, 
      public prop2: string,  /* <---- notice the comma here */ 
    ) { } 
} 

我想有作为打字稿类参数属性生成的C#类的属性,但与生成的TypeScript上面的示例无效。打字机模板有没有办法实现这一点?

回答

4

要回答我的问题:我修改这样的模板:

$Classes(c => c.Attributes.Any(x => x.Name == "Dto"))[ 
export class $Name { 
    constructor(
     $Properties[ 
      public $name: string][,] 
    ) { } 
}]