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

查看:41
本文介绍了如何在 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.

当然,我在客户端的 domain 对象应该与服务器端的对象匹配.过去,我通常手动完成此操作.有没有办法重用我的 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天全站免登陆