A ReadOnly
property only makes that property value read only; it does not affect the behavior of the object that property references. If you need to make a truly read-only instance you'll have to make ICompany
immutable, like this:
Public Interface ICompany
ReadOnly Property Id() As Integer
...
End Interface
Of course, some care needs to be taken here as well. If Company
(the class which implements ICompany
) is mutable, there's nothing stoping a user from doing this:
CType(context.Company,Company).ID = 1