Shorthand for Property declaration in VB

  • Thread starter Thread starter David W
  • Start date Start date
D

David W

I have a very simple class that just stores a number of strings so I can use
them in an ArrayList bound to a Repeater. There is no validation or
calculations needed for the properties. Is there any shorthand for this
without having to define a Property and a Get for every single instance
variable? This gets very old when you have many properties (30+). If I
just declare the instance vars as public (renaming them without the my) and
provide no Property accessor, the Repeater can't access them as it
enumerates. It just seems like an excessive amount of code for something so
simple.

Public Class SimpleClass
Private myName, myLabel As String

Public Sub New(ByVal Name As String, ByVal Label As String)
Me.myName = Name
Me.myLabel = Label
End Sub

Public ReadOnly Property Name() As String
Get
Return Me.myName
End Get
End Property

Public ReadOnly Property Label() As String
Get
Return Me.myLabel
End Get
End Property
End Class
 
Back
Top