tags:

views:

630

answers:

2

I got some set of base classes within one namespace and few sets of derived classes in other namespaces. Everything in one project. Something like:

Namespace Base
Public Class BaseElement
    Protected Friend Readonly Property SubElements() as BaseElements
End Class
End Namespace
...
Namespace Books
Public Class Book
    Inherits Base.BaseElement
    Public Readonly Property Pages() as Pages
        return MyBase.SubElements
    End Property
End Class
End Namespace

I have multiple derived classes and want them to have some easily understandable properties visible instead of .SubElements.

OK, it can be done declaring .SubElements as Protected in BaseElement class. But in this case I cannot access this property from other classes in Base namespace that are not derived from it.

I tried adding Friend keyword, but it made this property visible when I'm instantiating derived classes too.

So... any way to hide some properties when using derived classes while being able to use them using base class?

A: 

I believe you want to use an Interface in this case.

Daniel A. White
+2  A: 

.NET doesn't have namespace-based visibility modifiers.

You could potentially move everything in that namespace into its own class library project, and have it as a Friend member - or you could just live with it having more visibility than you want.

Jon Skeet