如何在TypeScript项目中重用现有的C#类定义 [英] How to reuse existing C# class definitions in TypeScript projects

查看:131
本文介绍了如何在TypeScript项目中重用现有的C#类定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在我的HTML客户端项目中开始使用 TypeScript ,该项目属于具有实体框架域模型的MVC项目。我希望我的两个项目(客户端和服务器端)完全分开,因为两个团队将在此工作...... JSON和REST用于来回传递对象。

I am just going to start use TypeScript in my HTML client project which belongs to a MVC project with a entity framework domain model already there. I want my two projects (client side and server side) totally separated as two teams will work on this... JSON and REST is used to communicate objects back and forth.

当然,客户端的对象应该与服务器端的对象匹配。在过去,我通常手动完成此操作。有没有办法重用我的C#类定义(特别是我的域模型中的 POJO 类)来在TypeScript中创建相应的类?

Of course, my domain objects on the client side should match the objects on the server side. In the past, I have normally done this manually. Is there a way to reuse my C# class definitions (specially of the POJO classes in my domain model) to create the corresponding classes in TypeScript"?

推荐答案

目前没有任何东西可以将C#映射到TypeScript。如果你有很多POCO或者你认为它们可能经常变化,你可以创建一个转换器 - 简单的... ...

There is not currently anything that will map C# to TypeScript. If you have a lot of POCOs or you think they might change often, you could create a converter - something simple along the lines of...

public class MyPoco {
    public string Name { get; set; }
}

export class MyPoco {
    public Name: string;
}

还有一个有关从C#自动生成的Codeplex的讨论

为了保持更新,TypeLite可以从C#生成TypeScript接口:

Just to keep things updated, TypeLite can generate TypeScript interfaces from C#:

http://type.litesolutions.net/

这篇关于如何在TypeScript项目中重用现有的C#类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆