简体   繁体   中英

Referenced DLLs with shared classes

Here's the issue I'm running into.

Project #1 - DLL

- Includes SomeCommonFile.cs file with several classes

Project #2 - Different DLL

- Includes SomeCommonFile.cs file with several classes

Project #3 - A web service

- Includes SomeCommonFile.cs file with several classes - Includes references to both the DLL files.

So I've got the DLLs imported in just fine in Project #3, after putting aliases on the references, and "extern alias" at the top of the relevant code files.

But here's the problem when coding in Project #3: every single class in that SomeCommonFile.cs has three versions - one for each dll, and one in Project #3. Is there any easy way to structure this so that I don't have to have conversion functions all over the place (converting Project1DLL.CommonClasses.MyClass to WebService.CommonClasses.MyClass, etc)? At this point, I'm at the point where I'm going to Link Projects #1 and #2's code files instead of their DLL, just to simplify the classes, even though that sounds bad from a maintenance perspective.

The solution is to not include the common classes in each of three different projects in your solution.

If both of your DLLs need to reference some common code, and neither can reference the other, then have a 4th DLL with the common code that they both (along with the web project) reference.

Now you only have one copy of the classes, and they all play nice with each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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