打字机:生成TypeScript参数属性

时间:2016-07-15 10:53:21

标签: typewriter

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

[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 */
    ) { }
}

我希望在TypeScript类中将C#类的属性生成为参数属性,但是上面的示例生成的TypeScript无效。有没有办法用打字机模板实现这个目标?

1 个答案:

答案 0 :(得分:6)

回答我自己的问题:我修改了这样的模板:

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