Hiding inner classes. What am I missing?
Really hope someone can point me in the right direction as I have no hair left anymore...
I am developing a simple SDK using VB.NET in VS 2010 and I have a class (OuterClass
) that is inheriting another class (InnerClass
).
There are obviously properties and methods in the InnerClass
that are accesible from 开发者_JAVA技巧the OuterClass
.
How the heck can I hide from my potential end users that InnerClass
even exists. I don't want to hide the InnerClass internals just the fact that InnerClass
is even there...
No matter what I try it is always visible in either the class viewer, debugger or editor.
I have tried the usual contenders:
<DebuggerBrowsable(DebuggerBrowsableState.Never)> _
and
<ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)> _
Please can someone even just point me in the right direction. I have found a few things but they are all to do with C++ and they are just confusing the .... out of me.
If OuterClass subclasses from InnerClass then InnerClass must be at least as visible as OuterClass. If you truly desire to hide InnerClass then you'll need to switch to an "OuterClass uses InnerClass" architecture instead of an "OuterClass is a InnerClass" architecture.
You could solve this problem with interfaces and a factory method.
Public Interface IOuterClass
End Interface
Friend MustOverride InnerClass
End Class
Friend Class OuterClass
Implements IOuterClass
Inherits InnerClass
End Class
Public Class OuterClassFactory
Public Shared Function Create() as IOuterClass
Return New OuterClass()
End Function
End Class
精彩评论