views:

57

answers:

1

I am developing a class library that will be used in several projects.

In my class library, I have a "Shape" Class which has a number of properties. One of these properties is "Dimensions" returns a class with "Height" "Width" and "Depth" properties.

How would I suppress the Dimension class from being viewable in the editor, whilst freely avilable in the class library?

I've put a command in the class file, but this hides it in the library and my application.

<ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)> _

I have also changed the class acess modifier to Friend, but this prevents Public access to the Property in the Shape class when called outside the class library.

All I want to do is prevent creating an Instance of the Dimension class outside the class library.

Thanks.

This is the code functionality I like to achieve:

Interface IShape

    ReadOnly Property Properties() As ShapeProperties

End Interface

Public Class Shape

    Implements IShape

    Dim _Properties As New ShapeProperties(0, 0, 0)

    Sub New()
        _Properties = New ShapeProperties(3, 4, 5)
    End Sub

    Public ReadOnly Property Properties() As ShapeProperties Implements IShape.Properties
        Get
            Return _Properties
        End Get
    End Property

End Class

Friend Class ShapeProperties

    Dim _Height As Integer = 0
    Dim _Width As Integer = 0
    Dim _Depth As Integer = 0

    Friend Sub New(ByVal h As Integer, ByVal w As Integer, ByVal d As Integer)
        _Height = h
        _Width = w
        _Depth = d
    End Sub

    Private ReadOnly Property Height() As Integer
        Get
            Return _Height
        End Get
    End Property
    Private ReadOnly Property Width() As Integer
        Get
            Return _Width
        End Get
    End Property
    Private ReadOnly Property Depth() As Integer
        Get
            Return _Depth
        End Get
    End Property

End Class

I could not compile the Class Library in the above code. I want ShapeProperties to be only accessible in the Shape class, not on its own. The only way I was able to resolve this was to change the access property of ShapeProperties which is not what I want.

ClassLibrary.Shape is OK but ClassLibrary.Properties is not.

Thanks.

+1  A: 

You could make a public interface (IShape) and make a private class that implements it.

mbanzon