问题描述
我将在我的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;
}
还有一个。
为了保持更新,TypeLite可以从C#生成TypeScript接口:
Just to keep things updated, TypeLite can generate TypeScript interfaces from C#:
这篇关于如何在TypeScript项目中重用现有的C#类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!