简体   繁体   中英

C# sharing Objects between projects

I have a Solution with 2 Projects...

Project A has Following A - Reference Third Party DLL (Which has a Class Called "Response") B - A Class which uses above DLL and returns the "Response" Object from a Method Called "GetResponse"

Now Project B Calls The Class From Project A Like This....

Response r = ProjectA.Class.GetResponse();

This will return a Error, because I dont have "Third party" reference in my project B.

I rather not ship my third party DLL to all of my other projects just to get the reference to Response Object from Third party DLL .

so is there anyway of doing it without having to add the 3rd party reference to Project B?

If your project is using objects defined in the third party DLL, it has to be referenced directly as well.

If you want to avoid this, you can wrap the Response object in a custom object defined in Project B, creating methods and properties to expose anything necessary on the Response class. Remember, you can't expose the Response class directly, or the direct reference will be necessary again.

Of course, even with wrapping, when deploying your final DLL, the third party DLL will still be required, it just won't need to be directly referenced.

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