[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:
ReadOnly Property p As Integer
Private _p As Integer
Public Property p As Integer Implements I.p
Private Set(ByVal value As Integer)
_p = value
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
Interface IConsumer(Of In T)
WriteOnly Property p() As T
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
Set(ByVal value As T)
_p = value
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.