I created an abstract base class in C# but didn’t want it to be used outside the assembly I created it in.
How can you achieve this?
Your first guess could be to change the access modifier of the base class to internal. When you try to do this you’ll get the following error message:
Inconsistent accessibility: base class 'MyBaseClass' is less accessible than class 'MyInheritedClass'
You have no other choice than to make the abstract class public what makes it visible outside the assembly.
Is there still a way to only allow classes in the same assembly to implement it?
The trick is to make the abstract base class public, but give it an internal default constructor:
This will allow MyBaseClass to be visible outside the assembly, but classes outside the assembly cannot inherit from it.