简体   繁体   中英

2 projects 1 solution- sharing classes?

I am new to windows mobile development and also Visual Studio.

I am developing a web service as well as a mobile application. I have the 1 solution, but 2 different projects.

I have created a class in the web service (say project 1), but want to be able to use this class in the mobile application (say project 2).

Do I have to basically create a copy of it and reference it in the other project?

There are two possible solutions:

  1. Create a third project to contain the shared class and add it as a reference in the other two.
  2. Keep the class in a single file, but add it to each project as a link, as explained here .

No, you do not need to create copy. Instead, add a reference to project1 in the project2 .

Right-click [References->Add Reference...] in project2 , pick the "Projects" tab, select project1 , and click [OK].

make your common class as a class library and save it in the form of .dll

whenever you require that class just add its reference to your project and use it :)

This is called re-use one of the best feature of OOPS

it defeats the purpose of SOA... It becomes Tightly coupled project. One should not add.. Two different layers.. "add as a reference".

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