EnglishРусский  
 Share/Save/Bookmark
 

Properties

Gentee provides you with the property in order to get or set values of the fields of the structured types. Using the properties you can hide a direct access to the fields and perform additional calculations in order to get a field value or set a field value with the help of the assignment operator. A property name must differ from a field name, because a direct access to a field has a higher priority; otherwise, a field value will be got or set.

The get property, that returns a value, must contain no arguments.

type mytype
{
   str val
}

property str  mytype.value
{
   return this.val
}

The set property, that defines a value, must contain one argument. Also, the set property can return a value.

property str mytype.value( str newval )
{
   if *newval : this.val = newval
   else : this.val = "empty"
   return this.val
}

A property name is specified in the same way as a field in order to call a property. The set property is called if it is specified on the left side of the assignment operator; otherwise, the get property is called.

func myfunc
{
   mytype myt

   myt.value = "New value"  // set
   print( myt.value )       // get
}

Related links

Edit