Core4: Flexibility with implementing properties
[This post is part of a series, "wish-list for future versions of VB"]
IDEA: Flexibility with implementing properties. Allow you to implement a property with more accessors than was specified in the interface your implementing, or the abstract class you're inheriting from.
SCENARIO: An interface declares a readonly property, but you want to implement it with a private setter:
Interface I
ReadOnly Property p As Integer
End Interface
Class C
Implements I
Private _p As Integer
Public Property p As Integer Implements I.p
Get
Return _p
End Get
Private Set(ByVal value As Integer)
_p = value
End Set
End Property
End Class
SCENARIO: One interface has a readonly property, and another has a writeonly property, and you want to implement them both at the same time.
Interface IProducer(Of Out T)
ReadOnly Property p() As T
End Interface
Interface IConsumer(Of In T)
WriteOnly Property p() As T
End Interface
Class C(Of T)
Implements IProducer(Of T)
Implements IConsumer(Of T)
Private _p As T
Public ReadOnly Property p As T Implements IProducer(Of T).p, IConsumer(Of T).p
Get
Return _p
End Get
Set(ByVal value As T)
_p = value
End Set
End Property
End Class
Bill Sheldon suggested that maybe the "Implements" clause in the first scenario should go on the Getter or Setter that it's appropriate to.
Provisional evaluation from VB team: This is a decent idea, one that we should consider against all the other decent ideas.