嵌套的C#类无法通过打字机正确转换为TS类

时间:2018-06-21 10:38:06

标签: c# angular typewriter

我正在尝试将具有TsType属性的C#类转换为TS类,以在我的角度应用程序中使用。我在Visual Studio 2015应用程序中安装了打字机,并对其进行了配置。我可以看到它正在生成TS类(除了一个)。

我有一个嵌套类,它似乎无法识别该嵌套类,因此在生成的文件中被省略了。如果您在生成的代码中注意到,它还没有生成嵌套的数据类,因此会抱怨说在我构建我的角度应用程序时找不到数据。

有人遇到吗?

C#类:

[TsType]
public class BoxPlotSeries
{
    public string color { get; set; }
    public string name { get; set; }
    public Data data { get; set; }

    [TsType]
    public class Data
    {
        public decimal Low { get; set; }
        public decimal Q1 { get; set; }
        public decimal Median { get; set; }
        public decimal Q3 { get; set; }
        public decimal High { get; set; }
    }
}

生成的文件:

 export interface BoxPlotSeries  {
        color: string;
        name: string;
        data: Data;
    }

1 个答案:

答案 0 :(得分:0)

您可以使用一种$NestedClasses方法。所以像这样的东西会产生父母和孩子的第一层……

$Classes(c => c.Attributes.Any(a => a.Name == "TsType"))[

    export interface $Name$TypeParameters { $Properties[
        $name: $Type;]
    }]

    $Classes()[$NestedClasses(c => c.Attributes.Any(a => a.Name == "TsType"))[        
    export class $Name {
        $Properties[    
        public $Name: $Type;]
    }]]
}