0

I am evaluating TypeScript to see if it could save time in development for my requirements. Lets say I define simple classes to get and set hidden fields with the main purpose of being generic and working with MVC models.

class BaseObject {
    _Name: string;
    constructor(public name) { this._Name = name; }
}

interface BaseForm {
    SaveFields(): void;
    GetFields(): void;
    ToQueryString(): string;
    ToJsonString(): string;
}


class BaseReportForm extends BaseObject implements BaseForm {

    constructor(name) { super(name); }

    public PageNumber: number;
    public AllowPaging: bool;
    public ExportLink: string;
    ...
    SaveFields() {//WRITE HIDDEN FIELDS TO FORM }
    GetFields() { //GET HIDDEN FIELDS FROM FORM}
    ToQueryString() { return "Hidden Fields To Query String"; }
    ToJsonString() { return "Hidden Fields To Json"; }
} 

This all works great, however, I am not seeing anything that would allow me to work with @Models. It would be nice to be able to have the ability to magically do the following:

var ReportForm=new ReportForm(@Model.Report);

I am aware that to achieve this functionality there would have to be another translation layer of translations. Are there any tools that would help if it turns out to be a time saver? Similar to an ORM mapper or auto mapper but would work with JS or TypeScript?

Fenton
  • 241,084
  • 71
  • 387
  • 401
Ross Bush
  • 14,648
  • 2
  • 32
  • 55

1 Answers1

1

Yup there is TypeLITE that will convert your C# classes to TypeScript : http://type.litesolutions.net/

First create a TypeScript class from your C# class using TypeLITE. Next pass in your c# class instance to your TypeScript in your razor view as JSON https://stackoverflow.com/a/4072787/390330

Community
  • 1
  • 1
basarat
  • 261,912
  • 58
  • 460
  • 511