I have an internal class A that does a lot of stuff and I have a set of other classes B, D, E that inherit from class A. Of course this won’t work as the compiler will complain about a public class not being able to extend an internal one (see this for an explanation).
I don’t want A to be public as I don’t want my users to inherit from it. I want them to only use B, D, E.
I know I can hide the class from Intellisense using [EditorBrowsable(EditorBrowsableState.Never)] but the users can still access it using reflection 🙁
Is there a way I can achieve this?
Assuming that
Ais in the assembly A, andB,DandEare in the assembly BDE, you can declare theInternalsVisibleToattribute on A to make BDE a friend assembly. Like this,B,DandEwill be able to seeA.Still, you cannot inherit from
A, as superclasses cannot have a lower visibility than subclasses. You can solve this by declaringApublic while making all of its constructors internal. This way, only code with internal access toAwill be able to derive fromA.