Jon Glazer
Jon Glazer

Reputation: 785

Inheriting a subtype

Ok, this may be an easy question but its been so long since I've done it.

I have a library (libA) that contains classes. I want to create a new library (libB) that inherits and extends a class from libA:

public class c1:libA.c1(){}

One of the methods in libA.c1 returns another class defined in libA:

public c2 m1(){}

When all done, I want to utilize libB without any references defined to libA in the future code. However, I cannot seem to be able to do it because I have to have a definition of c2 somewhere and simply inheriting:

public c2:libAc2(){}

doesn't seem to do it.

Can anyone give me any pointers on how to expose c2 through libB and "hide" libA to any programs that reference libB?

Upvotes: 1

Views: 75

Answers (1)

ManoDestra
ManoDestra

Reputation: 6473

If you have a chain of reference like this...

Application - libB - libA

Then you will need to include a reference to libA, otherwise it will simply not build your application. libA is a dependency of libB, after all. You're going to need it to run your application.

You can do some fancy loading of classes at runtime, loading assemblies manually, but this won't allow you to write code based on them, as such. So, it won't be of much use to you here. https://msdn.microsoft.com/en-us/library/system.reflection.assembly.loadfile%28v=vs.110%29.aspx

My best advice would be to refactor the code from libA into libB, provided you have the source code for libA. Then mark the classes you wish to hide from outside the assembly as internal.

https://msdn.microsoft.com/en-us/library/7c5ka91b.aspx

Upvotes: 1

Related Questions