简体   繁体   English

C#、TypeScript 和 Python 的共享类定义

[英]Shared class definitions for C#, TypeScript and Python

We are developing a set of apps that share about 15 classes.我们正在开发一组共享大约 15 个类的应用程序。 The UI is Angular8, The API is C#, and we have some Azure Functions running Python. UI 是 Angular8,API 是 C#,我们有一些运行 Python 的 Azure Functions。 We're using Azure DevOps.我们正在使用 Azure DevOps。

So far we've manually defined the classes in each separate project and manually checked that they are no mismatches.到目前为止,我们已经在每个单独的项目中手动定义了类,并手动检查了它们是否不匹配。 But as the number of apps grows, we're going to hit a wall soon.但随着应用程序数量的增长,我们很快就会遇到困难。

Ideally we'd want to have the following scenario:理想情况下,我们希望有以下场景:

  • define these classes in a C# class library and then generate their equivalent in TypeScript and Python (two other libraries)在 C# 类库中定义这些类,然后在 TypeScript 和 Python(另外两个库)中生成它们的等效项
  • have these 3 class libraries available for import for the C#/TypeScript/Python apps有这 3 个类库可用于导入 C#/TypeScript/Python 应用程序

Is there a way to do this?有没有办法做到这一点? Is it possible?是否可以? Are there alternatives?有替代品吗?

There are ways to create a class library and share it through NuGet.有多种方法可以创建类库并通过 NuGet 共享它。 https://azuredevopslabs.com/labs/azuredevops/packagemanagement/ https://azuredevopslabs.com/labs/azuredevops/packagemanagement/

But we need the class definitions across TypeScript and Python too.但是我们也需要跨 TypeScript 和 Python 的类定义。

How are you passing these classes?你是如何通过这些课程的? Have you considered Protocol Buffers or Microsoft Bond?您是否考虑过 Protocol Buffers 或 Microsoft Bond? Could you use dynamic objects?你能使用动态对象吗? How much of your complexity is wrapped up in ensuring static types?确保静态类型包含了多少复杂性? As suggested JSON can be used as neutral definition language and can then be translated into the programmer's secret weapon, a dictionary.正如建议的那样,JSON 可以用作中性定义语言,然后可以将其翻译成程序员的秘密武器,即字典。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM