简体   繁体   English

在网站项目和 Web 服务项目之间共享枚举

[英]Share an enum between a website project and a web service project

I have an enum which is likely to be used in Project A(Website) and B(Web Service), but for now it is only used in project A.我有一个枚举,它很可能在项目 A(网站)和 B(网络服务)中使用,但目前它只在项目 A 中使用。

I do not want to add the same enum in both projects, so what is the best practice to do it?我不想在两个项目中添加相同的枚举,那么最好的做法是什么?

I am thinking of adding another project which will be referenced by both A and B, but I am not sure that it is the proper way to do it.我正在考虑添加另一个将由 A 和 B 引用的项目,但我不确定这是正确的方法。

Common functionality deserves being placed in it's own project to be accessible from all projects instead of duplication.公共功能应该放在它自己的项目中,以便从所有项目中访问,而不是重复。 It does not have to be a class library, you could define the enum in one of the projects and reference that project from the other one, but I'm inclined to putting in it's own project just for the sake of clarity.它不必是一个类库,您可以在其中一个项目中定义枚举并从另一个项目中引用该项目,但为了清楚起见,我倾向于将其放入自己的项目中。

Also, if you in the future decide to add another shared logic, you will already have a place to put it.此外,如果您将来决定添加另一个共享逻辑,您就已经有了放置它的地方。

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

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