0

I want to use some code of Project 1 (VB.NET) in Project 2 (c# Windows Form) and vice-versa. I know we cannot create circular reference but is there any other way we can achieve it?

Zoka
  • 2,312
  • 4
  • 23
  • 33
Developer Nation
  • 374
  • 3
  • 4
  • 20
  • 2
    I assume the VB.NET project deal with the business logic while the C# project is the UI part? If so, there's something very wrong if you take UI logic into business class. That said, you can just create a third project which refer to all classes on project 1 & 2. – Martheen Apr 01 '16 at 13:00
  • +1 on third project. Either third referencing those two or take out from both what you want to reference and make dll from that code. – Claudius Apr 01 '16 at 13:03

1 Answers1

1

First, circular reference means wrong design. If you need something like this, you must change your design in one of these ways:

1. Extract "circular" code

In general, create another library, with functions, which are called from both "circular" libraries. Then make both Project1 and Project2 dependent on newly created Project3.

2. Use callbacks

Make just one lib dependent on second - without any example from your code, it is hard to decide, which one should be dependant on other, but from "Windows Form" I would assume, it would be better if Project2 is dependent on Project1. So it means, that Project2 knows everything Project1. And then, if you need to call something from Project1 back to Project2, just provide callback during initializing. E.g. Project1 contains function, which makes some long calculations, and you want to be notified when it's done. OK, no problem. Project2 starts the operation with callback (search for delegates) and continues with its own work. When the function in Project1 finishes, it uses the provided callback to call function from Project2 (even it doesn't know this function, but it is not necessary, because compiler manage, that "incompatible" function cannot be provided as callback).

It is hard to give you more advices, since you haven't provided any piece of code. If you need more help, please update your question with some simplified example.

Zoka
  • 2,312
  • 4
  • 23
  • 33
  • Take a look at my two form project. I pass the instance of the main form to the child form so the two forms can send data between them : http://stackoverflow.com/questions/36251695/c-sharp-reference-two-forms – jdweng Apr 01 '16 at 13:18
  • OK, the code there is little messy, but from what I understand you do not want to share data. You just want Form2 to display list from Form1. This is not case for circular referrence at all. Make Form2 constructor to take list from Form1 as parameter and you have it. – Zoka Apr 01 '16 at 13:27