简体   繁体   中英

Nested c# class not getting converted to TS class correctly by typewriter

I am trying to convert C# classes with the TsType attribute to TS classes to be used in my angular application. I have installed typewriter in my Visual Studio 2015 application and its been configured. I can see that it is generating the TS classes except for one.

I have a nested class and it doesn't seem to recognize the nested class hence gets omitted in the generated file. If you notice in the generated code, it hasn't generated the nested data class and hence complains saying data not found when I build my angular application.

Has anybody come across this?

C# class:

[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; }
    }
}

Generated file:

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

There's a $NestedClasses method you can use. So something like this would generate the parent and the first level of children...

$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;]
    }]]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM