You can TypeScript and C# class source code, whith copatible by JSON format.

Use desktop application Simple TypeScript and C# Class Generator, and set class informations.

Hot to use!

1) Create ASP.NET Web Application in VS2013

2) Select Web API Project

3) Add C# and TypeScript source file.

4) enter class information to this tool

pic0001.png

5) push 'Generate Source Code'

pic0002.png

 then you get two source code, C# and TypeScript.

6) Copy them and paste your project

C# part Simple Sample

full souce code is available in Source Code
    public class ValuesController : ApiController
    {
        // GET api/values
        public test2 Get()
        {
            return new test2()
            {
                myname = "John Smith",
                myage = 17,
                test3 = new test3()
                {
                    Country = "Unit States"
                }
            };
        }
    }

Generated Code Sample for C#

// generated by tscsclassgen
// 2013/10/12 18:33:24

public class test1
{
    public string myname;
    public double myage;
}
public class test2 : test1
{
    public test3 test3;
}
public class test3
{
    public string Country;
}

Generated Code Sample for TypeScript

// generated by tscsclassgen
// 2013/10/12 18:33:24
class test1 {
    public myname: string;
    public myage: number;
}
class test2 extends test1 {
    public test3: test3;
}
class test3 {
    public Country: string;
}

TypeScirpt part Simple Sample

full souce code is available in Source Code
$(document).ready(function () {
    $.ajax({
        url: "api/values",
        type: "GET",
        dataType: "json",
        success: function (json) {
            var t: test2;
            t = json;
            $("#tgt1").text("my name is " + t.myname);
            $("#tgt2").text("my age is " + t.myage);
            $("#tgt3").text("my country is " + t.test3.Country);
        },
        error: function (xhr, status) {
            alert("Sorry, there was a problem!");
        },
    });
});

Last edited Oct 14, 2013 at 8:37 AM by autumn009, version 5