David Thielen
David Thielen

Reputation: 33006

.cs class definitions auto-created in .ts

I need to have a REST server (written in C#) pass a JSON object to/from my typescript client running in a browser. The best way to do this is define the class on the C# side that then creates a JSON object passed to the client where that JSON object matches the class structure in the client.

Which leads to the obvious question - is there a way to define the classes in C# and then run some program that will create the .ts class definitions? Or the reverse where I write out the classes in .TS and a program then creates matching .cs classes?

What I want to avoid is having to make sure any member added on one side is then added exactly the same on the other side.

And in a perfect world, the comments written for the class members are carried across too.

Update: I know I can write such a tool. However I'm hoping it already exists as that's a lot of work.

Upvotes: 2

Views: 646

Answers (2)

Richard
Richard

Reputation: 751

I created a library which allows you to create JS-models for knockout and backbone out of c#-classes (mainly for domain-classes, so it comes with stuff like DataAnnotations-support, etc).

I added support for Typescript, as well as a small tool to create the files directly.

Check it out and if you have time, I'd love some feedback :) https://jsmapper.codeplex.com/

Cheers, Richard

Upvotes: 1

basarat
basarat

Reputation: 276255

Type lite http://type.litesolutions.net/ gets you halfway. Just the data member signature.

As you know json doesn't carry behaviour just data. So no functions will not be available on the other side. It's not a "transpiler"

And in a perfect world, the comments written for the class members are carried across too.

Doesn't do this.

Upvotes: 2

Related Questions