简体   繁体   English

在Web API解决方案和客户端解决方案之间共享枚举类

[英]Share enum class between web api solution and client solution

I'm developing an ASP.NET MVC 4 Web Api with .NET Framework 4.0 and C#. 我正在使用.NET Framework 4.0和C#开发ASP.NET MVC 4 Web Api。

I'm using this: 我正在使用这个:

HttpError myCustomError = new HttpError(errorMessage) { { "CustomErrorCode", 12 } };

I want to change that 12 with an enum and share that enum class with all clients. 我想用一个枚举更改那个12并与所有客户端共享该enum类。 How can I do it? 我该怎么做?

I've thought to create that enum in a project and share that project with a C# client that I'm developing. 我曾考虑在项目中创建该enum ,然后与正在开发的C#客户端共享该项目。

Is there another better approach? 还有另一种更好的方法吗?

I don't want to have two copies of the same class in Web Api solution and another one in my client solution. 我不想在Web Api解决方案中有两个相同类的副本,而在我的客户端解决方案中却没有另一个副本。

Usually, we use a Common library, which is referenced both in server and client. 通常,我们使用一个公共库,该库在服务器和客户端中都被引用。 It allows to develop C# clients and also it not breakes other clients written in PHP, Javascript, etc. 它允许开发C#客户端,也不会破坏其他用PHP,Javascript等编写的客户端。

I think it is the cleanest solution, actually, the projects are growing and growing, so the amount of shared data increases and you already have a place to keep it. 我认为这是最干净的解决方案,实际上,项目在不断发展,因此共享数据的数量在增加,您已经拥有了保留它的位置。

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

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