0

Let's say i have a Project A that contains common classes that are going to be shared between Project B and Project C.

Is it possible for Project C to implement it's own version of a class from Project A so other classes within Project A will use the Project C version if that is going to be the build target or use the Project B(shared version) version if that is the target.

Having 2 seperate classes would be a solution i think but that is going to be a pain in the ass to make sure i update both versions. An other solution that i can think of would be virtual methods but i have no clue if the shared class dependency's will use the overridden method or the original one.

DarkSpikeX
  • 27
  • 4
  • You can use a shortcut file from one assembly in another. Combined with build configurations should do what you want – Novaterata Jun 23 '17 at 21:29
  • I don't recommend this though. Just have a common library and use dependency injection. – Novaterata Jun 23 '17 at 21:34
  • Did you think about inheritance? You could create a class in pA (project A) and use it in pB and pC. Its uncommon to build a class that is changed by another project to beeing used as in pC in pA. You could do `pA.MyClass` and `pC.MyClass : pA.MyClass` and than for the other classes the same `pA.otherClass; void xyz(pA.MyClass myClass); pC.otherClass : pa.otherClass; override void xyz(pC.MyClass myClass) : base...` – DomeTune Jun 23 '17 at 21:35
  • This `Is it possible for Project C to implement it's own version of a class from Project A so other classes within Project A will use the Project C version if that is going to be the build target or use the Project B(shared version) version if that is the target.` makes no sense. Are you sure that is what you want? Why would project A use Project C versions: That is a circular dependency. You need to edit your question and carefully think about what you are asking. – CodingYoshi Jun 23 '17 at 21:40

1 Answers1

1

Don't write a class. Write an interface. Then, by design, a class that depends on the interface can use any implementation of the interface.

Scott Hannen
  • 27,588
  • 3
  • 45
  • 62