. .
1) Create an interface that exposes all the properties, methods, functions, etc. that you would like available.
Public Interface Sample
ReadOnly Property A() As Integer
ReadOnly Property B() As Integer
End Interface
2) Create a private structure and implement the interface Sample.
Private Structure InternalSample
Implements Sample
Friend Sub New(ByVal A As Integer, ByVal B As Integer)
Me.m_a = A
Me.m_b = B
End Sub
Public ReadOnly Property A() As Integer Implements Sample.A
Get
Return Me.m_a
End Get
End Property
Public ReadOnly Property B() As Integer Implements Sample.B
Get
Return Me.m_a
End Get
End Property
Friend m_a As Integer
Friend m_b As Integer
End Structure
3) In the function, GetSamplecreate a new instance InternalSample, set the desired values and return the object.
Public Function GetSample() As Sample
Dim struct As New InternalSample(123, 456)
'You can still change the values before returning the object:
struct.m_a = 321
struct.m_b = 654
Return struct
End Function
source
share