We have an interface, which can be grossly simplified as:
public interface IPersistable<T>
{
T Id { get; }
}
Most places that implement the interface want to have it so that there is a protected or private set on that property, i.e, in C#:
public class Foo : IPersistable<int>
{
public int Id { get; protected set; }
}
However, I can't get any sample VB.Net code to compile that follows the same pattern, whilst still implementing the interface, so:
Public Class Foo
Implements IPersistable(Of Integer)
Public Property Id() As Integer Implements IPersistable(Of Integer).Id
Get
Throw New NotImplementedException()
End Get
Protected Set(ByVal value As Integer)
Throw New NotImplementedException()
End Set
End Property
End Class
...will not compile, but this would:
Public Class Foo
Public Property Id() As Integer
Get
Throw New NotImplementedException()
End Get
Protected Set(ByVal value As Integer)
Throw New NotImplementedException()
End Set
End Property
End Class
I appreciate that this example is overly trivial, and would possibly be better achieved through protected constructors, but I'm interested if it can be done in this manner?
[ EDIT: ] ...and obviously, if a type wants to use XMLSerialization, then the properties would need to be public read/write or the types would require custom serializers written for each.
Essentially, I see it that the interface should define the minimum accessibility, but VB is interpreting it as the exact accessibility?