So I have a problem in which I have an object that holds other objects that are loosely related to each other. I only want this object to be a sort of repository whereby variables can be read, but not altered if this object is used. This was my starting point (VB.Net):
Public Class CompanyVendorContext
Private _company As ICompany
Private _vendor As IVendor
Public ReadOnly Property Company As ICompany
Get
Return Me._company
End Get
End Property
Public ReadOnly Property Vendor As IVendor
Get
Return Me._vendor
End Get
End Property
Public Sub New(ByVal objCompany As ICompany, ByVal objVendor As IVendor)
Me._company = objCompany
Me._vendor = objVendor
End Sub
End Class
Now, appropriately, when I try to set the object itself, like so:
Dim context As New CompanyVendorContext(New Company, New Vendor)
context.Company = New Company
It doesn't allow me to do so, which is perfect. However, when I attempt to do this instead:
Dim context As New CompanyVendorContext(New Company, New Vendor)
context.Company.ID = 1
It allows me to do so. Can I set the properties of the Company object as readonly, but only when accessed from this CompanyVendorContext object?