views:

39

answers:

2

Hi all,

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 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.

Thanks in advance,

Andy

+1  A: 

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.

Ken Browning
Hi Ken, Thank you so much for getting back to me. I understand what you mean but I am unsure of it's implementation. Could you advise with a simple example at all please? //A
thor69uk
public class OuterClass { private class InnerClass { public int Position { get; set;} } private InnerClass inner; public int Position { get { return inner.Position; } set { inner.Position = value; } } }
s_hewitt
Hi, thank you so much for that. Now the concept makes perfect sense. One thing I did just notice is that when I wrote this out I missed off the all important point that InnerClass is also used by SecondaryClass as well as OuterClass. If I move InnerClass outside of OuterClass to make it accessible to SecondaryClass (even if I define it as Friend) and then add the <ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)> _ line above it, there it is staring back at me from the debugger as soon as I set a breakpoint... What am I missing here??? Thanks again to all.
thor69uk
A: 

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
Brian Gideon
Thanks for your help! Much appreciated... //A
thor69uk