[Gambas-bugtracker] Bug #1362: Auto-generate property accessors

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Sun Jul 8 14:33:48 CEST 2018


http://gambaswiki.org/bugtracker/edit?object=BUG.1362&from=L21haW4-

Tobias BOEGE reported a new bug.

Summary
-------

Auto-generate property accessors

Type             : Request
Priority         : Medium
Gambas version   : Unknown
Product          : Language


Description
-----------

Sometimes you want to have a property which is really just a (future-proof) proxy to
a Private variable. The recipe for that is

    Property Index As Integer
    Private $iIndex As Integer
    Public Sub Index_Read() As Integer
      Return $iIndex
    End
    Public Sub Index_Write(Value As Integer)
      $iIndex = Value
    End

My suggestion is to introduce

    Property Index As Integer Is $iIndex

or something like that, as a shortcut for the above. The code generator should be smart
enough not to override any accessor function I did declare:

    Property Index As Integer Is $iIndex
    Public Sub Index_Write(Value As Integer)
      If Value < 0 Then Error.Raise(("Index must be non-negative"))
      $iIndex = Value
    End

Here, I supply a setter with an additional check, but the getter is generated as proposed
above. The variable $iIndex can be used anywhere else in the class code, as usual.






More information about the Bugtracker mailing list