
Accessing a Property through read-only and read-write interfaces
I would like to create an object with some Property and provide two
interfaces to the object, one read-only, the other read-write. The
compiler can then detect when I erroneously attempt to modify the
object through its read-only interface:
Module Console
Public Sub Main()
Dim o As MyObject = New MyObject()
Dim rw As IReadwrite = o
Dim ro As IReadonly = o
Dim value As String
value = rw.value
rw.value = value
value = ro.value
ro.value = value ' Expected compile error
End Sub
End Module
In C#, I can do this:
public interface IReadonly
{
string value { get; }
}
public interface IReadwrite
{
string value { get; set; }
}
public class MyObject : IReadonly, IReadwrite
{
private string _value = "some value" ;
public string value
{
get { return _value ; }
set { _value = value ; }
}
}
How would I code IReadonly, IReadwrite, and MyObject in VB.NET?
Thanks,
Michael.