Public class, derived from an internal class  
Author Message
Barguast





PostPosted: .NET Base Class Library, Public class, derived from an internal class Top

I have a class library which defines a few public classes. All of these classes have shared functionality, which is defined in a base class from which they are all derived. However, this functionality should only be available within the class library, and not by any other external code. For this reason, I specify the class as internal.

When I attempted to compile the code, I got the error;

Inconsistent accessibility: base class 'HTS.Database.Dbo<int>' is less accessible than class 'HTS.Database.StaffDetails'

Dbo is the internal class. StaffDetails is the public class.

Normally I would understand this error, however in this case I do not see why it should be a problem. The Dbo class consists entirely of internal properties and constructors, and private fields which, from an external point of view won't make any semantic changes to the StaffDetails class.

Hopefully that makes sense Can someone explain why this is a problem

Thanks




.NET Development26  
 
 
Ajeeth Kumar





PostPosted: .NET Base Class Library, Public class, derived from an internal class Top

Hi Barguast

What happens here is , when you instantiate the derived class it creates the object of its parent in the memory which unfortunately

you are not exposing outside the project. I feel this is the reason why you are getting the compilation error.

Thanks,



 
 
Barguast





PostPosted: .NET Base Class Library, Public class, derived from an internal class Top

That may be it, though the instantiation of the derived class would be done inside the public classes' constructor which, given that the public classes are declared inside the class library alongside the internal base class, shouldn't be an issue as far as I'm aware...

Thanks for your reply.

 
 
nobugz





PostPosted: .NET Base Class Library, Public class, derived from an internal class Top

Guessing a bit: I think this requirement is imposed by Reflection. It promises you can fully reconstruct the type hierarchy of a class from the meta-data of an assembly. Having the base class of a public class declared as internal would prevent that.


 
 
Barguast





PostPosted: .NET Base Class Library, Public class, derived from an internal class Top

Well, I'm just pleased the answer isn't so obvious. :p

It's no big deal to declare the class as public since it is abstract with internal constructors and members anyway - it still can't be used in any true sense outside of the class library. It just would've been nice to hide it. Oh well.

Thanks for all your help.